Subject

Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

class Subject(subject_id: str, images: ~typing.Mapping[str, ~habit.contracts.image.ImageRef], masks: ~typing.Mapping[str, ~habit.contracts.image.ImageRef], metadata: ~typing.Mapping[str, ~typing.Any] = <factory>)[source]

Bases: object

One imaging subject.

subject_id

Identifier unique within a cohort.

Type:

str

images

Modality name to lazy image handle.

Type:

Mapping[str, habit.contracts.image.ImageRef]

masks

ROI name to lazy mask handle.

Type:

Mapping[str, habit.contracts.image.ImageRef]

metadata

Clinical or acquisition attributes. Never required for computation; consumed by downstream modelling and reporting.

Type:

Mapping[str, Any]

__post_init__() → None[source]

Validate identity and defensively copy the mapping fields.

image(modality: str) → ImageVolume[source]

Materialise one modality.

Parameters:

modality – Key into images.

Returns:

The loaded intensity volume.

Raises:

KeyError – If the modality is absent for this subject.

mask(roi_name: str | None = None) → MaskVolume[source]

Materialise one ROI mask.

Parameters:

roi_name – Key into masks. When None and exactly one mask exists, that mask is returned.

Returns:

The loaded label volume.

Raises:
  • KeyError – If the ROI is absent.

  • ValueError – If roi_name is None and the subject has more than one mask, since silently picking one would be unsafe.

__init__(subject_id: str, images: ~typing.Mapping[str, ~habit.contracts.image.ImageRef], masks: ~typing.Mapping[str, ~habit.contracts.image.ImageRef], metadata: ~typing.Mapping[str, ~typing.Any] = <factory>) → None

Examples using habit.contracts.Subject

Quickstart: Python API

Quickstart: Python API

Quickstart: YAML

Quickstart: YAML