DLICV 0.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ 0.0.0
File without changes
@@ -0,0 +1,73 @@
1
+ import sys
2
+ import argparse
3
+ import shutil
4
+ from pathlib import Path
5
+ import tempfile
6
+ from DLICV.compute_icv import compute_volume
7
+
8
+ def validate_path(parser, arg):
9
+ """Ensure the provided path exists."""
10
+ if not Path(arg).exists():
11
+ parser.error(f"The path {arg} does not exist.")
12
+ sys.exit(1)
13
+ return arg
14
+
15
+ def copy_and_rename_inputs(input_path, destination_dir):
16
+ """Copy and rename input files according to nnUNet convention."""
17
+ input_path = Path(input_path)
18
+ destination_dir = Path(destination_dir)
19
+
20
+ if input_path.is_dir():
21
+ for filepath in input_path.glob('*.nii.gz'):
22
+ new_filename = filepath.stem.split('.')[0] + '_0000.nii.gz'
23
+ shutil.copy(filepath, destination_dir / new_filename)
24
+ else:
25
+ new_filename = input_path.stem + '_0000.nii.gz'
26
+ shutil.copy(input_path, destination_dir / new_filename)
27
+
28
+ def main():
29
+ """Main function to manage the prediction workflow."""
30
+ parser = argparse.ArgumentParser(description="DLICV - Deep Learning Intra Cranial Volume")
31
+ parser.add_argument("-i","--input", required=True, type=lambda x: validate_path(parser, x), help="Input .nii.gz image or folder path.")
32
+ parser.add_argument("-o","--output", required=True, help="Output image or folder path. If folder path, it should exist.")
33
+ parser.add_argument("-m","--model", required=True, type=lambda x: validate_path(parser, x), help="Model path.")
34
+ parser.add_argument("-v","--version", action="version", version=Path(__file__).with_name("VERSION").read_text().strip(), help="Show program's version number and exit.")
35
+ parser.add_argument("--kwargs", nargs=argparse.REMAINDER, help="Additional keyword arguments to pass to compute_icv.py")
36
+
37
+ args = parser.parse_args()
38
+
39
+ kwargs = {}
40
+ if args.kwargs:
41
+ for kwarg in args.kwargs:
42
+ key, value = kwarg.split('=', 1)
43
+ kwargs[key] = value
44
+
45
+ input_path, output_path, model_path = args.input, args.output, args.model
46
+
47
+ # Create cross-platform temp dir, and child dirs that nnUNet needs
48
+ with tempfile.TemporaryDirectory() as temp_dir:
49
+ temp_input_dir = Path(temp_dir) / "nnUNet_raw_data"
50
+ temp_preprocessed_dir = Path(temp_dir) / "nnUNet_preprocessed"
51
+ temp_output_dir = Path(temp_dir) / "nnUNet_out"
52
+ temp_input_dir.mkdir()
53
+ temp_output_dir.mkdir()
54
+
55
+ copy_and_rename_inputs(input_path, temp_input_dir)
56
+ compute_volume(
57
+ str(temp_input_dir),
58
+ str(temp_output_dir),
59
+ model_path,
60
+ **kwargs
61
+ )
62
+
63
+ # Move results to the specified output location, including only .nii.gz files
64
+ for file in temp_output_dir.iterdir():
65
+ if file.suffixes == ['.nii', '.gz']:
66
+ shutil.move(str(file), output_path)
67
+ print()
68
+ print()
69
+ print()
70
+ print(f"Prediction complete. Results saved to {output_path}")
71
+
72
+ if __name__ == "__main__":
73
+ main()
@@ -0,0 +1,63 @@
1
+ def compute_volume(input_path, output_path, model_path, **kwargs):
2
+ """
3
+ Compute the intracranial volume from the input image using the nnUNet model.
4
+ :param input_path: Path to the input image (single image or directory of images).
5
+ :param output_path: Path for the output image (single image or directory of images).
6
+ :param model_path: Path to the model to be applied, or 'default'.
7
+ :param kwargs: Additional keyword arguments for the predict_from_folder function.
8
+ :return: The output image with the computed volume or a list of output images.
9
+ """
10
+ from nnunet.inference.predict import predict_from_folder
11
+
12
+ # FROM nnUNet docs: (https://github.com/MIC-DKFZ/nnUNet/blob/nnunetv1/nnunet/inference/predict.py#L614)
13
+ # predict_from_folder( model: str, "model output folder. Will automatically discover the folds "
14
+ # input_folder: str, "Must contain all modalities for each patient in the correct order (same as training). Files must be named CASENAME_XXXX.nii.gz where XXXX is the modality identifier (0000, 0001, etc)", required=True
15
+ # output_folder: str, "folder for saving predictions"
16
+ # folds: Union[Tuple[int], List[int]],"folds to use for prediction. Default is None which means that folds will be detected automatically in the model output folder"
17
+ # save_npz: bool, "use this if you want to ensemble these predictions with those of other models. Softmax probabilities will be saved as compresed numpy arrays in output_folder and can be merged between output_folders with merge_predictions.py"
18
+ # num_threads_preprocessing: int, "Determines many background processes will be used for data preprocessing. Reduce this if you run into out of memory (RAM) problems. Default: 6"
19
+ # num_threads_nifti_save: int, "Determines many background processes will be used for segmentation export. Reduce this if you run into out of memory (RAM) problems. Default: 6"
20
+ # lowres_segmentations: Union[str, None], "if model is the highres stage of the cascade then you need to use -l to specify where the segmentations of the corresponding lowres unet are. Here they are required to do a prediction"
21
+ # part_id: int, "Used to parallelize the prediction of the folder over several GPUs. If you want to use n GPUs to predict this folder you need to run this command n times with --part_id=0, ... n-1 and --num_parts=n (each with a different GPU (for example via CUDA_VISIBLE_DEVICES=X)"
22
+ # num_parts: int, "Used to parallelize the prediction of the folder over several GPUs. If you want to use n GPUs to predict this folder you need to run this command n times with --part_id=0, ... n-1 and --num_parts=n (each with a different GPU (for example via CUDA_VISIBLE_DEVICES=X)"
23
+ # tta: bool, "Set to 0 to disable test time data augmentation (speedup of factor 4(2D)/8(3D)), lower quality segmentations"
24
+ # mixed_precision: bool = True, 'Predictions are done with mixed precision by default. This improves speed and reduces the required vram. If you want to disable mixed precision you can set this flag. Note that this is not recommended (mixed precision is ~2x faster!)'
25
+ # overwrite_existing: bool = True, "Set this to 0 if you need to resume a previous prediction. Default: 1 (=existing segmentations in output_folder will be overwritten)"
26
+ # mode: str = 'normal', "'normal' or 'fast' or 'fastest'"
27
+ # overwrite_all_in_gpu: bool = None, "can be None, False or True"
28
+ # step_size: float = 0.5, "don't touch"
29
+ # checkpoint_name: str = "model_final_checkpoint",
30
+ # segmentation_export_kwargs: dict = None,
31
+ # disable_postprocessing: bool = False):
32
+
33
+ # FOR THE PRETRAINED MODEL WITH TASK_ID = 802 AKA DLICV
34
+ # Default values for predict_from_folder parameters
35
+ default_params = {
36
+ 'folds': [1],
37
+ 'save_npz': False,
38
+ 'num_threads_preprocessing': 6,
39
+ 'num_threads_nifti_save': 6,
40
+ 'lowres_segmentations': None,
41
+ 'part_id': 0, # Change this if multiple GPUs are present
42
+ 'num_parts': 1,
43
+ 'tta': 0,
44
+ 'mixed_precision': True,
45
+ 'overwrite_existing': False,
46
+ 'mode': 'fastest',
47
+ 'overwrite_all_in_gpu': 1,
48
+ 'step_size': 0.5,
49
+ 'checkpoint_name': "model_final_checkpoint",
50
+ 'segmentation_export_kwargs': None,
51
+ 'disable_postprocessing': False
52
+ }
53
+
54
+ # Update default parameters with any additional keyword arguments provided
55
+ params = {**default_params, **kwargs}
56
+
57
+ # Call predict_from_folder with updated parameters
58
+ predict_from_folder(model_path,
59
+ input_path,
60
+ output_path,
61
+ **params)
62
+
63
+ return
@@ -0,0 +1,107 @@
1
+ Metadata-Version: 2.1
2
+ Name: DLICV
3
+ Version: 0.0.0
4
+ Summary: DLICV - Deep Learning Intra Cranial Volume
5
+ Home-page: https://github.com/georgeaidinis/DLICV/
6
+ Download-URL: https://github.com/georgeaidinis/DLICV/
7
+ Author: Ashish Singh, Guray Erus, Vishnu Bashyam, George Aidinis
8
+ Author-email: software@cbica.upenn.edu
9
+ Maintainer: George Aidinis
10
+ Maintainer-email: aidinisg@pennmedicine.upenn.edu
11
+ License: By installing/using DeepMRSeg, the user agrees to the following license: See https://www.med.upenn.edu/cbica/software-agreement-non-commercial.html
12
+ Keywords: deep learning,image segmentation,semantic segmentation,medical image analysis,medical image segmentation,nnU-Net,nnunet
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Intended Audience :: Healthcare Industry
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
19
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: nnunet>=1.7.0
23
+ Requires-Dist: torch<2.1,>2.0
24
+ Provides-Extra: test
25
+ Requires-Dist: nnunet>=1.7.0; extra == "test"
26
+ Requires-Dist: torch<2.1,>2.0; extra == "test"
27
+ Requires-Dist: pytest>=7.0.0; extra == "test"
28
+
29
+ # DLICV - Deep Learning Intra Cranial Volume
30
+
31
+ ## Overview
32
+
33
+ DLICV uses a trained [nnUNet](https://github.com/MIC-DKFZ/nnUNet/tree/nnunetv1) model to compute the intracranial volume from structural MRI scans in the nifti image format, oriented in _**LPS**_ orientation.
34
+
35
+ ## Installation
36
+
37
+ ### As a python package
38
+
39
+ ```bash
40
+ pip install dlicv
41
+ ```
42
+
43
+ ### Directly from this repository
44
+
45
+ ```bash
46
+ git clone https://github.com/georgeaidinis/DLICV
47
+ cd DLICV
48
+ conda create -n DLICV -y python=3.8 && conda activate DLICV
49
+ pip install .
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ A pre-trained nnUNet model can be found in the [DLICV-0.0.0 release](https://github.com/georgeaidinis/DLICV/releases/tag/v0.0.0) as an [artifact](https://github.com/georgeaidinis/DLICV/releases/download/v0.0.0/model.zip). Feel free to use it under the package's [license](LICENSE).
55
+
56
+ ### Import as a python package
57
+
58
+ ```python
59
+ from dlicv.compute_icv import compute_volume
60
+
61
+ # Assuming your nifti file is named 'input.nii.gz'
62
+ volume_image = compute_volume("input.nii.gz", "output.nii.gz", "path/to/model/")
63
+ ```
64
+
65
+ ### From the terminal
66
+
67
+ ```bash
68
+ DLICV --input input.nii.gz --output output.nii.gz --model path/to/model
69
+ ```
70
+
71
+ Replace the `input.nii.gz` with the path to your input nifti file, as well as the model path.
72
+
73
+ Example:
74
+
75
+ Assuming a file structure like so:
76
+
77
+ ```bash
78
+ .
79
+ ├── in
80
+ │   ├── input1.nii.gz
81
+ │   ├── input2.nii.gz
82
+ │   └── input3.nii.gz
83
+ ├── model
84
+ │   ├── fold_0
85
+ │   ├── fold_1
86
+ │   │   ├── debug.json
87
+ │   │   ├── model_final_checkpoint.model
88
+ │   │   ├── model_final_checkpoint.model.pkl
89
+ │   │   ├── model_latest.model
90
+ │   │   ├── model_latest.model.pkl
91
+ │   └── plans.pkl
92
+ └── out
93
+ ```
94
+
95
+ An example command might be:
96
+
97
+ ```bash
98
+ DLICV --input path/to/input/ --output path/to/output/ --model path/to/model/
99
+ ```
100
+
101
+ ### Using the docker container
102
+
103
+ In the docker container, the.
104
+
105
+ ## Contact
106
+
107
+ For more information, please contact [CBICA Software](mailto:software@cbica.upenn.edu).
@@ -0,0 +1,18 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ requirements-dev.txt
5
+ requirements-test.txt
6
+ requirements.txt
7
+ setup.py
8
+ DLICV/VERSION
9
+ DLICV/__init__.py
10
+ DLICV/__main__.py
11
+ DLICV/compute_icv.py
12
+ DLICV.egg-info/PKG-INFO
13
+ DLICV.egg-info/SOURCES.txt
14
+ DLICV.egg-info/dependency_links.txt
15
+ DLICV.egg-info/entry_points.txt
16
+ DLICV.egg-info/requires.txt
17
+ DLICV.egg-info/top_level.txt
18
+ tests/test_main.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ DLICV = DLICV.__main__:main
@@ -0,0 +1,7 @@
1
+ nnunet>=1.7.0
2
+ torch<2.1,>2.0
3
+
4
+ [test]
5
+ nnunet>=1.7.0
6
+ torch<2.1,>2.0
7
+ pytest>=7.0.0
@@ -0,0 +1 @@
1
+ DLICV
DLICV-0.0.0/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ By installing/using DeepMRSeg, the user agrees to the following license:
2
+
3
+ See https://www.med.upenn.edu/cbica/software-agreement-non-commercial.html
@@ -0,0 +1,2 @@
1
+ include DLICV/VERSION*
2
+ include requirements*
DLICV-0.0.0/PKG-INFO ADDED
@@ -0,0 +1,107 @@
1
+ Metadata-Version: 2.1
2
+ Name: DLICV
3
+ Version: 0.0.0
4
+ Summary: DLICV - Deep Learning Intra Cranial Volume
5
+ Home-page: https://github.com/georgeaidinis/DLICV/
6
+ Download-URL: https://github.com/georgeaidinis/DLICV/
7
+ Author: Ashish Singh, Guray Erus, Vishnu Bashyam, George Aidinis
8
+ Author-email: software@cbica.upenn.edu
9
+ Maintainer: George Aidinis
10
+ Maintainer-email: aidinisg@pennmedicine.upenn.edu
11
+ License: By installing/using DeepMRSeg, the user agrees to the following license: See https://www.med.upenn.edu/cbica/software-agreement-non-commercial.html
12
+ Keywords: deep learning,image segmentation,semantic segmentation,medical image analysis,medical image segmentation,nnU-Net,nnunet
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Intended Audience :: Healthcare Industry
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
19
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: nnunet>=1.7.0
23
+ Requires-Dist: torch<2.1,>2.0
24
+ Provides-Extra: test
25
+ Requires-Dist: nnunet>=1.7.0; extra == "test"
26
+ Requires-Dist: torch<2.1,>2.0; extra == "test"
27
+ Requires-Dist: pytest>=7.0.0; extra == "test"
28
+
29
+ # DLICV - Deep Learning Intra Cranial Volume
30
+
31
+ ## Overview
32
+
33
+ DLICV uses a trained [nnUNet](https://github.com/MIC-DKFZ/nnUNet/tree/nnunetv1) model to compute the intracranial volume from structural MRI scans in the nifti image format, oriented in _**LPS**_ orientation.
34
+
35
+ ## Installation
36
+
37
+ ### As a python package
38
+
39
+ ```bash
40
+ pip install dlicv
41
+ ```
42
+
43
+ ### Directly from this repository
44
+
45
+ ```bash
46
+ git clone https://github.com/georgeaidinis/DLICV
47
+ cd DLICV
48
+ conda create -n DLICV -y python=3.8 && conda activate DLICV
49
+ pip install .
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ A pre-trained nnUNet model can be found in the [DLICV-0.0.0 release](https://github.com/georgeaidinis/DLICV/releases/tag/v0.0.0) as an [artifact](https://github.com/georgeaidinis/DLICV/releases/download/v0.0.0/model.zip). Feel free to use it under the package's [license](LICENSE).
55
+
56
+ ### Import as a python package
57
+
58
+ ```python
59
+ from dlicv.compute_icv import compute_volume
60
+
61
+ # Assuming your nifti file is named 'input.nii.gz'
62
+ volume_image = compute_volume("input.nii.gz", "output.nii.gz", "path/to/model/")
63
+ ```
64
+
65
+ ### From the terminal
66
+
67
+ ```bash
68
+ DLICV --input input.nii.gz --output output.nii.gz --model path/to/model
69
+ ```
70
+
71
+ Replace the `input.nii.gz` with the path to your input nifti file, as well as the model path.
72
+
73
+ Example:
74
+
75
+ Assuming a file structure like so:
76
+
77
+ ```bash
78
+ .
79
+ ├── in
80
+ │   ├── input1.nii.gz
81
+ │   ├── input2.nii.gz
82
+ │   └── input3.nii.gz
83
+ ├── model
84
+ │   ├── fold_0
85
+ │   ├── fold_1
86
+ │   │   ├── debug.json
87
+ │   │   ├── model_final_checkpoint.model
88
+ │   │   ├── model_final_checkpoint.model.pkl
89
+ │   │   ├── model_latest.model
90
+ │   │   ├── model_latest.model.pkl
91
+ │   └── plans.pkl
92
+ └── out
93
+ ```
94
+
95
+ An example command might be:
96
+
97
+ ```bash
98
+ DLICV --input path/to/input/ --output path/to/output/ --model path/to/model/
99
+ ```
100
+
101
+ ### Using the docker container
102
+
103
+ In the docker container, the.
104
+
105
+ ## Contact
106
+
107
+ For more information, please contact [CBICA Software](mailto:software@cbica.upenn.edu).
DLICV-0.0.0/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # DLICV - Deep Learning Intra Cranial Volume
2
+
3
+ ## Overview
4
+
5
+ DLICV uses a trained [nnUNet](https://github.com/MIC-DKFZ/nnUNet/tree/nnunetv1) model to compute the intracranial volume from structural MRI scans in the nifti image format, oriented in _**LPS**_ orientation.
6
+
7
+ ## Installation
8
+
9
+ ### As a python package
10
+
11
+ ```bash
12
+ pip install dlicv
13
+ ```
14
+
15
+ ### Directly from this repository
16
+
17
+ ```bash
18
+ git clone https://github.com/georgeaidinis/DLICV
19
+ cd DLICV
20
+ conda create -n DLICV -y python=3.8 && conda activate DLICV
21
+ pip install .
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ A pre-trained nnUNet model can be found in the [DLICV-0.0.0 release](https://github.com/georgeaidinis/DLICV/releases/tag/v0.0.0) as an [artifact](https://github.com/georgeaidinis/DLICV/releases/download/v0.0.0/model.zip). Feel free to use it under the package's [license](LICENSE).
27
+
28
+ ### Import as a python package
29
+
30
+ ```python
31
+ from dlicv.compute_icv import compute_volume
32
+
33
+ # Assuming your nifti file is named 'input.nii.gz'
34
+ volume_image = compute_volume("input.nii.gz", "output.nii.gz", "path/to/model/")
35
+ ```
36
+
37
+ ### From the terminal
38
+
39
+ ```bash
40
+ DLICV --input input.nii.gz --output output.nii.gz --model path/to/model
41
+ ```
42
+
43
+ Replace the `input.nii.gz` with the path to your input nifti file, as well as the model path.
44
+
45
+ Example:
46
+
47
+ Assuming a file structure like so:
48
+
49
+ ```bash
50
+ .
51
+ ├── in
52
+ │   ├── input1.nii.gz
53
+ │   ├── input2.nii.gz
54
+ │   └── input3.nii.gz
55
+ ├── model
56
+ │   ├── fold_0
57
+ │   ├── fold_1
58
+ │   │   ├── debug.json
59
+ │   │   ├── model_final_checkpoint.model
60
+ │   │   ├── model_final_checkpoint.model.pkl
61
+ │   │   ├── model_latest.model
62
+ │   │   ├── model_latest.model.pkl
63
+ │   └── plans.pkl
64
+ └── out
65
+ ```
66
+
67
+ An example command might be:
68
+
69
+ ```bash
70
+ DLICV --input path/to/input/ --output path/to/output/ --model path/to/model/
71
+ ```
72
+
73
+ ### Using the docker container
74
+
75
+ In the docker container, the.
76
+
77
+ ## Contact
78
+
79
+ For more information, please contact [CBICA Software](mailto:software@cbica.upenn.edu).
@@ -0,0 +1,2 @@
1
+ nnunet>=1.7.0
2
+ torch>2.0,<2.1
@@ -0,0 +1,3 @@
1
+ nnunet>=1.7.0
2
+ torch>2.0,<2.1
3
+ pytest>=7.0.0
@@ -0,0 +1,2 @@
1
+ nnunet>=1.7.0
2
+ torch>2.0,<2.1
DLICV-0.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
DLICV-0.0.0/setup.py ADDED
@@ -0,0 +1,64 @@
1
+ """Setup tool for DLICV."""
2
+
3
+ import io
4
+ import os
5
+ from setuptools import find_packages, setup
6
+
7
+
8
+ def read(*paths, **kwargs):
9
+ """Read the contents of a text file safely."""
10
+
11
+ content = ""
12
+ with io.open(
13
+ os.path.join(os.path.dirname(__file__), *paths),
14
+ encoding=kwargs.get("encoding", "utf8"),
15
+ ) as open_file:
16
+ content = open_file.read().strip()
17
+ return content
18
+
19
+
20
+ def read_requirements(path):
21
+ return [
22
+ line.strip()
23
+ for line in read(path).split("\n")
24
+ if not line.startswith(('"', "#", "-", "git+"))
25
+ ]
26
+
27
+
28
+ setup(
29
+ name="DLICV",
30
+ version=read("DLICV", "VERSION"),
31
+ description="DLICV - Deep Learning Intra Cranial Volume",
32
+ long_description=read("README.md"),
33
+ long_description_content_type="text/markdown",
34
+ author="Ashish Singh, Guray Erus, Vishnu Bashyam, George Aidinis",
35
+ author_email="software@cbica.upenn.edu",
36
+ maintainer="George Aidinis",
37
+ maintainer_email="aidinisg@pennmedicine.upenn.edu",
38
+ download_url="https://github.com/georgeaidinis/DLICV/",
39
+ url="https://github.com/georgeaidinis/DLICV/",
40
+ packages=find_packages(exclude=["tests", ".github"]),
41
+ install_requires=read_requirements("requirements.txt"),
42
+ entry_points={"console_scripts": ["DLICV = DLICV.__main__:main"]},
43
+ extras_require={"test": read_requirements("requirements-test.txt")},
44
+ classifiers=[
45
+ "Intended Audience :: Developers",
46
+ "Intended Audience :: Science/Research",
47
+ "Intended Audience :: Healthcare Industry",
48
+ "Programming Language :: Python :: 3",
49
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
50
+ "Topic :: Scientific/Engineering :: Image Processing",
51
+ "Topic :: Scientific/Engineering :: Medical Science Apps.",
52
+ ],
53
+ license="By installing/using DeepMRSeg, the user agrees to the following license: See https://www.med.upenn.edu/cbica/software-agreement-non-commercial.html",
54
+ keywords = [
55
+ 'deep learning',
56
+ 'image segmentation',
57
+ 'semantic segmentation',
58
+ 'medical image analysis',
59
+ 'medical image segmentation',
60
+ 'nnU-Net',
61
+ 'nnunet'
62
+ ],
63
+ package_data={"DLICV": ["VERSION"]},
64
+ )
@@ -0,0 +1,61 @@
1
+ # content of tests/test_main.py
2
+
3
+ import pytest
4
+ import shutil
5
+ from DLICV.__main__ import main, validate_path, copy_and_rename_inputs
6
+ from unittest.mock import patch, MagicMock
7
+ from pathlib import Path
8
+
9
+ # Fixture for creating mock paths
10
+ @pytest.fixture
11
+ def mock_paths(tmp_path):
12
+ input_path = tmp_path / "input"
13
+ input_path.mkdir()
14
+ (input_path / "test.nii.gz").write_text("dummy nii data")
15
+
16
+ output_path = tmp_path / "output"
17
+ output_path.mkdir()
18
+
19
+ model_path = tmp_path / "model"
20
+ model_path.mkdir()
21
+ (model_path / "model.pkl").write_text("dummy model data")
22
+
23
+ return input_path, output_path, model_path
24
+
25
+ # Fixture for setting up argparse arguments
26
+ @pytest.fixture
27
+ def setup_args(mock_paths):
28
+ input_path, output_path, model_path = mock_paths
29
+ return [
30
+ '--input', str(input_path),
31
+ '--output', str(output_path),
32
+ '--model', str(model_path),
33
+ # Add other necessary arguments here
34
+ ]
35
+
36
+ # Use the fixtures to provide the paths for each test function
37
+ def test_validate_path_existing(mock_paths):
38
+ input_path, _, _ = mock_paths
39
+ assert validate_path(MagicMock(), str(input_path)) == str(input_path)
40
+
41
+ def test_validate_path_non_existing():
42
+ with pytest.raises(SystemExit):
43
+ validate_path(MagicMock(), 'non_existing_path')
44
+
45
+ def test_copy_and_rename_inputs_file(mock_paths):
46
+ input_path, output_path, _ = mock_paths
47
+ # ...
48
+
49
+ def test_copy_and_rename_inputs_directory(mock_paths):
50
+ input_path, output_path, _ = mock_paths
51
+ # ...
52
+
53
+ # Example of a more complex test using the setup_args fixture
54
+ @patch('DLICV.__main__.compute_volume')
55
+ def test_main_end_to_end(mock_compute_volume, setup_args):
56
+ args = setup_args
57
+ with patch('sys.argv', ['__main__.py'] + args):
58
+ main()
59
+ # Assert statements to verify behavior
60
+
61
+ # Place additional tests here, expanding on the simple structure above