ctkit 0.1.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.
ctkit-0.1.0/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2026, Pachter Lab
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ctkit-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.4
2
+ Name: ctkit
3
+ Version: 0.1.0
4
+ Summary: A toolkit for reproducible CT image processing for AI and radiomics.
5
+ Author-email: Joseph Rich <josephrich98@gmail.com>
6
+ Maintainer-email: Joseph Rich <josephrich98@gmail.com>
7
+ License: BSD 2-Clause License
8
+
9
+ Copyright (c) 2026, Pachter Lab
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright notice, this
15
+ list of conditions and the following disclaimer.
16
+
17
+ 2. Redistributions in binary form must reproduce the above copyright notice,
18
+ this list of conditions and the following disclaimer in the documentation
19
+ and/or other materials provided with the distribution.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+
32
+ Project-URL: Homepage, https://github.com/pachterlab/ctkit
33
+ Project-URL: Source, https://github.com/pachterlab/ctkit
34
+ Project-URL: Issues, https://github.com/pachterlab/ctkit/issues
35
+ Keywords: AI,bioinformatics,deep learning,medicine,radiology,radiomics,CT,DICOM,NIfTI,TCIA,medical imaging
36
+ Classifier: Environment :: Console
37
+ Classifier: Framework :: Jupyter
38
+ Classifier: Intended Audience :: Science/Research
39
+ Classifier: License :: OSI Approved :: BSD License
40
+ Classifier: Operating System :: OS Independent
41
+ Classifier: Programming Language :: Python :: 3.10
42
+ Classifier: Programming Language :: Python :: 3.11
43
+ Classifier: Programming Language :: Python :: 3.12
44
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
45
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
46
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
47
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
48
+ Classifier: Topic :: Utilities
49
+ Requires-Python: >=3.10
50
+ Description-Content-Type: text/markdown
51
+ License-File: LICENSE
52
+ Requires-Dist: numpy
53
+ Requires-Dist: pandas
54
+ Requires-Dist: matplotlib
55
+ Requires-Dist: tqdm
56
+ Requires-Dist: requests
57
+ Requires-Dist: pydicom
58
+ Requires-Dist: highdicom
59
+ Requires-Dist: nibabel
60
+ Requires-Dist: scipy
61
+ Requires-Dist: simpleitk
62
+ Requires-Dist: pyyaml
63
+ Requires-Dist: openpyxl
64
+ Requires-Dist: pydantic>=2
65
+ Provides-Extra: segmentation
66
+ Requires-Dist: TotalSegmentator; extra == "segmentation"
67
+ Provides-Extra: radiomics
68
+ Requires-Dist: pyradiomics; extra == "radiomics"
69
+ Provides-Extra: notebook
70
+ Requires-Dist: ipython; extra == "notebook"
71
+ Requires-Dist: ipykernel; extra == "notebook"
72
+ Requires-Dist: ipywidgets; extra == "notebook"
73
+ Provides-Extra: dicom
74
+ Requires-Dist: dcm2niix; extra == "dicom"
75
+ Provides-Extra: test
76
+ Requires-Dist: pytest; extra == "test"
77
+ Provides-Extra: all
78
+ Requires-Dist: TotalSegmentator; extra == "all"
79
+ Requires-Dist: pyradiomics; extra == "all"
80
+ Requires-Dist: ipython; extra == "all"
81
+ Requires-Dist: ipykernel; extra == "all"
82
+ Requires-Dist: ipywidgets; extra == "all"
83
+ Requires-Dist: dcm2niix; extra == "all"
84
+ Dynamic: license-file
85
+
86
+ # ctkit
87
+
88
+ CT image processing for AI and radiomics. Makes CT processing simple and reproducible.
89
+
90
+ ![pipeline](https://github.com/pachterlab/ctkit/blob/main/figures/Fig1.png?raw=true)
91
+
92
+ ## Installation
93
+
94
+ ```sh
95
+ pip install ctkit
96
+ ```
97
+
98
+ To install pyradiomics and TotalSegmentator:
99
+
100
+ ```sh
101
+ pip install 'ctkit[all]'
102
+ ```
103
+
104
+ ## Quick start
105
+
106
+ ```python
107
+ import ctkit
108
+
109
+ ctkit.download("tcga-kirc", "data/tcga_kirc_raw", limit=20)
110
+
111
+ data = ctkit.Dataset("data/tcga_kirc_raw")
112
+ data.filter(min_slices=25).process("tcga-kirc", out_dir="data/processed")
113
+ # the tcga-kirc protocol segments the kidneys, so this one needs ctkit[all]
114
+ ```
115
+
116
+ ## The pipeline
117
+
118
+ | Step | What it does | Why it matters |
119
+ | --- | --- | --- |
120
+ | `filter` | Drop series that fail quality control, keeping a pass/fail table | Localizers, reformats and 4D series are not the acquisition you meant to analyze, and finding that out after processing wastes the expensive part |
121
+ | `check` | Run the same quality control without dropping anything: a result for one series, the whole table for a cohort | The measurements behind every pass and fail, which is what an exclusion criterion has to cite |
122
+ | `orient` | Reorient to canonical RAS | Archives disagree on storage order, so two scans of the same anatomy can arrive mirrored or transposed |
123
+ | `segment` | TotalSegmentator organ masks, merged with any tumor mask | Gives a region of interest when the collection ships without one |
124
+ | `clip` | Clamp to an intensity window (e.g. −200/300 HU) | Spends the dynamic range on the tissue you care about; caps metal artifacts |
125
+ | `resample` | Resample to a fixed voxel size in mm | Until scans share a voxel grid, a millimeter of anatomy is a different number of voxels in each one |
126
+ | `select_slice` | Keep one axial slice: the one with the most mask, or the one you name (2D mode) | How a 3D series becomes a 2D training example |
127
+ | `apply_mask` | Blank outside the ROI, crop to its bounding box | Removes irrelevant anatomy and makes volumes small enough to hold a cohort in memory |
128
+ | `crop_to_content` | Crop to the voxels above a threshold — air, once intensities are clipped | Trims the air around the body when there is no mask to crop to |
129
+ | `standardize_size` | Center-crop/pad to a common array shape | Fixed-size tensors, without rescaling the anatomy |
130
+ | `normalize` | Z-score, per volume or per dataset | Stops a model keying on per-scan intensity offsets |
131
+ | `save` | Write the processed series to disk | Makes the processed dataset available for training and sharing |
132
+ | `process` | Run the whole pipeline, with a saved configuration | Reproducibility and collaboration |
133
+ | `radiomics` | Extract radiomics features | For radiomic analysis. Does not require many steps above. |
134
+
135
+ ## Reproducibility
136
+
137
+ Every run that writes a cohort to disk writes `processing_config.yaml` next to
138
+ it. To reproduce a dataset, or to hand one to a collaborator:
139
+
140
+ ```python
141
+ ctkit.Dataset("data/raw").process(
142
+ "data/processed/processing_config.yaml", out_dir="rerun"
143
+ )
144
+ ```
145
+
146
+ `process` takes a protocol as a `ProcessingConfig`, a path to a saved one, or
147
+ the name of a collection whose curated protocol to use.
148
+
149
+ ## Notebooks
150
+
151
+ [`notebooks/quickstart.ipynb`](notebooks/quickstart.ipynb) walks through the
152
+ package end to end: pick a collection, download it, filter it, process it, and
153
+ extract features.
154
+
155
+ ## Relationship to tcia-radiology-processing
156
+
157
+ This package grew out of the protocol in
158
+ [pachterlab/tcia-radiology-processing](https://github.com/pachterlab/tcia-radiology-processing),
159
+ which documents the same pipeline as a step-by-step notebook. That repository
160
+ remains the written protocol; `ctkit` is the library implementation of it.
161
+
162
+ ## License
163
+
164
+ BSD 2-Clause. See [LICENSE](LICENSE).
165
+
166
+ ---
167
+
168
+ Issues and pull requests welcome.
ctkit-0.1.0/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # ctkit
2
+
3
+ CT image processing for AI and radiomics. Makes CT processing simple and reproducible.
4
+
5
+ ![pipeline](https://github.com/pachterlab/ctkit/blob/main/figures/Fig1.png?raw=true)
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pip install ctkit
11
+ ```
12
+
13
+ To install pyradiomics and TotalSegmentator:
14
+
15
+ ```sh
16
+ pip install 'ctkit[all]'
17
+ ```
18
+
19
+ ## Quick start
20
+
21
+ ```python
22
+ import ctkit
23
+
24
+ ctkit.download("tcga-kirc", "data/tcga_kirc_raw", limit=20)
25
+
26
+ data = ctkit.Dataset("data/tcga_kirc_raw")
27
+ data.filter(min_slices=25).process("tcga-kirc", out_dir="data/processed")
28
+ # the tcga-kirc protocol segments the kidneys, so this one needs ctkit[all]
29
+ ```
30
+
31
+ ## The pipeline
32
+
33
+ | Step | What it does | Why it matters |
34
+ | --- | --- | --- |
35
+ | `filter` | Drop series that fail quality control, keeping a pass/fail table | Localizers, reformats and 4D series are not the acquisition you meant to analyze, and finding that out after processing wastes the expensive part |
36
+ | `check` | Run the same quality control without dropping anything: a result for one series, the whole table for a cohort | The measurements behind every pass and fail, which is what an exclusion criterion has to cite |
37
+ | `orient` | Reorient to canonical RAS | Archives disagree on storage order, so two scans of the same anatomy can arrive mirrored or transposed |
38
+ | `segment` | TotalSegmentator organ masks, merged with any tumor mask | Gives a region of interest when the collection ships without one |
39
+ | `clip` | Clamp to an intensity window (e.g. −200/300 HU) | Spends the dynamic range on the tissue you care about; caps metal artifacts |
40
+ | `resample` | Resample to a fixed voxel size in mm | Until scans share a voxel grid, a millimeter of anatomy is a different number of voxels in each one |
41
+ | `select_slice` | Keep one axial slice: the one with the most mask, or the one you name (2D mode) | How a 3D series becomes a 2D training example |
42
+ | `apply_mask` | Blank outside the ROI, crop to its bounding box | Removes irrelevant anatomy and makes volumes small enough to hold a cohort in memory |
43
+ | `crop_to_content` | Crop to the voxels above a threshold — air, once intensities are clipped | Trims the air around the body when there is no mask to crop to |
44
+ | `standardize_size` | Center-crop/pad to a common array shape | Fixed-size tensors, without rescaling the anatomy |
45
+ | `normalize` | Z-score, per volume or per dataset | Stops a model keying on per-scan intensity offsets |
46
+ | `save` | Write the processed series to disk | Makes the processed dataset available for training and sharing |
47
+ | `process` | Run the whole pipeline, with a saved configuration | Reproducibility and collaboration |
48
+ | `radiomics` | Extract radiomics features | For radiomic analysis. Does not require many steps above. |
49
+
50
+ ## Reproducibility
51
+
52
+ Every run that writes a cohort to disk writes `processing_config.yaml` next to
53
+ it. To reproduce a dataset, or to hand one to a collaborator:
54
+
55
+ ```python
56
+ ctkit.Dataset("data/raw").process(
57
+ "data/processed/processing_config.yaml", out_dir="rerun"
58
+ )
59
+ ```
60
+
61
+ `process` takes a protocol as a `ProcessingConfig`, a path to a saved one, or
62
+ the name of a collection whose curated protocol to use.
63
+
64
+ ## Notebooks
65
+
66
+ [`notebooks/quickstart.ipynb`](notebooks/quickstart.ipynb) walks through the
67
+ package end to end: pick a collection, download it, filter it, process it, and
68
+ extract features.
69
+
70
+ ## Relationship to tcia-radiology-processing
71
+
72
+ This package grew out of the protocol in
73
+ [pachterlab/tcia-radiology-processing](https://github.com/pachterlab/tcia-radiology-processing),
74
+ which documents the same pipeline as a step-by-step notebook. That repository
75
+ remains the written protocol; `ctkit` is the library implementation of it.
76
+
77
+ ## License
78
+
79
+ BSD 2-Clause. See [LICENSE](LICENSE).
80
+
81
+ ---
82
+
83
+ Issues and pull requests welcome.
@@ -0,0 +1,144 @@
1
+ """ctkit: reproducible CT image processing for AI and radiomics.
2
+
3
+ The package exists so that "how was this image processed?" has an exact,
4
+ runnable answer. A protocol is a :class:`ProcessingConfig`; applying it to one
5
+ scan is :class:`RadiologyImage`, and to a cohort is :class:`Dataset`.
6
+
7
+ Quick start — construct a cohort or a scan, then call the steps on it::
8
+
9
+ import ctkit
10
+
11
+ ctkit.download("tcga-kirc", "data/raw", limit=20)
12
+
13
+ data = ctkit.Dataset("data/raw")
14
+ data.filter(min_slices=25).process("tcga-kirc", out_dir="data/processed")
15
+
16
+ The same steps chain on one scan, modifying it in place::
17
+
18
+ scan = ctkit.RadiologyImage("case/imaging.nii.gz", mask="case/segmentation.nii.gz")
19
+ scan.orient().clip(-200, 300).resample((0.8, 0.8, 3.0)).save("processed/case.nii.gz")
20
+
21
+ Each step is also a function taking whatever you have — a path, an array, a
22
+ scan, or a cohort::
23
+
24
+ ctkit.clip("case/imaging.nii.gz", -200, 300)
25
+
26
+ and a field of a :class:`ProcessingConfig`, which is what makes a protocol
27
+ something you can print, save to YAML, and publish alongside a paper.
28
+
29
+ Nothing is written to disk until ``save()``; intermediate volumes only ever
30
+ exist in memory.
31
+ """
32
+
33
+ from __future__ import annotations
34
+
35
+ from importlib import import_module
36
+ from typing import TYPE_CHECKING
37
+
38
+ __version__ = "0.1.0"
39
+
40
+ from .api import (
41
+ apply_mask,
42
+ check,
43
+ clip,
44
+ crop_to_content,
45
+ filter,
46
+ normalize,
47
+ orient,
48
+ process,
49
+ radiomics,
50
+ resample,
51
+ save,
52
+ segment,
53
+ select_slice,
54
+ standardize_size,
55
+ )
56
+ from .config import ProcessingConfig
57
+ from .constants import tcia_dataset_to_info
58
+ from .dataset import Dataset
59
+ from .datasets import EXTRA_CT_COLLECTIONS, get_dataset_info, list_datasets
60
+ from .image import RadiologyImage
61
+ from .io import dicom_to_nifti, load_image, save_image
62
+ from .metadata import annotate, categorize_phase, categorize_region, summarize
63
+ from .qc import QCCriteria, QCResult, check_series_metadata, check_volume
64
+
65
+ if TYPE_CHECKING: # pragma: no cover
66
+ from . import features, segmentation
67
+ from .tcia import download, list_collections
68
+
69
+ __all__ = [
70
+ "__version__",
71
+ # pipeline steps, in the order they run
72
+ "filter",
73
+ "orient",
74
+ "segment",
75
+ "clip",
76
+ "resample",
77
+ "select_slice",
78
+ "apply_mask",
79
+ "crop_to_content",
80
+ "standardize_size",
81
+ "normalize",
82
+ # whole protocols and output
83
+ "process",
84
+ "save",
85
+ "radiomics",
86
+ # core
87
+ "RadiologyImage",
88
+ "Dataset",
89
+ "ProcessingConfig",
90
+ # quality control
91
+ "QCCriteria",
92
+ "QCResult",
93
+ "check",
94
+ "check_volume",
95
+ "check_series_metadata",
96
+ # data access
97
+ "download",
98
+ "download_supplementary",
99
+ "list_collections",
100
+ "list_datasets",
101
+ "get_dataset_info",
102
+ "EXTRA_CT_COLLECTIONS",
103
+ "tcia_dataset_to_info",
104
+ # io
105
+ "load_image",
106
+ "save_image",
107
+ "dicom_to_nifti",
108
+ # metadata
109
+ "categorize_region",
110
+ "categorize_phase",
111
+ "annotate",
112
+ "summarize",
113
+ # submodules
114
+ "features",
115
+ "segmentation",
116
+ "tcia",
117
+ "metadata",
118
+ ]
119
+
120
+ #: Attributes served on first use, so that importing the package does not pull
121
+ #: in `requests`, `pyradiomics` or `matplotlib`.
122
+ _LAZY = {
123
+ "download": ("tcia", "download"),
124
+ "download_supplementary": ("tcia", "download_supplementary"),
125
+ "list_collections": ("tcia", "list_collections"),
126
+ "download_with_nbia_retriever": ("tcia", "download_with_nbia_retriever"),
127
+ "get_series": ("tcia", "get_series"),
128
+ "extract_features": ("features", "extract_features"),
129
+ "segment_organs": ("segmentation", "segment_organs"),
130
+ }
131
+ _LAZY_MODULES = {"features", "segmentation", "tcia", "io", "qc", "datasets", "metadata"}
132
+
133
+
134
+ def __getattr__(name: str):
135
+ if name in _LAZY:
136
+ module_name, attribute = _LAZY[name]
137
+ return getattr(import_module(f".{module_name}", __name__), attribute)
138
+ if name in _LAZY_MODULES:
139
+ return import_module(f".{name}", __name__)
140
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
141
+
142
+
143
+ def __dir__() -> list:
144
+ return sorted(set(__all__) | set(globals()))