diff --git a/__init__.py b/__init__.py deleted file mode 100644 index 0d9d64f..0000000 --- a/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# Hi! diff --git a/dicom2stl.py b/dicom2stl/Dicom2STL.py similarity index 96% rename from dicom2stl.py rename to dicom2stl/Dicom2STL.py index 6e9f5f4..7dbc810 100755 --- a/dicom2stl.py +++ b/dicom2stl/Dicom2STL.py @@ -21,7 +21,6 @@ import os import sys import tempfile -import shutil import time import zipfile import vtk @@ -30,12 +29,12 @@ from SimpleITK.utilities.vtk import sitk2vtk -import parseargs +import dicom2stl from glob import glob -from utils import dicomutils -from utils import vtkutils +from dicom2stl.utils import dicomutils +from dicom2stl.utils import vtkutils def roundThousand(x): @@ -89,7 +88,8 @@ def loadVolume(fname, tempDir=None, verbose=0): print("zip") if not tempDir: with tempfile.TemporaryDirectory() as defaultTempDir: - img, modality = dicomutils.loadZipDicom(fname[0], defaultTempDir) + img, modality = dicomutils.loadZipDicom(fname[0], + defaultTempDir) else: img, modality = dicomutils.loadZipDicom(fname[0], tempDir) @@ -154,7 +154,8 @@ def writeMetadataFile(img, metaName): def volumeProcessingPipeline( - img, shrinkFlag=True, anisotropicSmoothing=False, thresholds=[], medianFilter=False + img, shrinkFlag=True, anisotropicSmoothing=False, thresholds=[], + medianFilter=False ): # # shrink the volume to 256 cubed @@ -178,8 +179,8 @@ def volumeProcessingPipeline( gc.collect() - # Apply anisotropic smoothing to the volume image. That's a smoothing filter - # that preserves edges. + # Apply anisotropic smoothing to the volume image. That's a smoothing + # filter that preserves edges. # if anisotropicSmoothing: print("Anisotropic Smoothing") @@ -197,13 +198,14 @@ def volumeProcessingPipeline( print("Double Threshold: ", thresholds) t = time.perf_counter() img = sitk.DoubleThreshold( - img, thresholds[0], thresholds[1], thresholds[2], thresholds[3], 255, 0 + img, thresholds[0], thresholds[1], thresholds[2], thresholds[3], + 255, 0 ) elapsedTime(t) gc.collect() - # Apply a 3x3x1 median filter. I only use 1 in the Z direction so it's not so - # slow. + # Apply a 3x3x1 median filter. I only use 1 in the Z direction so it's + # not so slow. # if medianFilter: print("Median filter") @@ -297,7 +299,7 @@ def getTissueThresholds(tissueType): return thresholds, medianFilter -def dicom2stl(args): +def Dicom2STL(args): # Global variables # thresholds = [] @@ -328,7 +330,7 @@ def dicom2stl(args): rotFlag = val print("") - if args.temp == None: + if args.temp is None: args.temp = tempfile.mkdtemp() print("Temp dir: ", args.temp) @@ -428,8 +430,9 @@ def dicom2stl(args): def main(): - args = parseargs.parseargs() - dicom2stl(args) + args = dicom2stl.utils.parseargs.parseargs() + Dicom2STL(args) + if __name__ == "__main__": main() diff --git a/dicom2stl/__init__.py b/dicom2stl/__init__.py new file mode 100644 index 0000000..d4891da --- /dev/null +++ b/dicom2stl/__init__.py @@ -0,0 +1,6 @@ +import dicom2stl +import dicom2stl.utils.parseargs +def main(): + """Entry point for the application script""" + args = dicom2stl.utils.parseargs.parseargs() + dicom2stl.Dicom2STL(args) diff --git a/utils/__init__.py b/dicom2stl/utils/__init__.py similarity index 100% rename from utils/__init__.py rename to dicom2stl/utils/__init__.py diff --git a/utils/dicomutils.py b/dicom2stl/utils/dicomutils.py similarity index 100% rename from utils/dicomutils.py rename to dicom2stl/utils/dicomutils.py diff --git a/parseargs.py b/dicom2stl/utils/parseargs.py similarity index 94% rename from parseargs.py rename to dicom2stl/utils/parseargs.py index 737ea63..f25b4c4 100644 --- a/parseargs.py +++ b/dicom2stl/utils/parseargs.py @@ -2,6 +2,16 @@ import argparse +from importlib.metadata import version, PackageNotFoundError + +__version__ = "unknown" + +try: + __version__ = version("dicom2stl") +except PackageNotFoundError: + # package is not installed + pass + class disableFilter(argparse.Action): def __call__(self, parser, args, values, option_string=None): @@ -104,6 +114,9 @@ def createParser(): help="Dicom series search string", ) + parser.add_argument("--version", action="version", version=f"{__version__}") + + # Options that apply to the volumetric portion of the pipeline vol_group = parser.add_argument_group("Volume options") diff --git a/utils/regularize.py b/dicom2stl/utils/regularize.py similarity index 100% rename from utils/regularize.py rename to dicom2stl/utils/regularize.py diff --git a/utils/sitk2vtk.py b/dicom2stl/utils/sitk2vtk.py similarity index 100% rename from utils/sitk2vtk.py rename to dicom2stl/utils/sitk2vtk.py diff --git a/utils/vtk2sitk.py b/dicom2stl/utils/vtk2sitk.py similarity index 100% rename from utils/vtk2sitk.py rename to dicom2stl/utils/vtk2sitk.py diff --git a/utils/vtkutils.py b/dicom2stl/utils/vtkutils.py similarity index 100% rename from utils/vtkutils.py rename to dicom2stl/utils/vtkutils.py diff --git a/pyproject.toml b/pyproject.toml index 6a09e3c..b16559c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,8 +24,11 @@ dynamic = ["dependencies", "version"] [tool.setuptools.dynamic] dependencies = {file = ["requirements.txt"]} +[tool.setuptools.packages.find] +exclude = ["docs*", "tests*", "binder*", "utils*", "examples*", "tmp*"] + [project.scripts] -dicom2stl = "dicom2stl:main" +dicom2stl = "dicom2stl.Dicom2STL:main" [tool.setuptools_scm] local_scheme = "dirty-tag" diff --git a/tests/test_dicom2stl.py b/tests/test_dicom2stl.py index d03e28f..0c16c2f 100644 --- a/tests/test_dicom2stl.py +++ b/tests/test_dicom2stl.py @@ -2,8 +2,8 @@ import os import SimpleITK as sitk -import parseargs -import dicom2stl +from dicom2stl.utils import parseargs +from dicom2stl.Dicom2STL import Dicom2STL from tests import create_data @@ -34,7 +34,7 @@ def test_dicom2stl(self): print(args) try: - dicom2stl.dicom2stl(args) + Dicom2STL(args) except BaseException: self.fail("dicom2stl: exception thrown") diff --git a/tests/test_dicomutils.py b/tests/test_dicomutils.py index 51fc5eb..da50909 100755 --- a/tests/test_dicomutils.py +++ b/tests/test_dicomutils.py @@ -8,7 +8,7 @@ import SimpleITK as sitk from tests import create_data from tests import write_series -from utils import dicomutils +from dicom2stl.utils import dicomutils class TestDicomUtils(unittest.TestCase): diff --git a/tests/test_vtkutils.py b/tests/test_vtkutils.py index 78129fd..3058997 100755 --- a/tests/test_vtkutils.py +++ b/tests/test_vtkutils.py @@ -6,7 +6,7 @@ import SimpleITK as sitk import create_data import vtk -from utils import vtkutils +from dicom2stl.utils import vtkutils class TestVTKUtils(unittest.TestCase):