synthrad-sct 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.
@@ -0,0 +1,194 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Abstra
171
+ # Abstra is an AI-powered process automation framework.
172
+ # Ignore directories containing user credentials, local state, and settings.
173
+ # Learn more at https://abstra.io/docs
174
+ .abstra/
175
+
176
+ # Visual Studio Code
177
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
178
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
179
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
180
+ # you could uncomment the following to ignore the enitre vscode folder
181
+ # .vscode/
182
+
183
+ # Ruff stuff:
184
+ .ruff_cache/
185
+
186
+ # PyPI configuration file
187
+ .pypirc
188
+
189
+ # Cursor
190
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
191
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
192
+ # refer to https://docs.cursor.com/context/ignore-files
193
+ .cursorignore
194
+ .cursorindexingignore
@@ -0,0 +1,129 @@
1
+ Metadata-Version: 2.5
2
+ Name: synthrad-sct
3
+ Version: 0.1.0
4
+ Summary: One-command installer for the COMP3888 P40 abdomen MRI-to-sCT models
5
+ Project-URL: Source, https://github.sydney.edu.au/fyan0582/COMP3888_W11_04_P40/tree/main/installer
6
+ Project-URL: Weights, https://github.sydney.edu.au/dmat0262/synthrad-sct-weights
7
+ Author: COMP3888 W11-04 P40
8
+ Keywords: installer,medical-imaging,mri,synthetic-ct,synthrad
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
14
+ Requires-Python: >=3.9
15
+ Requires-Dist: pyyaml>=6
16
+ Requires-Dist: questionary>=2
17
+ Requires-Dist: rich>=13
18
+ Description-Content-Type: text/markdown
19
+
20
+ # synthrad-sct installer
21
+
22
+ One command that sets up the abdomen MRI-to-sCT models from this repository:
23
+ it clones the code, builds a Python 3.11 environment, downloads the trained
24
+ weights, checks them, and runs a smoke test. No retraining.
25
+
26
+ ## For the client
27
+
28
+ You need [uv](https://docs.astral.sh/uv/getting-started/installation/),
29
+ git and the [GitHub CLI](https://cli.github.com), plus read access to this
30
+ repository and [dmat0262/synthrad-sct-weights](https://github.sydney.edu.au/dmat0262/synthrad-sct-weights)
31
+ on `github.sydney.edu.au` (on campus or VPN). You do not need to clone anything.
32
+
33
+ Log in once, so that uv, git and the installer reuse the same login and never ask for a token:
34
+
35
+ ```bash
36
+ gh auth login --hostname github.sydney.edu.au
37
+ uvx synthrad-sct init
38
+ ```
39
+
40
+ The installer asks a few questions:
41
+
42
+ 1. **GitHub token**, only if you skipped `gh auth login`. Make one at
43
+ <https://github.sydney.edu.au/settings/tokens/new?scopes=repo>, or set
44
+ `SYNTHRAD_GITHUB_TOKEN`.
45
+ 2. **Where to clone.** Skipped if you run it inside an existing clone.
46
+ 3. **Which models.** B6 and B2 are pre-selected.
47
+ 4. **CPU or CUDA.** Detected automatically. On macOS it is always CPU.
48
+ 5. **Web previewer.** Optionally installs the Gradio demo, which supports B2 or B3.
49
+
50
+ Then it:
51
+
52
+ - creates `.venv` with Python 3.11, which uv downloads if needed;
53
+ - installs PyTorch 2.5.1 and the pinned NumPy/SimpleITK/SciPy versions the
54
+ weights were trained with;
55
+ - downloads each `epoch_0400.pt` and checks its SHA-256 against the hash
56
+ recorded with the test results;
57
+ - puts each file where the inference code already looks:
58
+ `<experiment>/checkpoints_AB_400epochs/<run>/epoch_0400.pt`;
59
+ - writes `ct_free_inference/configs/inference.local.yaml`;
60
+ - runs `ct_free_inference/smoke_models.py` on the downloaded weights.
61
+
62
+ If a download is interrupted, run the command again. It resumes and skips
63
+ anything already downloaded and checked.
64
+
65
+ | Model | What it is | Test MAE (HU) | Evidence |
66
+ | --- | --- | ---: | --- |
67
+ | B6 | 2.5D U-Net + PatchGAN, 5 slices, GAN weight 0.01 | 108.80 | MRI-only pipeline |
68
+ | B2 | 2.5D U-Net + PatchGAN, 5 slices, 256 crop | 113.03 | historical paired workflow |
69
+ | B0 | 2D U-Net + PatchGAN, centre slice | 114.20 | historical paired workflow |
70
+ | B3 | 2.5D U-Net + PatchGAN, 5 slices, 512 crop | 118.00 | historical paired workflow |
71
+
72
+ See [AB_EXPERIMENTS_README.md](https://github.sydney.edu.au/fyan0582/COMP3888_W11_04_P40/blob/main/AB_EXPERIMENTS_README.md) for what the
73
+ evidence columns mean.
74
+
75
+ ### Other commands
76
+
77
+ ```bash
78
+ synthrad-sct list # models, scores, which are installed
79
+ synthrad-sct doctor # check git/uv/token/GPU/.venv/weights
80
+ synthrad-sct download --models B3 B0 # add weights to an existing setup
81
+ synthrad-sct init -y --models B6 --device cpu --no-previewer # no prompts
82
+ ```
83
+
84
+ Prefix each with `uvx`, or install once with `uv tool install synthrad-sct`.
85
+ Without PyPI, the same CLI runs straight from Git:
86
+ `uvx --from "git+https://github.sydney.edu.au/fyan0582/COMP3888_W11_04_P40.git#subdirectory=installer" synthrad-sct init`.
87
+
88
+ ## For the team: publishing the weights
89
+
90
+ The weights are files on the `weights-v1` release of
91
+ [dmat0262/synthrad-sct-weights](https://github.sydney.edu.au/dmat0262/synthrad-sct-weights),
92
+ kept apart from this course repository so they outlive it. They are never
93
+ committed to Git: GitHub rejects files over 100 MB. You need the [GitHub CLI](https://cli.github.com) logged in
94
+ with `gh auth login --hostname github.sydney.edu.au`.
95
+
96
+ ```bash
97
+ cd installer
98
+ uv run synthrad-sct publish --dry-run B0=/path/B0/epoch_0400.pt B2=/path/B2/epoch_0400.pt \
99
+ B3=/path/B3/epoch_0400.pt B6=/path/B6/epoch_0400.pt
100
+ # then the same command without --dry-run
101
+ ```
102
+
103
+ `publish` first writes the weights repository's `README.md` (a model card)
104
+ and `SHA256SUMS` from the pinned table, then creates the release if needed and
105
+ uploads the files. It refuses any file whose SHA-256 differs from the checkpoint the
106
+ reported results came from. Hashes are pinned in
107
+ `src/synthrad_sct/models.py`, and the tests check them against `results/` and
108
+ `metadata/`. If a model is retrained, update the recorded results and the
109
+ pinned hash together, and publish under a new tag.
110
+
111
+ ## Releasing to PyPI
112
+
113
+ Bump `version` in `pyproject.toml` and `__init__.py`, then:
114
+
115
+ ```bash
116
+ cd installer
117
+ rm -rf dist && uv build
118
+ UV_PUBLISH_TOKEN=pypi-… uv publish
119
+ ```
120
+
121
+ If the package is ever removed from PyPI, switch the commands in this README and
122
+ `weights_repo.INSTALL` back to the Git form first.
123
+
124
+ ## Tests
125
+
126
+ ```bash
127
+ cd installer
128
+ uv run --with numpy --with SimpleITK python -m unittest discover -s tests -v
129
+ ```
@@ -0,0 +1,110 @@
1
+ # synthrad-sct installer
2
+
3
+ One command that sets up the abdomen MRI-to-sCT models from this repository:
4
+ it clones the code, builds a Python 3.11 environment, downloads the trained
5
+ weights, checks them, and runs a smoke test. No retraining.
6
+
7
+ ## For the client
8
+
9
+ You need [uv](https://docs.astral.sh/uv/getting-started/installation/),
10
+ git and the [GitHub CLI](https://cli.github.com), plus read access to this
11
+ repository and [dmat0262/synthrad-sct-weights](https://github.sydney.edu.au/dmat0262/synthrad-sct-weights)
12
+ on `github.sydney.edu.au` (on campus or VPN). You do not need to clone anything.
13
+
14
+ Log in once, so that uv, git and the installer reuse the same login and never ask for a token:
15
+
16
+ ```bash
17
+ gh auth login --hostname github.sydney.edu.au
18
+ uvx synthrad-sct init
19
+ ```
20
+
21
+ The installer asks a few questions:
22
+
23
+ 1. **GitHub token**, only if you skipped `gh auth login`. Make one at
24
+ <https://github.sydney.edu.au/settings/tokens/new?scopes=repo>, or set
25
+ `SYNTHRAD_GITHUB_TOKEN`.
26
+ 2. **Where to clone.** Skipped if you run it inside an existing clone.
27
+ 3. **Which models.** B6 and B2 are pre-selected.
28
+ 4. **CPU or CUDA.** Detected automatically. On macOS it is always CPU.
29
+ 5. **Web previewer.** Optionally installs the Gradio demo, which supports B2 or B3.
30
+
31
+ Then it:
32
+
33
+ - creates `.venv` with Python 3.11, which uv downloads if needed;
34
+ - installs PyTorch 2.5.1 and the pinned NumPy/SimpleITK/SciPy versions the
35
+ weights were trained with;
36
+ - downloads each `epoch_0400.pt` and checks its SHA-256 against the hash
37
+ recorded with the test results;
38
+ - puts each file where the inference code already looks:
39
+ `<experiment>/checkpoints_AB_400epochs/<run>/epoch_0400.pt`;
40
+ - writes `ct_free_inference/configs/inference.local.yaml`;
41
+ - runs `ct_free_inference/smoke_models.py` on the downloaded weights.
42
+
43
+ If a download is interrupted, run the command again. It resumes and skips
44
+ anything already downloaded and checked.
45
+
46
+ | Model | What it is | Test MAE (HU) | Evidence |
47
+ | --- | --- | ---: | --- |
48
+ | B6 | 2.5D U-Net + PatchGAN, 5 slices, GAN weight 0.01 | 108.80 | MRI-only pipeline |
49
+ | B2 | 2.5D U-Net + PatchGAN, 5 slices, 256 crop | 113.03 | historical paired workflow |
50
+ | B0 | 2D U-Net + PatchGAN, centre slice | 114.20 | historical paired workflow |
51
+ | B3 | 2.5D U-Net + PatchGAN, 5 slices, 512 crop | 118.00 | historical paired workflow |
52
+
53
+ See [AB_EXPERIMENTS_README.md](https://github.sydney.edu.au/fyan0582/COMP3888_W11_04_P40/blob/main/AB_EXPERIMENTS_README.md) for what the
54
+ evidence columns mean.
55
+
56
+ ### Other commands
57
+
58
+ ```bash
59
+ synthrad-sct list # models, scores, which are installed
60
+ synthrad-sct doctor # check git/uv/token/GPU/.venv/weights
61
+ synthrad-sct download --models B3 B0 # add weights to an existing setup
62
+ synthrad-sct init -y --models B6 --device cpu --no-previewer # no prompts
63
+ ```
64
+
65
+ Prefix each with `uvx`, or install once with `uv tool install synthrad-sct`.
66
+ Without PyPI, the same CLI runs straight from Git:
67
+ `uvx --from "git+https://github.sydney.edu.au/fyan0582/COMP3888_W11_04_P40.git#subdirectory=installer" synthrad-sct init`.
68
+
69
+ ## For the team: publishing the weights
70
+
71
+ The weights are files on the `weights-v1` release of
72
+ [dmat0262/synthrad-sct-weights](https://github.sydney.edu.au/dmat0262/synthrad-sct-weights),
73
+ kept apart from this course repository so they outlive it. They are never
74
+ committed to Git: GitHub rejects files over 100 MB. You need the [GitHub CLI](https://cli.github.com) logged in
75
+ with `gh auth login --hostname github.sydney.edu.au`.
76
+
77
+ ```bash
78
+ cd installer
79
+ uv run synthrad-sct publish --dry-run B0=/path/B0/epoch_0400.pt B2=/path/B2/epoch_0400.pt \
80
+ B3=/path/B3/epoch_0400.pt B6=/path/B6/epoch_0400.pt
81
+ # then the same command without --dry-run
82
+ ```
83
+
84
+ `publish` first writes the weights repository's `README.md` (a model card)
85
+ and `SHA256SUMS` from the pinned table, then creates the release if needed and
86
+ uploads the files. It refuses any file whose SHA-256 differs from the checkpoint the
87
+ reported results came from. Hashes are pinned in
88
+ `src/synthrad_sct/models.py`, and the tests check them against `results/` and
89
+ `metadata/`. If a model is retrained, update the recorded results and the
90
+ pinned hash together, and publish under a new tag.
91
+
92
+ ## Releasing to PyPI
93
+
94
+ Bump `version` in `pyproject.toml` and `__init__.py`, then:
95
+
96
+ ```bash
97
+ cd installer
98
+ rm -rf dist && uv build
99
+ UV_PUBLISH_TOKEN=pypi-… uv publish
100
+ ```
101
+
102
+ If the package is ever removed from PyPI, switch the commands in this README and
103
+ `weights_repo.INSTALL` back to the Git form first.
104
+
105
+ ## Tests
106
+
107
+ ```bash
108
+ cd installer
109
+ uv run --with numpy --with SimpleITK python -m unittest discover -s tests -v
110
+ ```
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "synthrad-sct"
7
+ version = "0.1.0"
8
+ description = "One-command installer for the COMP3888 P40 abdomen MRI-to-sCT models"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = ["rich>=13", "questionary>=2", "PyYAML>=6"]
12
+ authors = [{ name = "COMP3888 W11-04 P40" }]
13
+ keywords = ["synthrad", "mri", "synthetic-ct", "medical-imaging", "installer"]
14
+ classifiers = [
15
+ "Environment :: Console",
16
+ "Intended Audience :: Science/Research",
17
+ "Operating System :: OS Independent",
18
+ "Programming Language :: Python :: 3",
19
+ "Topic :: Scientific/Engineering :: Medical Science Apps.",
20
+ ]
21
+
22
+ [project.urls]
23
+ Source = "https://github.sydney.edu.au/fyan0582/COMP3888_W11_04_P40/tree/main/installer"
24
+ Weights = "https://github.sydney.edu.au/dmat0262/synthrad-sct-weights"
25
+
26
+ [project.scripts]
27
+ synthrad-sct = "synthrad_sct.cli:main"
28
+
29
+ [tool.hatch.build.targets.wheel]
30
+ packages = ["src/synthrad_sct"]
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,4 @@
1
+ import sys
2
+ from .cli import main
3
+
4
+ sys.exit(main())