Skip to content

Commit 2c9ffa7

Browse files
authored
ENH: AnatomyTaxonomy, USD pipeline hardening, tutorials + docs (#49)
* ENH: AnatomyTaxonomy, USD pipeline hardening, tutorials + docs Replaces the per-organ flat dicts on SegmentAnatomyBase and USDAnatomyTools with a shared AnatomyTaxonomy data type so new segmenters can register custom groups via taxonomy.add_organ without subclassing either class. Adds anatomy-type grouping to ConvertVTKToUSD's labeled output, ships tutorials 07-09 (DirLab PCA + PhysicsNeMo), and fixes several USD- pipeline issues that prevented clean rendering in Omniverse Kit. Anatomy / segmentation - AnatomyTaxonomy + AnatomyGroup (new). SegmentAnatomyBase owns one; subclasses populate via taxonomy.add_organ and call _finalize_other_group. Eight legacy *_mask_ids attributes and set_other_and_all_mask_ids removed; label_to_type delegates to the taxonomy. segment() now returns only the groups the segmenter registered (caller-checks contract; tests updated). - SegmentHeartSimpleware: graceful fallback when ASCardio omits landmarks.csv; only the groups it actually populates are returned. USD generation - ConvertVTKToUSD: new segmenter= parameter groups labeled prims under /World/{basename}/{type}/{label} and materials under /World/Looks/{type}/{label}_material. Preserves cell-data primvars; new compute_von_mises_stress helper for 9-component stress tensors; framing camera with tight near-clip; stale USD-layer eviction; triangulation face-map propagated to uniform primvars so per-cell arrays survive quad-to-triangle splits. - USDAnatomyTools: DEFAULT_RENDER_PARAMS promoted to a module-level constant so CLIs/tests can enumerate types without a stage; per- instance deep copy keeps mutations isolated; enhance_meshes now a single taxonomy loop with organ-level overrides as data instead of imperative carve-outs. MaterialBindingAPI.Apply() so Omniverse RTX consumes the binding (was rendering white). - CLI convert_vtk_to_usd: ANATOMY_TYPES sourced from DEFAULT_RENDER_PARAMS (auto-syncs with future additions); "kidney" alias preserved. Tutorials / experiments - Tutorials 07-09 added (DirLab PCA lung-lobe model, time-series propagation, PhysicsNeMo mesh-stage training). - Tutorials 02-09 gain if __name__ == "__main__" guards (Windows nnUNet spawn) matching tutorial_01; experiments gain the same guards plus Path(__file__)-anchored paths; valve scripts wire compute_von_mises_stress. - notebook_utils.py removed (last consumers gone); experiment scripts and READMEs scrubbed of .ipynb references; test runner already on *.py glob. Tests, docs, packaging - New test_anatomy_taxonomy (12 tests); mask_ids / Simpleware assertions updated to the caller-checks contract; tutorial test harness rewritten. - Segmentation .rst pages, developer/segmentation.rst, and developer/ usd_generation.rst updated to document AnatomyTaxonomy, the type-grouped layout, von Mises helper, framing camera, and the three ways to register a new group's look. - New CLI .rst pages, simpleware/greedy API pages, vtk_to_usd_lib page, data_download / test_tools utility pages; API_MAP.md regenerated. - mypy: 7 errors fixed (Optional render-params indexing, redundant np.asarray casts, pyvista Plotter binding via Any cast, matplotlib colormap return typing). Full src/ tree clean. Other - data_download_tools.py extracted (was notebook_utils.py glue). - pyproject.toml mypy overrides tightened. - Stale baseline PNGs removed (regenerated by test_tools at runtime). * COMP: Bump CI to Python 3.11. 3.10 is no longer supported. * ENH: PR review fixes, save_3d_images split, USD utils, deps save_3d_images: split the single basename argument into (directory, basename); create the directory if needed. Propagated to all 7 callers across src/, tests/, experiments/, data/Slicer-Heart-CT, and the gated-CT workflow. USDTools: move the module-level load_openusd_as_vtk and _openusd_display_color helpers onto USDTools as load_usd_as_vtk and _usd_display_color; update test_tools and test_vtk_to_usd_library callers. Tutorial outputs unified under TUTORIALS_DIR / "output" / ... so tutorials 01/07/08/09 agree with tests/test_tutorials.py. tutorial_01: drop the stray "test_mode = True" override so TestTools.running_as_test() actually drives data_dir selection and registration iteration count. tutorial_08: validate phase_files, forward_transforms, and inverse_transforms have equal length and raise ValueError on mismatch before zipping so dropped frames surface instead of truncating silently. experiments/Heart-GatedCT_To_USD/3: move TestTools.running_as_test() inside the __main__ guard so behavior matches the defensive Windows-spawn comment. vtk_to_usd/usd_utils.add_framing_camera: pick the camera offset axis perpendicular to the stage up axis (+Y for Z-up stages, +Z otherwise) so Z-up stages frame correctly. Bump pyvista[all] floor: >=0.43.0 -> >=0.47.0. Drop legacy Verity{SlicerHeartCT,KCLHeartModel}Data typo shims in data_download_tools; current code only uses Verify* spellings. docs/api/cli/index.rst: fix "an main() function" -> "a main() function". docs/contributing.rst: drop the now-obsolete "If users might copy your code..." paragraph. docs/API_MAP.md regenerated. * ENH: Enable offscreen rendering in github CI runners. * ENH: No offscreen rendering on windows, disable certain tests * ENH: Simplify results and baseline paths for tests * BUG: Camera should point to center of bbox * BUG: Ensure download goes to unique tmp file * DOC: Cleanup doc mentions of notebook * DOC: Remove reference to notebook/ipynb and emojis * DOC: Minor doc fixes
1 parent 533d0da commit 2c9ffa7

138 files changed

Lines changed: 6259 additions & 4593 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.agents/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
settings.local.json
2+
.nicc*

.github/workflows/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Runs on every push and pull request to main branches. Includes:
1010

1111
- **unit-tests**: Cross-platform unit tests
1212
- Runs on Ubuntu and Windows
13-
- Python 3.10, 3.11, and 3.12
13+
- Python 3.11 and 3.12
1414
- Uses PyTorch CPU version to avoid GPU dependencies
1515
- Excludes slow tests and tests requiring external data
1616
- Generates coverage reports
@@ -83,7 +83,7 @@ The workflows use multiple caching layers to speed up builds:
8383

8484
### Important: GPU Tests Are Disabled by Default
8585

86-
⚠️ **GPU tests do NOT run automatically** to prevent jobs from waiting indefinitely in the queue when no runner is available.
86+
**GPU tests do NOT run automatically** to prevent jobs from waiting indefinitely in the queue when no runner is available.
8787

8888
To run GPU tests, you must either:
8989
1. **Manually trigger the workflow**: Go to Actions > CI > Run workflow

.github/workflows/ci.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
fail-fast: false
3131
matrix:
3232
os: [ubuntu-latest, windows-latest]
33-
python-version: ['3.10', '3.11', '3.12']
33+
python-version: ['3.11', '3.12']
3434

3535
steps:
3636
- name: Checkout code
@@ -79,7 +79,9 @@ jobs:
7979
libxrender1 \
8080
libxext6 \
8181
libxrandr2 \
82-
libxi6
82+
libxi6 \
83+
xvfb \
84+
libosmesa6
8385
sudo apt-get clean
8486
sudo rm -rf /var/lib/apt/lists/*
8587
@@ -99,13 +101,20 @@ jobs:
99101
run: |
100102
pip list
101103
102-
- name: Run unit tests (fast, no external data)
104+
- name: Run unit tests (fast, no external data) - Ubuntu
105+
if: matrix.os == 'ubuntu-latest'
106+
run: |
107+
xvfb-run -a --server-args="-screen 0 1024x768x24" \
108+
pytest tests/ -v -m "not slow and not requires_data and not experiment" --cov=physiomotion4d --cov-report=xml --cov-report=term --cov-report=html
109+
110+
- name: Run unit tests (fast, no external data) - Windows
111+
if: matrix.os == 'windows-latest'
103112
run: |
104113
pytest tests/ -v -m "not slow and not requires_data and not experiment" --cov=physiomotion4d --cov-report=xml --cov-report=term --cov-report=html
105114
106115
- name: Upload coverage to Codecov
107116
uses: codecov/codecov-action@v4
108-
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10'
117+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
109118
with:
110119
token: ${{ secrets.CODECOV_TOKEN }}
111120
file: ./coverage.xml
@@ -115,7 +124,7 @@ jobs:
115124

116125
- name: Upload coverage artifacts
117126
uses: actions/upload-artifact@v4
118-
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10'
127+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
119128
with:
120129
name: coverage-report-unit-tests
121130
path: htmlcov/
@@ -148,10 +157,10 @@ jobs:
148157
echo "Disk space after cleanup:"
149158
df -h
150159
151-
- name: Set up Python 3.10
160+
- name: Set up Python 3.11
152161
uses: actions/setup-python@v5
153162
with:
154-
python-version: '3.10'
163+
python-version: '3.11'
155164
cache: 'pip'
156165
cache-dependency-path: pyproject.toml
157166

@@ -185,7 +194,9 @@ jobs:
185194
libxrender1 \
186195
libxext6 \
187196
libxrandr2 \
188-
libxi6
197+
libxi6 \
198+
xvfb \
199+
libosmesa6
189200
sudo apt-get clean
190201
sudo rm -rf /var/lib/apt/lists/*
191202
@@ -218,17 +229,20 @@ jobs:
218229

219230
- name: Run USD conversion tests
220231
run: |
221-
pytest tests/test_convert_vtk_to_usd_polymesh.py -v -m "not slow" --cov=physiomotion4d --cov-append --cov-report=xml
232+
xvfb-run -a --server-args="-screen 0 1024x768x24" \
233+
pytest tests/test_convert_vtk_to_usd_polymesh.py -v -m "not slow" --cov=physiomotion4d --cov-append --cov-report=xml
222234
continue-on-error: true
223235

224236
- name: Run USD utility tests
225237
run: |
226-
pytest tests/test_usd_merge.py tests/test_usd_time_preservation.py -v --cov=physiomotion4d --cov-append --cov-report=xml
238+
xvfb-run -a --server-args="-screen 0 1024x768x24" \
239+
pytest tests/test_usd_merge.py tests/test_usd_time_preservation.py -v --cov=physiomotion4d --cov-append --cov-report=xml
227240
continue-on-error: true
228241

229242
- name: Run all integration tests
230243
run: |
231-
pytest tests/ -v -m "not slow and not experiment and not requires_gpu"
244+
xvfb-run -a --server-args="-screen 0 1024x768x24" \
245+
pytest tests/ -v -m "not slow and not experiment and not requires_gpu"
232246
continue-on-error: true
233247

234248
- name: Upload coverage to Codecov
@@ -345,10 +359,10 @@ jobs:
345359
with:
346360
lfs: true
347361

348-
- name: Set up Python 3.10
362+
- name: Set up Python 3.11
349363
uses: actions/setup-python@v5
350364
with:
351-
python-version: "3.10"
365+
python-version: "3.11"
352366
cache: 'pip'
353367

354368
- name: Install dev dependencies

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Set up Python
3333
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
3434
with:
35-
python-version: '3.10'
35+
python-version: '3.11'
3636

3737
- name: Install build tools
3838
run: |

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ py -m pytest tests/ --ignore=tests/test_segment_chest_total_segmentator.py \
3636
# With coverage
3737
py -m pytest tests/ --cov=src/physiomotion4d --cov-report=html
3838

39-
# Experiment notebook tests (very slow, opt-in)
39+
# Experiment script tests (very slow, opt-in)
4040
py -m pytest tests/ --run-experiments
4141

4242
# Create missing baselines

0 commit comments

Comments
 (0)