siibra.core.region

Representation of a brain region.

Attributes

REGEX_TYPE

THRESHOLD_STATISTICAL_MAPS

Classes

Region

Representation of a region with name and more optional attributes

RegionRelationAssessments

Abstract base class for generic types.

SpatialProp

SpatialPropCmpt

Module Contents

class siibra.core.region.Region(name: str, children: List[Region] = [], parent: Region = None, shortname: str = '', description: str = '', modality: str = '', publications: list = [], datasets: list = [], rgb: str = None, spec=None, prerelease: bool = False)
Inheritance diagram of siibra.core.region.Region

Representation of a region with name and more optional attributes

compute_centroids(space: siibra.core.space.Space) siibra.locations.pointset.PointSet

Compute the centroids of the region in the given space.

Parameters:

space (Space) – reference space in which the computation will be performed

Returns:

Found centroids (as Point objects) in a PointSet

Return type:

PointSet

Note

A region can generally have multiple centroids if it has multiple connected components in the map.

static copy(other: Region)

copy constructor must detach the parent to avoid problems with the Anytree implementation.

fetch_regional_map(space: str | siibra.core.space.Space, maptype: siibra.commons.MapType = SIIBRA_DEFAULT_MAPTYPE, threshold: float = SIIBRA_DEFAULT_MAP_THRESHOLD, via_space: str | siibra.core.space.Space = None)

Attempts to build a binary mask of this region in the given space, using the specified MapTypes.

Parameters:
  • space (Space or str) – The requested reference space

  • maptype (MapType, default: SIIBRA_DEFAULT_MAPTYPE) – The type of map to be used (‘labelled’ or ‘statistical’)

  • threshold (float, optional) – When fetching a statistical map, use this threshold to convert it to a binary mask

  • via_space (Space or str) –

    If specified, fetch the map in this space first, and then perform a linear warping from there to the requested space.

    Tip

    You might want to use this if a map in the requested space is not available.

    Note

    This linear warping is an affine approximation of the nonlinear deformation, computed from the warped corner points of the bounding box (see siibra.locations.BoundingBox.estimate_affine()). It does not require voxel resampling, just replaces the affine matrix, but is less accurate than a full nonlinear warping, which is currently not supported in siibra-python for images.

Return type:

Nifti1Image

find(regionspec, filter_children=False, find_topmost=True) List[Region]

Find regions that match the given region specification in the subtree headed by this region.

Parameters:
  • regionspec (str, regex, int, Region) –

    • a string with a possibly inexact name (matched both against the name and the identifier key)

    • a string in ‘/pattern/flags’ format to use regex search (acceptable flags: aiLmsux)

    • a regex applied to region names

    • a Region object

  • filter_children (bool, default: False) – If True, children of matched parents will not be returned

  • find_topmost (bool, default: True) – If True (requires filter_children=True), will return parent structures if all children are matched, even though the parent itself might not match the specification.

Returns:

list of regions matching to the regionspec

Return type:

list[Region]

Tip

See example 01-003, find regions.

get_bounding_box(space: siibra.core.space.Space, maptype: siibra.commons.MapType = MapType.LABELLED, threshold_statistical=None)

Compute the bounding box of this region in the given space.

Parameters:
  • space (Space or str) – Requested reference space

  • maptype (MapType, default: MapType.LABELLED) – Type of map to build (‘labelled’ will result in a binary mask, ‘statistical’ attempts to build a statistical mask, possibly by elementwise maximum of statistical maps of children)

  • threshold_statistical (float, or None) – if not None, masks will be preferably constructed by thresholding statistical maps with the given value.

Return type:

BoundingBox

Get assements on relations of this region to others defined on EBRAINS.

Yields:

RegionRelationAssessments

Example

>>> region = siibra.get_region("monkey", "PG")^M
>>> for assesment in region.get_related_regions():
>>>    print(assesment)
'PG' is homologous to 'Area PGa (IPL)'
'PG' is homologous to 'Area PGa (IPL) left'
'PG' is homologous to 'Area PGa (IPL) right'
'PG' is homologous to 'Area PGa (IPL)'
'PG' is homologous to 'Area PGa (IPL) left'
'PG' is homologous to 'Area PGa (IPL) right'
'PG' is homologous to 'Area PGa (IPL)'
'PG' is homologous to 'Area PGa (IPL) right'
'PG' is homologous to 'Area PGa (IPL) left'
has_parent(parent)
includes(region)

Determine whether this region-tree includes the given region.

Parameters:

region (Region) –

Returns:

