Data registry#
The data registry is the shared state container used throughout the package. It keeps loaded images, registrations, and related objects available across multi-step workflows.
- class medicalimageanalysis.data.Data[source]#
Bases:
VolumeData,AnnotationData,MarkupData,RegistrationData,GroupData,GroupStatusDataGlobal orchestrator for medical imaging data and transformations.
This class acts as a centralized, static repository (Singleton pattern) for managing volumetric data, spatial transformations, and clinical annotations. Because data is stored at the class level, all modifications are reflected globally across the application.
Every attribute is a Registry: look entries up by permanent id (int) or user name (str). Iterating and keys() give names, like the plain dictionaries they replace; ids() gives the permanent ids.
- image#
Images; the name is mirrored onto image.image_name.
- Type:
Registry
- rigid#
Rigid registration objects; the name is mirrored onto rigid.rigid_name.
- Type:
Registry
- deformable#
Deformable registration objects; the name is mirrored onto deformable.deformable_name.
- Type:
Registry
- dose#
Dose distribution objects; the name is mirrored onto dose.image_name. Image and dose ids share one counter, so a volume id is unique across both.
- Type:
Registry
- roi_next_id, poi_next_id
Fallback counters for new ROI / POI ids (no provider). ROIs and POIs themselves live only on images (
image.roi/image.poi).- Type:
- moi_next_id, planeoi_next_id, model_next_id, group_next_id
Fallback counters for new markup / plane / model / group ids (no provider). They themselves live only on images (
image.moi/image.planeoi/image.model/image.roi_group, …).- Type:
- GROUP_KINDS#
Kinds of item a group can hold; each image has a container
image.<kind>_groupfor each.
Examples
Access the registry from any module without passing objects around:
>>> import medicalimageanalysis as mia >>> from medicalimageanalysis import Data >>> mia.read_dicoms(folder_path='C:/Data/Patient01') >>> Data.image_list() ['CT 01', 'MR 01']
Grab an image by name or by id (always z-y-x):
>>> ct = Data.image['CT 01'] >>> ct is Data.image[ct.id] True >>> ct.array.shape (142, 512, 512)
The same ROI id on every image:
>>> Data.image['CT 01'].roi['GTV'].id == Data.image['MR 01'].roi['GTV'].id True
- volume_id_provider = None#
- roi_id_provider = None#
- poi_id_provider = None#
- rigid_id_provider = None#
- deformable_id_provider = None#
- moi_id_provider = None#
- planeoi_id_provider = None#
- model_id_provider = None#
- group_id_provider = None#
- GROUP_KINDS = ('roi', 'poi', 'moi', 'planeoi', 'model')#
- roi_next_id = 1#
- poi_next_id = 1#
- moi_next_id = 1#
- planeoi_next_id = 1#
- model_next_id = 1#
- group_next_id = 1#
- image = <medicalimageanalysis.registry.Registry object>#
- rigid = <medicalimageanalysis.registry.Registry object>#
- deformable = <medicalimageanalysis.registry.Registry object>#
- dose = <medicalimageanalysis.registry.Registry object>#
- classmethod clear()[source]#
Wipe all data from the global registry.
Performs a full reset of the class-level storage, clearing the current session’s images (with their groups), registrations, dose objects and ROI/POI/MOI/PlaneOI/Model/group ids. Ids start again at 1. This action is non-reversible and affects every module importing Data.
- Return type:
None
Examples
Reset the session before loading a new patient:
>>> import medicalimageanalysis as mia >>> from medicalimageanalysis import Data >>> mia.read_dicoms(folder_path='C:/Data/Patient01') >>> Data.image_list() ['CT 01', 'MR 01'] >>> Data.clear() >>> Data.image_list() []
Every registry is emptied, not just images:
>>> Data.clear() >>> Data.rigid_list(), Data.deformable_list(), Data.dose_list(), Data.roi_list() ([], [], [], [])
- classmethod delete(name, registry=None)[source]#
Remove an image, dose, rigid or deformable registration from the registry.
Registrations are not removed with their images: Rigid and Deformable keep their frames of reference (and Deformable its meshes), so they keep working when the image is loaded again. Use delete_roi / delete_poi for ROIs and POIs.
- Parameters:
- Return type:
None
- Raises:
KeyError – If name is not in the registry (or in any registry when registry is None).
ValueError – If registry is not a known registry, registry is None and name is in more than one, or name is an id and registry is None.
Examples
Remove a dose, a rigid and a deformable registration:
>>> import medicalimageanalysis as mia >>> from medicalimageanalysis import Data >>> Data.delete('Dose_0') >>> Data.delete('CT 01_MR 01', registry='rigid') >>> Data.delete('DVF_CT 01_CBCT 01')
Remove an image by id while keeping the rest of the session:
>>> Data.delete(Data.image.get_id('MR 01'), registry='image') >>> Data.image_list() ['CT 01']