From 05a5fd9860d40172a98002cc139824e88ac3e5a1 Mon Sep 17 00:00:00 2001 From: Thomas Wemyss Date: Thu, 26 Nov 2020 12:55:48 +0000 Subject: [PATCH] Add CLI entry point to module (Addresses UCL-RITS/rse-classwork-2020#144) --- sagital_average/__init__.py | 1 + sagital_average/brain_sample.csv | 20 +++++++++++++++++++ sagital_average/command.py | 12 +++++++++++ .../requirements.txt | 0 .../sagital_brain.py | 14 ------------- .../tests/test_average.py | 0 sagital_brain/__init__.py | 0 setup.py | 5 +++++ 8 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 sagital_average/__init__.py create mode 100644 sagital_average/brain_sample.csv create mode 100644 sagital_average/command.py rename {sagital_brain => sagital_average}/requirements.txt (100%) rename {sagital_brain => sagital_average}/sagital_brain.py (50%) rename {sagital_brain => sagital_average}/tests/test_average.py (100%) delete mode 100644 sagital_brain/__init__.py diff --git a/sagital_average/__init__.py b/sagital_average/__init__.py new file mode 100644 index 0000000..829850f --- /dev/null +++ b/sagital_average/__init__.py @@ -0,0 +1 @@ +from .sagital_brain import run_averages \ No newline at end of file diff --git a/sagital_average/brain_sample.csv b/sagital_average/brain_sample.csv new file mode 100644 index 0000000..d0b9035 --- /dev/null +++ b/sagital_average/brain_sample.csv @@ -0,0 +1,20 @@ +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 diff --git a/sagital_average/command.py b/sagital_average/command.py new file mode 100644 index 0000000..29e6aa1 --- /dev/null +++ b/sagital_average/command.py @@ -0,0 +1,12 @@ +from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter +import sagital_brain + +def process(): + parser = ArgumentParser(description="Calculates the average for each sagital-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() + sagital_brain.run_averages(arguments.file_input, arguments.file_output) \ No newline at end of file diff --git a/sagital_brain/requirements.txt b/sagital_average/requirements.txt similarity index 100% rename from sagital_brain/requirements.txt rename to sagital_average/requirements.txt diff --git a/sagital_brain/sagital_brain.py b/sagital_average/sagital_brain.py similarity index 50% rename from sagital_brain/sagital_brain.py rename to sagital_average/sagital_brain.py index 063d63a..b33870c 100755 --- a/sagital_brain/sagital_brain.py +++ b/sagital_average/sagital_brain.py @@ -1,7 +1,3 @@ -#!/usr/local/python3 - -from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter - import numpy as np def run_averages(file_input='brain_sample.csv', file_output='brain_average.csv'): @@ -23,13 +19,3 @@ def run_averages(file_input='brain_sample.csv', file_output='brain_average.csv') np.savetxt(file_output, averages, fmt='%.1f', delimiter=',') -if __name__ == "__main__": - parser = ArgumentParser(description="Calculates the average for each sagital-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) diff --git a/sagital_brain/tests/test_average.py b/sagital_average/tests/test_average.py similarity index 100% rename from sagital_brain/tests/test_average.py rename to sagital_average/tests/test_average.py diff --git a/sagital_brain/__init__.py b/sagital_brain/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/setup.py b/setup.py index 090b6a5..4f16d5a 100644 --- a/setup.py +++ b/setup.py @@ -4,4 +4,9 @@ name="Sagital Brain", version="0.1.0", packages=find_packages(), + install_requires=['numpy', 'pytest'], + entry_points={ + 'console_scripts': [ + 'sagital_brain = sagital_brain.command:process' + ]} ) \ No newline at end of file