Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting up directory structure and .toml file for package creation #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
165 changes: 165 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Default .gitignore by github when initiating a repo

# Byte-compiled / optimized / DLL files
__pycache__/
*.pyc
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[project]
name = "sagittal_average" # Name of the package
version = "0.1.2" # Version of the package
description = "Brain stuff"
dependencies = [ # Adding dependency installation
"numpy", "pathlib", "argparse"
]
readme = "README.md" # Path to the README file
requires-python = ">=3.8" # Minimum Python version
license = {file = "LICENSE"} # License file or name

[build-system]
requires = ["setuptools>=42", "wheel"] # Tools needed to build the package
build-backend = "setuptools.build_meta" # Build backend

[project.scripts]
sagittal_average_run = "sagittal_average.command:process" # Creating a run command

[tool.hatch.build.targets.wheel]
packages = [
"src/sagittal_average",
]
Empty file.
14 changes: 14 additions & 0 deletions src/sagittal_average/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
import numpy as np
from sagittal_average.sagittal_brain import run_averages

def process():
parser = ArgumentParser(description="Calculates the average for each sagittal-horizontal plane.",
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('file_input', nargs='?', default="brain_sample.csv",
help="Input CSV file with the results from scikit-brain binning algorithm.")
parser.add_argument('--file_output', '-o', default="brain_average.csv",
help="Name of the output CSV file.")
arguments = parser.parse_args()

run_averages(arguments.file_input, arguments.file_output)
20 changes: 10 additions & 10 deletions sagittal_brain.py → src/sagittal_average/sagittal_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ def run_averages(file_input='brain_sample.csv', file_output='brain_average.csv')

# Calculates the averages through the sagittal/horizontal planes
# and makes it as a row vector
averages = planes.mean(axis=0)[np.newaxis, :]
averages = planes.mean(axis=1)[np.newaxis, :]

# write it out on my file
np.savetxt(file_output, averages, fmt='%.1f', delimiter=',')


if __name__ == "__main__":
parser = ArgumentParser(description="Calculates the average for each sagittal-horizontal plane.",
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('file_input', nargs='?', default="brain_sample.csv",
help="Input CSV file with the results from scikit-brain binning algorithm.")
parser.add_argument('--file_output', '-o', default="brain_average.csv",
help="Name of the output CSV file.")
arguments = parser.parse_args()
# if __name__ == "__main__":
# parser = ArgumentParser(description="Calculates the average for each sagittal-horizontal plane.",
# formatter_class=ArgumentDefaultsHelpFormatter)
# parser.add_argument('file_input', nargs='?', default="brain_sample.csv",
# help="Input CSV file with the results from scikit-brain binning algorithm.")
# parser.add_argument('--file_output', '-o', default="brain_average.csv",
# help="Name of the output CSV file.")
# arguments = parser.parse_args()

run_averages(arguments.file_input, arguments.file_output)
# run_averages(arguments.file_input, arguments.file_output)
Empty file.
33 changes: 33 additions & 0 deletions tests/test_python_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import numpy as np

TEST_DIR = '/Users/sirbucks/Desktop/UCL/Coding/COMP0233_Research_SWE_Python/session_7/part2/sagittal_average/'

import numpy as np
from pathlib import Path
import tempfile
from src.sagittal_average.sagittal_brain import run_averages

def test_sagittal_average():
with tempfile.TemporaryDirectory() as temp_dir:
# Create an input dataset
data_input = np.zeros((20, 20))
data_input[-1, :] = 1

# Save it into a file in the temporary directory
input_file = Path(temp_dir) / "brain_sample.csv"
np.savetxt(input_file, data_input, fmt='%d', delimiter=',')

# Create an array with expected result
expected = np.zeros(20)
expected[-1] = 1

# Call the function with the files in the temporary directory
output_file = Path(temp_dir) / "brain_average.csv"
run_averages(file_input=str(input_file),
file_output=str(output_file))

# Load the result
result = np.loadtxt(output_file, delimiter=',')

# Compare the result with the expected values
np.testing.assert_array_equal(result, expected)