Skip to content

Commit

Permalink
Merge pull request #64 from dave3d/Packaging4PyPI
Browse files Browse the repository at this point in the history
Packaging4 py pi
  • Loading branch information
dave3d authored Feb 29, 2024
2 parents a36f4f0 + 971cf67 commit 9481973
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 22 deletions.
1 change: 0 additions & 1 deletion __init__.py

This file was deleted.

33 changes: 18 additions & 15 deletions dicom2stl.py → dicom2stl/Dicom2STL.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import os
import sys
import tempfile
import shutil
import time
import zipfile
import vtk
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -297,7 +299,7 @@ def getTissueThresholds(tissueType):
return thresholds, medianFilter


def dicom2stl(args):
def Dicom2STL(args):
# Global variables
#
thresholds = []
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()
6 changes: 6 additions & 0 deletions dicom2stl/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions parseargs.py → dicom2stl/utils/parseargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_dicom2stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -34,7 +34,7 @@ def test_dicom2stl(self):
print(args)

try:
dicom2stl.dicom2stl(args)
Dicom2STL(args)
except BaseException:
self.fail("dicom2stl: exception thrown")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_dicomutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_vtkutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 9481973

Please sign in to comment.