Skip to content

Commit

Permalink
Add CLI entry point to module (Addresses UCL-RITS/rse-classwork-2020#144
Browse files Browse the repository at this point in the history
)
  • Loading branch information
twemyss committed Nov 26, 2020
1 parent e615a77 commit 05a5fd9
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 14 deletions.
1 change: 1 addition & 0 deletions sagital_average/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .sagital_brain import run_averages
20 changes: 20 additions & 0 deletions sagital_average/brain_sample.csv
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions sagital_average/command.py
Original file line number Diff line number Diff line change
@@ -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)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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'):
Expand All @@ -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)
File renamed without changes.
Empty file removed sagital_brain/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]}
)

0 comments on commit 05a5fd9

Please sign in to comment.