Skip to content

Commit

Permalink
CLI Interface, argparse moved to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
skim2257 committed Jun 10, 2022
1 parent 1407e1d commit 6bf5f4f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
39 changes: 10 additions & 29 deletions imgtools/autopipeline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, pathlib
import os, pathlib, sys
import shutil
import glob
import pickle
Expand All @@ -8,6 +8,7 @@

from imgtools.ops import StructureSetToSegmentation, ImageAutoInput, ImageAutoOutput, Resample
from imgtools.pipeline import Pipeline
from imgtools.utils import parser
from joblib import Parallel, delayed

###############################################################
Expand Down Expand Up @@ -203,34 +204,9 @@ def run(self):
Parallel(n_jobs=self.n_jobs, verbose=verbose)(
delayed(self._process_wrapper)(subject_id) for subject_id in subject_ids)
self.save_data()


if __name__ == "__main__":
parser = ArgumentParser("imgtools Automatic Processing Pipeline.")

#arguments
parser.add_argument("input_directory", type=str,
help="Path to top-level directory of dataset.")

parser.add_argument("output_directory", type=str,
help="Path to output directory to save processed images.")

parser.add_argument("--modalities", type=str, default="CT",
help="List of desired modalities. Type as string for ex: RTSTRUCT,CT,RTDOSE")

parser.add_argument("--visualize", type=bool, default=False,
help="Whether to visualize the data graph")

parser.add_argument("--spacing", nargs=3, type=float, default=(1., 1., 0.),
help="The resampled voxel spacing in (x, y, z) directions.")

parser.add_argument("--n_jobs", type=int, default=-1,
help="The number of parallel processes to use.")

parser.add_argument("--show_progress", action="store_true",
help="Whether to print progress to standard output.")

args = parser.parse_args()
def main():
args = parser()
pipeline = AutoPipeline(args.input_directory,
args.output_directory,
modalities=args.modalities,
Expand All @@ -243,4 +219,9 @@ def run(self):
pipeline.run()


print(f'finished Pipeline!')
print(f'finished Pipeline!')

if __name__ == "__main__":
main()


1 change: 1 addition & 0 deletions imgtools/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .arrayutils import *
from .crawl import *
from .dicomutils import *
from .args import *
28 changes: 28 additions & 0 deletions imgtools/utils/args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from argparse import ArgumentParser

def parser():
parser = ArgumentParser("imgtools Automatic Processing Pipeline.")

#arguments
parser.add_argument("input_directory", type=str,
help="Path to top-level directory of dataset.")

parser.add_argument("output_directory", type=str,
help="Path to output directory to save processed images.")

parser.add_argument("--modalities", type=str, default="CT",
help="List of desired modalities. Type as string for ex: RTSTRUCT,CT,RTDOSE")

parser.add_argument("--visualize", type=bool, default=False,
help="Whether to visualize the data graph")

parser.add_argument("--spacing", nargs=3, type=float, default=(1., 1., 0.),
help="The resampled voxel spacing in (x, y, z) directions.")

parser.add_argument("--n_jobs", type=int, default=-1,
help="The number of parallel processes to use.")

parser.add_argument("--show_progress", action="store_true",
help="Whether to print progress to standard output.")

return parser.parse_known_args()[0]
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
extras_require={
'debug': ['pyvis'],
},
entry_points={'console_scripts': ['autopipe = imgtools.autopipeline:main']},
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
Expand Down

0 comments on commit 6bf5f4f

Please sign in to comment.