Core Developer Guide

This page summarizes the core conventions for extending MONAI Physio.

Data Conventions

These conventions are fixed and hold everywhere in MONAI Physio; this section is their single source of truth. Docstrings, comments and test docstrings do not restate them, and document only genuine deviations, such as a raw NumPy array whose axes are reversed relative to the ITK image it came from.

  • Images are itk.Image objects with axes X, Y, Z [, T] in LPS world space, ITK’s native frame: itk.imread normalizes DICOM, NIfTI, MHA and NRRD inputs to LPS. A 4D time series has axes (X, Y, Z, T). Axes are never silently squeezed or permuted. Images are written with itk.imwrite(image, path, compression=True).

  • Surfaces are pv.PolyData in LPS, inherited from the source image via itk.vtk_image_from_image.

  • USD is right-handed and Y-up. Surfaces are converted to it only at USD export, by vtk_to_usd.lps_points_to_usd: USD +X is Left, +Y is Superior and +Z is Anterior.

  • Labelmaps are ITK images of integer labels. The segmenter that made a labelmap defines its ids through its taxonomy, which also names the anatomy groups (heart, lung, …) shared across segmenters.

  • Masks are binary ITK images.

  • Transforms are ITK transforms, stored in compressed .hdf files. See Transform Direction Conventions for which direction each one maps.

Base Class

Runtime classes inherit from monai_physio.MONAIPhysioBase and use the shared logging methods.

import logging

from monai_physio import MONAIPhysioBase

class MyWorkflow(MONAIPhysioBase):
    def __init__(self, input_file: str) -> None:
        super().__init__(class_name="MyWorkflow", log_level=logging.INFO)
        self.input_file = input_file

    def process(self) -> str:
        self.log_info("Processing %s", self.input_file)
        return self.input_file

Use log_info(), log_debug(), and log_warning() inside runtime classes. Standalone scripts may use print() for command-line status.

Class Boundaries

  • Workflows orchestrate complete pipelines.

  • Registration classes estimate transforms.

  • Segmentation classes return ITK images or dictionaries of ITK masks.

  • ProcessTransforms applies transforms to images and PyVista contours.

  • ProcessSurfaceMesh creates and transforms VTK/PyVista surface data; ProcessVolumetricMesh builds tetrahedral meshes (voxel-based, or through netgen or Simpleware Medical) and relaxes and repairs them; both run their GPU work through ProcessMeshKernels.

  • ProcessUSD and ProcessUSDAnatomy operate on USD stages and files.

Public APIs should be documented in docs/api.

Validation

For most code changes, run:

py -m pytest tests/ -v

(Slow / GPU / Simpleware / PhysicsNeMo / tutorial tests are auto-skipped; opt in with --run-slow, --run-gpu, --run-simpleware, --run-physicsnemo, --run-tutorials, or use --run-all to enable every bucket at once. Data-dependent tests download their data through the session fixtures and run by default.)

After public API changes, refresh the graphify knowledge graph so AI assistants keep resolving symbols correctly (see AI Assistants):

graphify update .

See Also