confusius.atlas¶
atlas ¶
Brain atlas integration via BrainGlobe.
Modules:
-
atlas–Atlas class for brain atlas integration via BrainGlobe.
Classes:
-
Atlas–Brain atlas wrapper backed by BrainGlobe, exposing DataArrays.
Atlas ¶
Brain atlas wrapper backed by BrainGlobe, exposing DataArrays.
Use from_brainglobe to construct an
instance.
Parameters:
-
(dataset¶Dataset) –Dataset with variables
reference,annotation, andhemisphereson a common(z, y, x)grid with physical coordinates in millimetres. -
(structures¶StructuresDict) –BrainGlobe structure dictionary (carries the
treelibhierarchy tree). -
(mesh_to_physical¶(4, 4) numpy.ndarray) –Homogeneous affine that maps mesh vertex coordinates (microns, atlas voxel space) to the DataArrays' physical space (millimetres).
-
(rl_midline_um¶float, default:0.0) –Midpoint of the RL axis in microns (atlas voxel space). Used to clip mesh vertices to a single hemisphere.
Attributes:
-
reference(DataArray) –Reference template DataArray.
-
annotation(DataArray) –Region annotations DataArray with integer labels.
-
hemispheres(DataArray) –Hemisphere map DataArray (1 = left, 2 = right).
-
lookup(DataFrame) –DataFrame with columns
acronym,name,rgb_tripletindexed by structure index. -
cmap(ListedColormap) –ListedColormapderived fromannotation.attrs["rgb_lookup"]. -
norm(BoundaryNorm) –BoundaryNormderived fromannotation.attrs["rgb_lookup"].
Methods:
-
ancestors–Return the ancestor nodes of
region, from root down (exclusive). -
from_brainglobe–Construct an Atlas from a BrainGlobe atlas name or instance.
-
get_masks–Return integer region masks stacked along a
masksdimension. -
get_mesh–Return vertex coordinates and face indices for a region's mesh.
-
resample_like–Resample the atlas onto the grid of
reference. -
search–Search structures by name or acronym.
-
show_tree–Print the structure hierarchy tree.
annotation
property
¶
annotation: DataArray
Region annotations DataArray.
attrs["rgb_lookup"] carries a {id: [r, g, b]} dict used for colormap
construction.
Returns:
-
DataArray–The region annotation DataArray with integer labels.
cmap
property
¶
cmap: ListedColormap
ListedColormap derived from annotation.attrs["rgb_lookup"].
Returns:
-
ListedColormap–The colormap to use for atlas rendering.
hemispheres
property
¶
hemispheres: DataArray
Hemisphere map DataArray (1 = left, 2 = right).
Returns:
-
DataArray–The hemisphere map DataArray.
lookup
property
¶
lookup: DataFrame
DataFrame with columns acronym, name, rgb_triplet.
The DataFrame is indexed by structure index.
Returns:
-
DataFrame–The structure lookup DataFrame, built from the BrainGlobe atlas's
StructuresDict. Cached on first access.
norm
property
¶
norm: BoundaryNorm
BoundaryNorm derived from annotation.attrs["rgb_lookup"].
Returns:
-
BoundaryNorm–The norm to use for atlas rendering.
reference
property
¶
reference: DataArray
Reference template DataArray.
Returns:
-
DataArray–The reference template DataArray.
ancestors ¶
from_brainglobe
classmethod
¶
Construct an Atlas from a BrainGlobe atlas name or instance.
Parameters:
-
(atlas¶str or BrainGlobeAtlas) –Either a BrainGlobe atlas name string (e.g.
"allen_mouse_25um") or an already-loadedBrainGlobeAtlasinstance. -
(**kwargs¶object, default:{}) –Additional keyword arguments forwarded to
BrainGlobeAtlaswhenatlasis a string. Common options includebrainglobe_dir(override the atlas cache directory) andcheck_latest(disable the latest-version check). Ignored whenatlasis already aBrainGlobeAtlasinstance.
Returns:
-
Atlas–Atlas with DataArrays in the atlas physical space (millimetres).
Examples:
get_masks ¶
get_masks(
regions: int | str | Sequence[int | str],
sides: Literal["left", "right", "both"]
| Sequence[Literal["left", "right", "both"]] = "both",
) -> DataArray
Return integer region masks stacked along a masks dimension.
Each layer along mask has values in {0, region_id}; voxels
belonging to the requested region (including all descendants in the
hierarchy) carry the region's index, all others are zero.
Parameters:
-
(regions¶int or str or sequence of int or str) –One or more regions, each given as a structure index or acronym.
-
(sides¶(left, right, both), default:"left") –Hemisphere filter. Pass a scalar to apply the same side to all regions, or a sequence of the same length as
regionsfor per-region control.
Returns:
-
DataArray–Integer DataArray with dims
["mask", "z", "y", "x"]. Themaskcoordinate holds the region acronym for each layer.
Raises:
-
KeyError–If any requested region acronym or index is not found in the atlas.
-
ValueError–If
sidesis a sequence whose length does not matchregions, or if any element ofsidesis not"left","right", or"both".
Examples:
get_mesh ¶
get_mesh(
region: int | str,
side: Literal["left", "right", "both"] = "both",
) -> tuple[NDArray[float64], NDArray[int32]]
Return vertex coordinates and face indices for a region's mesh.
Reads the OBJ file bundled with the BrainGlobe atlas, optionally clips to one hemisphere, then transforms vertices from micron space to the DataArrays' current physical space (millimetres).
Parameters:
-
(region¶int or str) –Structure index or acronym.
-
(side¶(left, right, both), default:"left") –Hemisphere to include.
"both"keeps the full mesh."left"and"right"clip in the original atlas micron space along the RL axis at the volume midline. Only triangles whose three vertices all fall on the requested side are retained; the cut face is not closed.Note
Generalising axis detection from the orientation attribute for non-
asratlases is not yet implemented.
Returns:
-
vertices((ndarray, shape(N, 3))) –Vertex coordinates in the current physical space (millimetres).
-
faces((ndarray, shape(M, 3))) –Zero-indexed triangle face indices (int32).
Raises:
-
KeyError–If the requested region is not found in the atlas.
-
ValueError–If the atlas does not have mesh files.
resample_like ¶
resample_like(
reference: DataArray,
transform: NDArray[float64],
*,
reference_interpolation: Literal[
"linear", "bspline"
] = "linear",
sitk_threads: int = -1,
) -> Atlas
Resample the atlas onto the grid of reference.
Mirrors
confusius.registration.resample_like.
Returns a new Atlas whose DataArrays live on
reference's grid.
reference: resampled withreference_interpolation.annotationandhemispheres: resampled with nearest-neighbour to preserve integer labels.- Meshes returned by
get_meshwill also be in the new physical space.
Parameters:
-
(reference¶DataArray) –Target grid. Must be 2D or 3D and must not have a
timedimension. -
(transform¶(N+1, N+1) numpy.ndarray) –Pull/inverse affine returned by
register_volume, mappingreferencephysical coordinates to atlas physical coordinates. -
(reference_interpolation¶(linear, bspline), default:"linear") –Interpolation used for the
referencevariable. -
(sitk_threads¶int, default:-1) –Number of SimpleITK threads. Negative values use
max(1, cpu_count + 1 + sitk_threads).
Returns:
-
Atlas–New Atlas with DataArrays on
reference's grid.
Examples:
search ¶
Search structures by name or acronym.
Parameters:
-
(pattern¶str) –Substring or regex pattern.
-
(field¶(all, acronym, name), default:"all") –Which column to search.
"all": case-insensitive substring match on bothacronymandname."acronym"/"name": full regex match on that column only.
Returns:
Examples: