Atlas#

class brainglobe_atlasapi.core.Atlas(path: str | Path, dask: Literal[False] = False, resolution: float | None = None, remote: str = descriptors.DEFAULT_REMOTE)[source]#
class brainglobe_atlasapi.core.Atlas(path: str | Path, dask: Literal[True] = True, resolution: float | None = None, remote: str = descriptors.DEFAULT_REMOTE)
class brainglobe_atlasapi.core.Atlas(path: str | Path, dask: bool = False, resolution: float | None = None, remote: str = descriptors.DEFAULT_REMOTE)

Bases: Generic[AtlasArray]

Base class to handle atlases in BrainGlobe.

Parameters:
  • path (str or Path object) – Path to folder containing data info.

  • resolution (float or None) – Requested resolution, in micrometres: the first axis of a non-isotropic atlas, e.g. 16 for 16 x 16 x 20 um. Defaults to the finest available for manifests offering several.

  • remote (str) – Remote to fetch data from; defaults to the BrainGlobe bucket.

  • dask (bool) – If True, atlas array properties return dask arrays instead of loading them into memory as numpy arrays.

Methods

get_structure_ancestors(structure)

Return a list of acronyms for all ancestors of a given structure.

get_structure_descendants(structure)

Return a list of acronyms for all descendants of a given structure.

get_structure_mask(structure)

Return binary uint8 mask for the given structure.

get_structures_at_hierarchy_level(structure)

Get structures at a specific hierarchy level within the subgraph of nodes connected to the given structure.

hemisphere_from_coords(coords[, microns, ...])

Get the hemisphere from a coordinate triplet.

mesh_from_structure(structure)

Retrieve the mesh associated with a given structure.

meshfile_from_structure(structure)

Retrieve the path to the mesh file associated with a given structure.

root_mesh()

Retrieve the mesh for the root structure.

root_meshfile()

Retrieve the path to the mesh file for the root structure.

structure_from_coords(coords[, microns, ...])

Get the structure from a coordinate triplet.

Attributes

annotation

Return the annotation image data.

hemispheres

Returns a stack with the hemisphere information.

hierarchy

Returns a Treelib.tree object with structures hierarchy.

left_hemisphere_value

lookup_df

Returns a dataframe with id, acronym and name for each structure.

orientation

Origin of the atlas axes, in brainglobe-space letters.

reference

Return the template image data.

resolution

Make resolution more accessible from class.

right_hemisphere_value

shape

Make shape more accessible from class.

shape_um

Make shape more accessible from class.

template

Return the template image data.

property annotation: AtlasArray#

Return the annotation image data. Loads it if not already loaded.

get_structure_ancestors(structure)[source]#

Return a list of acronyms for all ancestors of a given structure.

Parameters:

structure (str or int) – Structure id or acronym

Returns:

List of descendants acronyms

Return type:

list

get_structure_descendants(structure)[source]#

Return a list of acronyms for all descendants of a given structure.

Parameters:

structure (str or int) – Structure id or acronym

Returns:

List of descendants acronyms

Return type:

list

get_structure_mask(structure)[source]#

Return binary uint8 mask for the given structure.

Reads directly from the pre-built 4D annotation masks array.

Parameters:

structure (str or int) – Structure acronym or id.

Returns:

Binary uint8 array; 1 where the structure (or a descendant) has a voxel, 0 elsewhere.

Return type:

np.ndarray

Raises:
  • FileNotFoundError – If this atlas does not have a 4D mask array on disk.

  • KeyError – If the structure is not present in the annotation mapping.

get_structures_at_hierarchy_level(structure, hierarchy_level=None, as_acronym=False)[source]#

Get structures at a specific hierarchy level within the subgraph of nodes connected to the given structure.

For a given brain structure, this method finds all leaf nodes (terminal structures with no children) in its subtree, then extracts the structures at the specified hierarchy level from their paths.

Parameters:
  • structure (str or int) – Structure ID or acronym to query.

  • hierarchy_level (int or None, optional) – The hierarchy level to extract (0-indexed, where 0 is root). If None, returns all structures in the paths to all leaves in anatomical order (breadth-first traversal).

  • as_acronym (bool, optional) – If True, return acronyms instead of IDs. Default is False.

