Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

atlases

atlases

Atlas registry, lazy loading, and coordinate labeling.

Atlases are hosted at huggingface.co/datasets/nltools/niftis under atlases/ and fetched on first use via fetch_resource. Cached locally afterwards.

The labeling logic was adapted from atlasreader (BSD-3-Clause). Cite:

Notter et al. (2019). AtlasReader. JOSS 4(34), 1257. Notter et al. (2019)

Attributes:

NameTypeDescription
ATLASESdict [ str , AtlasMetadata ]
AtlasKind
DEFAULT_ATLASEStuple [ str , ...]

Classes:

NameDescription
AtlasA loaded atlas — image, labels, and metadata.
AtlasMetadataStatic description of a registered atlas.
ClusterReportResult of BrainData.cluster_report.

Methods:

NameDescription
cluster_report_dataCompute cluster report DataFrames + thresholded BrainData.
label_coordsLook up anatomical labels for a set of MNI mm coordinates.
list_atlasesReturn the sorted list of registered atlas names.
load_atlasLazy-load an atlas by registry name.

Modules:

NameDescription
labelingCoordinate-level atlas labeling.
loadingLazy loading of atlas NIfTI + label CSV files from the HF dataset.
registryStatic registry of atlases hosted at nltools/niftis/atlases.
reportingCluster reports — peak/cluster geometry plus atlas labels.

Classes

Atlas

Atlas(name: str, image: nb.Nifti1Image, labels: pl.DataFrame, kind: AtlasKind, citation: str) -> None

A loaded atlas — image, labels, and metadata.

Constructed by load_atlas; users normally don’t instantiate directly.

Attributes:

NameTypeDescription
namestrRegistry key (e.g. "harvard_oxford").
imageNifti1ImageNIfTI volume. 3D for deterministic atlases, 4D for probabilistic ones (last axis indexes regions).
labelsDataFrameTwo-column index, name table. For deterministic atlases index is the integer voxel value; for probabilistic atlases index is the region index along the 4th dim of image.
kindAtlasKind"deterministic" or "probabilistic".
citationstrShort citation for the original atlas.

AtlasMetadata

AtlasMetadata(kind: AtlasKind, citation: str) -> None

Static description of a registered atlas.

Attributes:

NameTypeDescription
kindAtlasKind"deterministic" (3D integer-labeled) or "probabilistic" (4D, last axis indexes regions).
citationstrShort citation string for the original atlas.

ClusterReport

ClusterReport(peaks: pl.DataFrame, clusters: pl.DataFrame, stat_img: BrainData) -> None

Result of BrainData.cluster_report.

Attributes:

NameTypeDescription
peaksDataFramePolars DataFrame, one row per peak (incl. sub-peaks). Columns cluster_id, x, y, z (mm), peak_stat, volume_mm3, n_voxels, then one Utf8 column per atlas. cluster_id shares the integer id space of clusters (they are joinable); sub-peaks carry their parent cluster’s id.
clustersDataFramePolars DataFrame, one row per cluster. Columns cluster_id, peak_x, peak_y, peak_z, mean_stat, volume_mm3, n_voxels, then one Utf8 column per atlas (mass-weighted top regions).
stat_imgBrainDataBrainData with the thresholded stat map (sub-cluster voxels and clusters smaller than cluster_threshold zeroed).

Methods:

NameDescription
plotRender an overview glass brain + one slice figure per cluster.
to_csvWrite peaks.csv and clusters.csv into output_dir.

Methods

plot
plot(*, output_dir: str | Path | None = None) -> list[tuple[str, Figure]] | None

Render an overview glass brain + one slice figure per cluster.

Parameters:

NameTypeDescriptionDefault
output_dirstr | Path | NoneIf given, save overview.png and cluster_NN.png files into the directory and return None. If omitted, return a list of (label, matplotlib.figure.Figure) tuples without writing to disk.None

Returns:

