cohort_from_directory

Note

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

cohort_from_directory(root: str | Path, *, modalities: Sequence[str], roi: str, name: str | None = None, images_folder: str = 'images', masks_folder: str = 'masks') → Cohort[source]

Build a cohort from HABIT’s conventional directory layout.

Top-level convenience wrapper kept alongside the class method. Import from habit.contracts (from habit.contracts import cohort_from_directory) or call Cohort.from_directory() for object-style code. This function simply delegates to the class method.

Parameters:
  • root – Directory root holding the images and masks subdirectories.

  • modalities – Modality keys to load, in analysis order.

  • roi – Mask key identifying the region of interest.

  • name – Human-readable cohort name used in reports.

  • images_folder – Name of the images subdirectory under root.

  • masks_folder – Name of the masks subdirectory under root.

Returns:

A cohort with a defined, reproducible subject order.

Examples

Given the conventional layout:

processed_images/
  images/P001/T1/P001_T1.nrrd
  images/P001/T2/P001_T2.nrrd
  masks/P001/T1/P001_mask.nrrd
  images/P002/...

load the cohort with:

>>> from habit.contracts import cohort_from_directory
>>> cohort = cohort_from_directory(  
...     "processed_images",
...     modalities=["T1", "T2"],
...     roi="T1",  # masks/<subject>/T1/
...     name="training",
... )
>>> cohort.subject_ids  
('P001', 'P002', ...)

For file-free exploration, make_synthetic_cohort() builds an equivalent cohort in memory.

Examples using habit.contracts.cohort_from_directory

Quickstart: Python API

Quickstart: Python API

Quickstart: YAML

Quickstart: YAML