Returns:

List of structure IDs (if as_acronym=False) or acronyms (if as_acronym=True) at the specified hierarchy level.

Return type:

list

Raises:

ValueError – If hierarchy_level is not an integer or None. If the structure has no descendants at the specified level.

Examples

>>> atlas = BrainGlobeAtlas("allen_mouse_25um")
>>> # Get all level-3 structures under cortex
>>> ids = atlas.get_structures_at_hierarchy_level("CTX", 3)
>>> # Get as acronyms instead
>>> acronyms = atlas.get_structures_at_hierarchy_level(
...     "CTX", 3, as_acronym=True
... )
hemisphere_from_coords(coords, microns=False, as_string=False)[source]#

Get the hemisphere from a coordinate triplet.

Parameters:
  • coords (tuple or list or numpy array) – Triplet of coordinates. Default in voxels, can be microns if microns=True

  • microns (bool) – If true, coordinates are interpreted in microns.

  • as_string (bool) – If true, returns “left” or “right”.

Returns:

Hemisphere label.

Return type:

int or string

property hemispheres: AtlasArray#

Returns a stack with the hemisphere information. 1 - left, 2 - right.

If a symmetric reference is used, the hemisphere information is generated by splitting the reference in half along the frontal axis. The first round(n / 2) planes go to the hemisphere the frontal origin letter names (right for r, left for l), the rest to the other. round rounds halves to even, so with an odd n the middle plane goes to the first half for n = 7 but the second for n = 5. Hemispheres are also synthesized this way when the remote bucket holds no hemispheres asset, rather than being downloaded.

Raises:

FileNotFoundError – If the atlas is asymmetric and the bucket holds a hemispheres asset that is missing from the local cache.

property hierarchy#

Returns a Treelib.tree object with structures hierarchy.

property lookup_df#

Returns a dataframe with id, acronym and name for each structure.

mesh_from_structure(structure)[source]#

Retrieve the mesh associated with a given structure.

Parameters:

structure (int or str or list of int/str) – The ID or acronym of the structure for which to retrieve the mesh. If a list of IDs/acronyms is passed, a list of meshes will be returned.

Returns:

The mesh data (e.g., a Mesh object) associated with the structure(s).

Return type:

meshio.Mesh or list of meshio.Mesh

meshfile_from_structure(structure)[source]#

Retrieve the path to the mesh file associated with a given structure.

Parameters:

structure (int or str) – The ID or acronym of the structure for which to retrieve the mesh file path. If a list of IDs/acronyms is passed, a list of paths will be returned.

Returns:

The path(s) to the mesh file(s) for the structure(s).

Return type:

Path or list of Path

property orientation#

Origin of the atlas axes, in brainglobe-space letters.

property reference#

Return the template image data.

Warning: this is a deprecated alias for template, and will be removed in future versions. Use atlas.template instead.

property resolution#

Make resolution more accessible from class.

root_mesh()[source]#

Retrieve the mesh for the root structure.

Returns:

The mesh data for the root structure.

root_meshfile()[source]#

Retrieve the path to the mesh file for the root structure.

Returns:

str: The path to the mesh file for the root structure.

property shape#

Make shape more accessible from class.

property shape_um#

Make shape more accessible from class.

structure_from_coords(coords, microns=False, as_acronym=False, hierarchy_lev=None, key_error_string='Outside atlas')[source]#

Get the structure from a coordinate triplet.

Parameters:
  • coords (tuple or list or numpy array) – Triplet of coordinates.

  • microns (bool) – If true, coordinates are interpreted in microns.

  • as_acronym (bool) – If true, the region acronym is returned. If outside atlas (structure gives key error), return “Outside atlas”

  • hierarchy_lev (int or None) – If specified, return parent node at this hierarchy level.

Returns:

Structure containing the coordinates.

Return type:

int or string

property template: AtlasArray#

Return the template image data. Loads it if not already loaded.