TypeDescription
list [ tuple [ str , Figure ]] | NoneNone when output_dir is set, else a list of
list [ tuple [ str , Figure ]] | None(label, figure) tuples.
to_csv
to_csv(output_dir: str | Path) -> None

Write peaks.csv and clusters.csv into output_dir.

Methods

cluster_report_data

cluster_report_data(bd: BrainData, *, stat_threshold: float | None = 3.0, cluster_threshold: int = 10, two_sided: bool = True, min_distance: float = 8.0, atlas: str | Sequence[str] = DEFAULT_ATLASES, prob_threshold: float = 5.0) -> tuple[pl.DataFrame, pl.DataFrame, BrainData]

Compute cluster report DataFrames + thresholded BrainData.

Pure function — the BrainData facade BrainData.cluster_report wraps the result in a ClusterReport.

Parameters:

NameTypeDescriptionDefault
bdBrainDataBrainData with a 3D stat map (single sample).required
stat_thresholdfloat | NoneVoxel-level threshold. None means treat bd as already thresholded (skip voxel filtering, keep all non-zero voxels).3.0
cluster_thresholdintMinimum cluster size in voxels.10
two_sidedboolReport negative clusters as separate clusters.True
min_distancefloatMinimum distance (mm) between sub-peaks. Passed to get_clusters_table.8.0
atlasstr | Sequence [ str ]Atlas name or list of names from list_atlases.DEFAULT_ATLASES
prob_thresholdfloatDrop probabilistic-atlas regions below this %.5.0

Returns:

TypeDescription
tuple [ DataFrame , DataFrame , BrainData ]Tuple (peaks, clusters, thresholded_bd).

label_coords

label_coords(coords: CoordsLike, *, atlas: str | Sequence[str] = 'harvard_oxford', prob_threshold: float = 5.0) -> pl.DataFrame

Look up anatomical labels for a set of MNI mm coordinates.

For each coordinate, returns the atlas region(s) it falls in. Works for both deterministic atlases (single label per coord) and probabilistic atlases (formatted "42.0% Foo; 18.0% Bar" strings, sorted by descending probability).

Parameters:

NameTypeDescriptionDefault
coordsCoordsLike(N, 3) array-like of MNI mm coordinates (x, y, z). A single coord like (-42, -22, 56) is also accepted.required
atlasstr | Sequence [ str ]Atlas name or list of names from list_atlases. One column is added to the output per atlas.‘harvard_oxford’
prob_thresholdfloatFor probabilistic atlases only — drop regions with probability (in percent units) below this threshold.5.0

Returns:

TypeDescription
DataFramePolars DataFrame with columns x, y, z plus one
DataFramecolumn per atlas. All atlas columns are Utf8.

list_atlases

list_atlases() -> list[str]

Return the sorted list of registered atlas names.

Returns:

TypeDescription
list [ str ]Sorted list of atlas names usable with
list [ str ]load_atlas.

load_atlas

load_atlas(name: str) -> Atlas

Lazy-load an atlas by registry name.

First call fetches the NIfTI + label CSV from huggingface.co/datasets/nltools/niftis (cached locally afterwards). Subsequent calls in the same process are memoized.

Parameters:

NameTypeDescriptionDefault
namestrAtlas key from list_atlases.required

Returns:

TypeDescription
AtlasAn Atlas with image, labels, and metadata loaded.

Modules

labeling

Coordinate-level atlas labeling.

Adapted from atlasreader (BSD-3-Clause). Cite:

Notter et al. (2019). AtlasReader. JOSS 4(34), 1257.

Attributes:

NameTypeDescription
CoordsLike

Methods:

NameDescription
label_coordsLook up anatomical labels for a set of MNI mm coordinates.

Classes

Methods

label_coords
label_coords(coords: CoordsLike, *, atlas: str | Sequence[str] = 'harvard_oxford', prob_threshold: float = 5.0) -> pl.DataFrame

Look up anatomical labels for a set of MNI mm coordinates.

