atlas
tit.atlas ¶
Shared atlas module for TI-Toolbox.
Provides mesh (surface) and voxel (volumetric) atlas discovery, region listing, and overlap analysis.
MeshAtlasManager ¶
MeshAtlasManager(seg_dir: str)
Discovers and queries FreeSurfer .annot mesh atlases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seg_dir
|
str
|
Path to m2m_{subject}/segmentation/ directory. |
required |
Source code in tit/atlas/mesh.py
list_atlases ¶
List available mesh atlas names.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of atlas names (always includes builtins). |
Source code in tit/atlas/mesh.py
list_regions ¶
List regions for a mesh atlas from .annot files.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of region names in SimNIBS format (e.g. "lh.precentral"). |
Source code in tit/atlas/mesh.py
find_atlas_file ¶
Find the .annot file path for a given atlas and hemisphere.
Returns:
| Type | Description |
|---|---|
str | None
|
Path to the .annot file, or None if not found. |
Source code in tit/atlas/mesh.py
find_all_atlases ¶
Find all available atlas files for a hemisphere.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict mapping atlas display name to file path. |
Source code in tit/atlas/mesh.py
list_annot_regions ¶
List all regions in a .annot file.
Returns:
| Type | Description |
|---|---|
list[tuple[int, str]]
|
List of (region_index, region_name) tuples. |
Source code in tit/atlas/mesh.py
VoxelAtlasManager ¶
VoxelAtlasManager(freesurfer_mri_dir: str = '', seg_dir: str = '', masks_dir: str = '', fastsurfer_mri_dir: str = '')
Discovers and queries volumetric atlas files.
All discovery methods use the same canonical atlas-name lists from
:mod:tit.atlas.constants so that the analyzer, flex-search and NIfTI
viewer show identical atlases.
Search order for a name present in both trees: fastsurfer_mri_dir
first, then freesurfer_mri_dir. The two never collide in practice --
FastSurfer writes aparc.DKTatlas+aseg.deep.* and recon-all writes
aparc.DKTatlas+aseg.mgz -- but the order is fixed so a project that
holds both offers the current pipeline's output first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freesurfer_mri_dir
|
str
|
Path to a FreeSurfer |
''
|
fastsurfer_mri_dir
|
str
|
Path to the FastSurfer |
''
|
seg_dir
|
str
|
Path to m2m_{subject}/segmentation/ directory. |
''
|
masks_dir
|
str
|
Path to m2m_{subject}/masks/, holding user-supplied custom label volumes. Optional; most subjects have no such directory. |
''
|
Source code in tit/atlas/voxel.py
list_atlases ¶
Discover available voxel atlas files for a subject.
Checks FastSurfer mri/ first, then a legacy FreeSurfer mri/,
then segmentation/ for charm's own labeling.nii.gz, then
masks/ for any user-supplied label volume. Used by the analyzer
tab, the flex subcortical tab and the NIfTI viewer.
Returns:
| Type | Description |
|---|---|
list[tuple[str, str]]
|
List of (display_name, full_path) tuples, first match per name. |
Source code in tit/atlas/voxel.py
list_custom_masks ¶
Discover user-supplied label volumes in the subject's masks/ dir.
Any *.nii.gz/*.nii/*.mgz file dropped into
m2m_{subject}/masks/ is offered for targeting. Display names are
prefixed with masks/ so custom entries are distinguishable from
the curated atlases. A missing directory yields no entries.
Returns:
| Type | Description |
|---|---|
list[tuple[str, str]]
|
Sorted list of (display_name, full_path) tuples. |
Source code in tit/atlas/voxel.py
list_regions ¶
List regions in a voxel atlas.
Pure-Python replacement for shelling out to FreeSurfer's
mri_segstats: labels present in the volume come from
:func:~tit.atlas.segstats.compute_segstats (nibabel + numpy),
named via :func:~tit.atlas.segstats.resolve_lut_for_atlas (a
sidecar colour table next to the atlas, else the bundled standard
FreeSurfer colour table). Validated voxel-for-voxel against live
mri_segstats output on real recon-all data -- see
docs/dev/DECISIONS.md ยง 2026-09-03 (One Docker image and a real development loop).
Caches the label file next to the atlas, in mri_segstats
--sum's own text layout (other modules parse this exact sidecar
filename), so subsequent calls skip recomputation.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of "RegionName (ID: N)" strings. |
Source code in tit/atlas/voxel.py
detect_mni_atlases
staticmethod
¶
Detect available MNI atlases in an assets directory.
The list, its order and every atlas's kind/licence come from
resources/atlas/manifest.json (:mod:tit.atlas.manifest); a
manifest entry whose file is absent is skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atlas_dir
|
str
|
Path to the atlas resources directory. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of full paths to found MNI atlas files. |
Source code in tit/atlas/voxel.py
atlas_overlap_analysis ¶
atlas_overlap_analysis(sig_mask, atlas_files: list[str], data_dir: str, reference_img=None) -> dict[str, list]
Analyze overlap between significant voxels and atlas regions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sig_mask
|
Binary ndarray (x, y, z) of significant voxels. |
required | |
atlas_files
|
list[str]
|
List of atlas file names. |
required |
data_dir
|
str
|
Directory containing atlas files. |
required |
reference_img
|
nibabel image for resampling (optional). |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, list]
|
Dict mapping atlas names to lists of region overlap dicts. |
Source code in tit/atlas/overlap.py
check_and_resample_atlas ¶
check_and_resample_atlas(atlas_img, reference_img, atlas_name: str)
Check if atlas dimensions match reference, resample if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atlas_img
|
nibabel image of the atlas. |
required | |
reference_img
|
nibabel image of the reference (subject data). |
required | |
atlas_name
|
str
|
Name of atlas for logging. |
required |
Returns:
| Type | Description |
|---|---|
|
Atlas data as integer ndarray in correct dimensions. |