diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..fae8b7a Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..747f6b9 --- /dev/null +++ b/.gitignore @@ -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/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9b38853 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..de5505a --- /dev/null +++ b/pyproject.toml @@ -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", +] \ No newline at end of file diff --git a/src/sagittal_average/__init__.py b/src/sagittal_average/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/sagittal_average/command.py b/src/sagittal_average/command.py new file mode 100644 index 0000000..c51e377 --- /dev/null +++ b/src/sagittal_average/command.py @@ -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) \ No newline at end of file diff --git a/sagittal_brain.py b/src/sagittal_average/sagittal_brain.py similarity index 51% rename from sagittal_brain.py rename to src/sagittal_average/sagittal_brain.py index c257fc9..69d8625 100644 --- a/sagittal_brain.py +++ b/src/sagittal_average/sagittal_brain.py @@ -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) diff --git a/tests/fixtures/fixture_file.yaml b/tests/fixtures/fixture_file.yaml new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_python_file.py b/tests/test_python_file.py new file mode 100644 index 0000000..b7d09e3 --- /dev/null +++ b/tests/test_python_file.py @@ -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) \ No newline at end of file