For each coordinate, returns the atlas region(s) it falls in. Works for both deterministic atlases (single label per coord) and probabilistic atlases (formatted "42.0% Foo; 18.0% Bar" strings, sorted by descending probability).

Parameters:

NameTypeDescriptionDefault
coordsCoordsLike(N, 3) array-like of MNI mm coordinates (x, y, z). A single coord like (-42, -22, 56) is also accepted.required
atlasstr | Sequence [ str ]Atlas name or list of names from list_atlases. One column is added to the output per atlas.‘harvard_oxford’
prob_thresholdfloatFor probabilistic atlases only — drop regions with probability (in percent units) below this threshold.5.0

Returns:

TypeDescription
DataFramePolars DataFrame with columns x, y, z plus one
DataFramecolumn per atlas. All atlas columns are Utf8.

loading

Lazy loading of atlas NIfTI + label CSV files from the HF dataset.

Classes:

NameDescription
AtlasA loaded atlas — image, labels, and metadata.

Methods:

NameDescription
load_atlasLazy-load an atlas by registry name.

Classes

Atlas
Atlas(name: str, image: nb.Nifti1Image, labels: pl.DataFrame, kind: AtlasKind, citation: str) -> None

A loaded atlas — image, labels, and metadata.

Constructed by load_atlas; users normally don’t instantiate directly.

Attributes:

NameTypeDescription
namestrRegistry key (e.g. "harvard_oxford").
imageNifti1ImageNIfTI volume. 3D for deterministic atlases, 4D for probabilistic ones (last axis indexes regions).
labelsDataFrameTwo-column index, name table. For deterministic atlases index is the integer voxel value; for probabilistic atlases index is the region index along the 4th dim of image.
kindAtlasKind"deterministic" or "probabilistic".
citationstrShort citation for the original atlas.

####### Attributes##

citation
citation: str

######## image

image: nb.Nifti1Image

######## kind

kind: AtlasKind

######## labels

labels: pl.DataFrame

######## name

name: str

Methods

load_atlas
load_atlas(name: str) -> Atlas

Lazy-load an atlas by registry name.

First call fetches the NIfTI + label CSV from huggingface.co/datasets/nltools/niftis (cached locally afterwards). Subsequent calls in the same process are memoized.

Parameters:

NameTypeDescriptionDefault
namestrAtlas key from list_atlases.required

Returns:

TypeDescription
AtlasAn Atlas with image, labels, and metadata loaded.

registry

Static registry of atlases hosted at nltools/niftis/atlases.

Each entry describes an atlas’s kind (deterministic vs probabilistic) and the citation users should cite when they use it. The actual NIfTI + label files are fetched lazily by load_atlas via fetch_resource.

Atlases were sourced from atlasreader (BSD-3-Clause) and are subject to their original upstream licenses — see LICENSES.md in the HF dataset.

Attributes:

NameTypeDescription
ATLASESdict [ str , AtlasMetadata ]
AtlasKind
DEFAULT_ATLASEStuple [ str , ...]

Classes:

NameDescription
AtlasMetadataStatic description of a registered atlas.

Methods:

NameDescription
list_atlasesReturn the sorted list of registered atlas names.

Classes

AtlasMetadata
AtlasMetadata(kind: AtlasKind, citation: str) -> None

Static description of a registered atlas.

Attributes:

NameTypeDescription
kindAtlasKind"deterministic" (3D integer-labeled) or "probabilistic" (4D, last axis indexes regions).
citationstrShort citation string for the original atlas.

####### Attributes##

citation
citation: str

######## kind

kind: AtlasKind

Methods

list_atlases
list_atlases() -> list[str]

Return the sorted list of registered atlas names.

Returns:

TypeDescription
list [ str ]Sorted list of atlas names usable with
list [ str ]load_atlas.

reporting

Cluster reports — peak/cluster geometry plus atlas labels.