True if the region is in the region-tree.

Return type:

bool

mapped_in_space(space, recurse: bool = True) bool

Verifies wether this region is defined by an explicit map in the given space.

Parameters:
  • space (Space or str) – reference space

  • recurse (bool, default: True) – If True, check if all child regions are mapped instead

Return type:

bool

matches(regionspec)

Checks whether this region matches the given region specification.

Parameters:

regionspec (str, regex, Region) –

  • a string with a possibly inexact name, which is matched both against the name and the identifier key,

  • a regex applied to region names,

  • a region object

Returns:

If the regionspec matches to the Region.

Return type:

bool

render_tree()

Prints the tree representation of the region

spatial_props(space: siibra.core.space.Space, maptype: siibra.commons.MapType = MapType.LABELLED, threshold_statistical=None) SpatialProp

Compute spatial properties for connected components of this region in the given space.

Parameters:
  • space (Space) – reference space in which the computation will be performed

  • maptype (MapType, default: MapType.LABELLED) – Type of map to build (‘labelled’ will result in a binary mask, ‘statistical’ attempts to build a statistical mask, possibly by elementwise maximum of statistical maps of children)

  • threshold_statistical (float, or None) – if not None, masks will be preferably constructed by thresholding statistical maps with the given value.

Returns:

Dictionary of region’s spatial properties

Return type:

Dict

supports_space(space: siibra.core.space.Space)

Return true if this region supports the given space, else False.

tree2str()

Render region-tree as a string

children = []

All child nodes.

>>> from anytree import Node
>>> n = Node("n")
>>> a = Node("a", parent=n)
>>> b = Node("b", parent=n)
>>> c = Node("c", parent=n)
>>> n.children
(Node('/n/a'), Node('/n/b'), Node('/n/c'))

Modifying the children attribute modifies the tree.

Detach

The children attribute can be updated by setting to an iterable.

>>> n.children = [a, b]
>>> n.children
(Node('/n/a'), Node('/n/b'))

Node c is removed from the tree. In case of an existing reference, the node c does not vanish and is the root of its own tree.

>>> c
Node('/c')

Attach

>>> d = Node("d")
>>> d
Node('/d')
>>> n.children = [a, b, d]
>>> n.children
(Node('/n/a'), Node('/n/b'), Node('/n/d'))
>>> d
Node('/n/d')

Duplicate

A node can just be the children once. Duplicates cause a TreeError:

>>> n.children = [a, b, d, a]
Traceback (most recent call last):
    ...
anytree.node.exceptions.TreeError: Cannot add node Node('/n/a') multiple times as child.
property id
property names
property parcellation
parent = None

Parent Node.

On set, the node is detached from any previous parent node and attached to the new node.

>>> from anytree import Node, RenderTree
>>> udo = Node("Udo")
>>> marc = Node("Marc")
>>> lian = Node("Lian", parent=marc)
>>> print(RenderTree(udo))
Node('/Udo')
>>> print(RenderTree(marc))
Node('/Marc')
└── Node('/Marc/Lian')

Attach

>>> marc.parent = udo
>>> print(RenderTree(udo))
Node('/Udo')
└── Node('/Udo/Marc')
    └── Node('/Udo/Marc/Lian')

Detach

To make a node to a root node, just set this attribute to None.

>>> marc.is_root
False
>>> marc.parent = None
>>> marc.is_root
True
rgb = None
property spaces
property species
property supported_spaces: Set[siibra.core.space.Space]

The set of spaces for which a mask could be extracted. Overwrites the corresponding method of AtlasConcept.

class siibra.core.region.RegionRelationAssessments
Inheritance diagram of siibra.core.region.RegionRelationAssessments

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
classmethod get_object(obj: str)
classmethod get_snapshot_factory(type_str: str)
static get_uuid(long_id: str | Dict)
classmethod parse_from_region(region: Region) Iterable[RegionRelationAssessments]
static parse_id_arg(_id: str | List[str]) List[str]
classmethod parse_relationship_assessment(src: Region, assessment)
classmethod translate_cae(src: Region, _id: str | List[str])
classmethod translate_pevs(src: Region, _id: str | List[str])
anony_client
class siibra.core.region.SpatialProp
cog: SpatialPropCmpt = None
components: List[SpatialPropCmpt] = []
space: siibra.core.space.Space = None
class siibra.core.region.SpatialPropCmpt
centroid: siibra.locations.point.Point
volume: int
siibra.core.region.REGEX_TYPE
siibra.core.region.THRESHOLD_STATISTICAL_MAPS = None