The peak/sub-peak geometry comes from get_clusters_table; the cluster masks and mass-weighted labels are computed locally so we can attribute every voxel of every cluster to one or more atlases.

Classes:

NameDescription
ClusterReportResult of BrainData.cluster_report.

Methods:

NameDescription
cluster_report_dataCompute cluster report DataFrames + thresholded BrainData.

Classes

ClusterReport
ClusterReport(peaks: pl.DataFrame, clusters: pl.DataFrame, stat_img: BrainData) -> None

Result of BrainData.cluster_report.

Attributes:

NameTypeDescription
peaksDataFramePolars DataFrame, one row per peak (incl. sub-peaks). Columns cluster_id, x, y, z (mm), peak_stat, volume_mm3, n_voxels, then one Utf8 column per atlas. cluster_id shares the integer id space of clusters (they are joinable); sub-peaks carry their parent cluster’s id.
clustersDataFramePolars DataFrame, one row per cluster. Columns cluster_id, peak_x, peak_y, peak_z, mean_stat, volume_mm3, n_voxels, then one Utf8 column per atlas (mass-weighted top regions).
stat_imgBrainDataBrainData with the thresholded stat map (sub-cluster voxels and clusters smaller than cluster_threshold zeroed).

Methods:

NameDescription
plotRender an overview glass brain + one slice figure per cluster.
to_csvWrite peaks.csv and clusters.csv into output_dir.

####### Attributes##

clusters
clusters: pl.DataFrame

######## peaks

peaks: pl.DataFrame

######## stat_img

stat_img: BrainData

####### Functions##

plot
plot(*, output_dir: str | Path | None = None) -> list[tuple[str, Figure]] | None

Render an overview glass brain + one slice figure per cluster.

Parameters:

NameTypeDescriptionDefault
output_dirstr | Path | NoneIf given, save overview.png and cluster_NN.png files into the directory and return None. If omitted, return a list of (label, matplotlib.figure.Figure) tuples without writing to disk.None

Returns:

TypeDescription
list [ tuple [ str , Figure ]] | NoneNone when output_dir is set, else a list of
list [ tuple [ str , Figure ]] | None(label, figure) tuples.

######## to_csv

to_csv(output_dir: str | Path) -> None

Write peaks.csv and clusters.csv into output_dir.

Methods

cluster_report_data
cluster_report_data(bd: BrainData, *, stat_threshold: float | None = 3.0, cluster_threshold: int = 10, two_sided: bool = True, min_distance: float = 8.0, atlas: str | Sequence[str] = DEFAULT_ATLASES, prob_threshold: float = 5.0) -> tuple[pl.DataFrame, pl.DataFrame, BrainData]

Compute cluster report DataFrames + thresholded BrainData.

Pure function — the BrainData facade BrainData.cluster_report wraps the result in a ClusterReport.

Parameters:

NameTypeDescriptionDefault
bdBrainDataBrainData with a 3D stat map (single sample).required
stat_thresholdfloat | NoneVoxel-level threshold. None means treat bd as already thresholded (skip voxel filtering, keep all non-zero voxels).3.0
cluster_thresholdintMinimum cluster size in voxels.10
two_sidedboolReport negative clusters as separate clusters.True
min_distancefloatMinimum distance (mm) between sub-peaks. Passed to get_clusters_table.8.0
atlasstr | Sequence [ str ]Atlas name or list of names from list_atlases.DEFAULT_ATLASES
prob_thresholdfloatDrop probabilistic-atlas regions below this %.5.0

Returns:

TypeDescription
tuple [ DataFrame , DataFrame , BrainData ]Tuple (peaks, clusters, thresholded_bd).
References
  1. Notter, M., Gale, D., Herholz, P., Markello, R., Notter-Bielser, M.-L., & Whitaker, K. (2019). AtlasReader: A Python package to generate coordinate tables, region labels, and informative figures from statistical MRI images. Journal of Open Source Software, 4(34), 1257. 10.21105/joss.01257