bsb.topology package#

Submodules#

bsb.topology.partition module#

Module for the Partition configuration nodes and its dependencies.

class bsb.topology.partition.AllenStructure(*args, _parent=None, _key=None, **kwargs)[source]#

Bases: NrrdVoxels

Partition based on the Allen Institute for Brain Science mouse brain region ontology, later referred as Allen Mouse Brain Region Hierarchy (AMBRH)

classmethod find_structure(id)[source]#

Find an Allen structure by name, acronym or ID.

Parameters:

id (Union[str, int, float]) – Query for the name, acronym or ID of the Allen structure.

Returns:

Allen structure node of the Allen ontology tree.

Return type:

dict

Raises:

NodeNotFoundError

get_node_name()#
classmethod get_structure_idset(find)[source]#

Return the set of IDs that make up the requested Allen structure.

Parameters:

find (Union[str, int]) – Acronym or ID of the Allen structure.

Returns:

Set of IDs

Return type:

numpy.ndarray

classmethod get_structure_mask(find)[source]#

Returns the mask data delineated by the Allen structure.

Parameters:

find (Union[str, int]) – Acronym, Name or ID of the Allen structure.

Returns:

A boolean of the mask filtered based on the Allen structure.

Return type:

Callable[numpy.ndarray]

classmethod get_structure_mask_condition(find)[source]#

Return a lambda that when applied to the mask data, returns a mask that delineates the Allen structure.

Parameters:

find (Union[str, int]) – Acronym, Name or ID of the Allen structure.

Returns:

Masking lambda

Return type:

Callable[numpy.ndarray]

mask_only: bool#

Flag to indicate no voxel data needs to be stored

mask_source: NrrdDependencyNode#

Path to the NRRD file containing the volumetric annotation data of the Partition.

struct_id: int#

Id of the region to filter within the annotation volume according to the AMBRH. If struct_id is set, then struct_name should not be set.

struct_name: str#

Name or acronym of the region to filter within the annotation volume according to the AMBRH. If struct_name is set, then struct_id should not be set.

voxel_size: int#

Size of each voxel.

class bsb.topology.partition.Layer(*args, _parent=None, _key=None, **kwargs)[source]#

Bases: Rhomboid

axis: Literal['x'] | Literal['y'] | Literal['z']#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

get_layout(hint)[source]#

Given a Layout as hint to begin from, create a Layout object that describes how this partition would like to be laid out.

Parameters:

hint (bsb.topology._layout.Layout) – The layout space that this partition should place itself in.

Returns:

The layout describing the space this partition takes up.

Return type:

bsb.topology._layout.Layout

get_node_name()#
stack_index: float#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

thickness: float#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

volume_scale: list[float]#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

class bsb.topology.partition.NrrdVoxels(*args, _parent=None, _key=None, **kwargs)[source]#

Bases: Voxels

Voxel partition whose voxelset is loaded from an NRRD file. By default it includes all the nonzero voxels in the file, but other masking conditions can be specified. Additionally, data can be associated to each voxel by inclusion of (multiple) source NRRD files.

get_mask()[source]#

Get the mask to apply on the sources’ data of the partition.

Returns:

A tuple of arrays, one for each dimension of the mask, containing the indices of the non-zero elements in that dimension.

get_node_name()#
get_voxelset()[source]#

Creates a VoxelSet of the sources of the Partition that matches its mask.

Returns:

VoxelSet of the Partition sources.

keys: list[str]#

List of names to assign to each source of the Partition.

mask_only: bool#

Flag to indicate no voxel data needs to be stored

mask_source: NrrdDependencyNode#

Path to the NRRD file containing the volumetric annotation data of the Partition.

mask_value: int#

Integer value to filter in mask_source (if it is set, otherwise sources/source) to create a mask of the voxel set(s) used as input.

source: NrrdDependencyNode#

Path to the NRRD file containing volumetric data to associate with the partition. If source is set, then sources should not be set.

sources: NrrdDependencyNode#

List of paths to NRRD files containing volumetric data to associate with the Partition. If sources is set, then source should not be set.

sparse: bool#

Boolean flag to expect a sparse or dense mask. If the mask selects most voxels, use dense, otherwise use sparse.

strict: bool#

Boolean flag to check the sources and the mask sizes. When the flag is True, sources and mask should have exactly the same sizes; otherwise, sources sizes should be greater than mask sizes.

voxel_size: int#

Size of each voxel.

class bsb.topology.partition.Partition(*args, _parent=None, _key=None, **kwargs)[source]#

Bases: ABC

abstract chunk_to_voxels(chunk)[source]#

Voxelize the partition’s occupation in this chunk. Required to fill the partition with cells by the placement module.

Parameters:

chunk (bsb.storage._chunks.Chunk) – The chunk to calculate voxels for.

Returns:

The set of voxels that together make up the shape of this partition in this chunk.

Return type:

bsb.voxels.VoxelSet

property data#
abstract get_layout(hint)[source]#

Given a Layout as hint to begin from, create a Layout object that describes how this partition would like to be laid out.

Parameters:

hint (bsb.topology._layout.Layout) – The layout space that this partition should place itself in.

Returns:

The layout describing the space this partition takes up.

Return type:

bsb.topology._layout.Layout

get_node_name()#
name: str#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

property region[source]#
abstract rotate(rotation)[source]#

Rotate the partition by the given rotation object.

Parameters:

rotation (scipy.spatial.transform.Rotation) – Rotation object.

Raises:

exceptions.LayoutError if the rotation needs to be rejected.

scaffold: Scaffold#
abstract scale(factors)[source]#

Scale up/down the partition according to the given factors.

Parameters:

factors (numpy.ndarray) – Scaling factors, XYZ.

Raises:

exceptions.LayoutError if the scaling needs to be rejected.

abstract surface(chunk=None)[source]#

Calculate the surface of the partition in μm^2.

Parameters:

chunk (bsb.storage._chunks.Chunk) – If given, limit the surface of the partition inside of the chunk.

Returns:

Surface of the partition (in the chunk)

Return type:

float

abstract to_chunks(chunk_size)[source]#

Calculate all the chunks this partition occupies when cut into chunk_sized pieces.

Parameters:

chunk_size (numpy.ndarray) – Size per chunk (in μm). The slicing always starts at [0, 0, 0].

Returns:

Chunks occupied by this partition

Return type:

List[bsb.storage._chunks.Chunk]

abstract translate(offset)[source]#

Translate the partition by the given offset.

Parameters:

offset (numpy.ndarray) – Offset, XYZ.

Raises:

exceptions.LayoutError if the translation needs to be rejected.

type#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

abstract volume(chunk=None)[source]#

Calculate the volume of the partition in μm^3.

Parameters:

chunk (bsb.storage._chunks.Chunk) – If given, limit the volume of the partition inside of the chunk.

Returns:

Volume of the partition (in the chunk)

Return type:

float

class bsb.topology.partition.Rhomboid(*args, _parent=None, _key=None, **kwargs)[source]#

Bases: Partition

can_move: bool#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

can_rotate: bool#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

can_scale: bool#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

chunk_to_voxels(chunk)[source]#

Return an approximation of this partition intersected with a chunk as a list of voxels.

Default implementation creates a parallellepepid intersection between the LDC, MDC and chunk data.

dimensions: list[float]#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

get_dependencies()[source]#

Return other partitions or regions that need to be laid out before this.

get_layout(hint)[source]#

Given a Layout as hint to begin from, create a Layout object that describes how this partition would like to be laid out.

Parameters:

hint (bsb.topology._layout.Layout) – The layout space that this partition should place itself in.

Returns:

The layout describing the space this partition takes up.

Return type:

bsb.topology._layout.Layout

get_node_name()#
property ldc#
property mdc#
orientation: list[float]#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

origin: list[float]#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

rotate(rot)[source]#

Rotate the partition by the given rotation object.

Parameters:

rotation (scipy.spatial.transform.Rotation) – Rotation object.

Raises:

exceptions.LayoutError if the rotation needs to be rejected.

scale(factors)[source]#

Scale up/down the partition according to the given factors.

Parameters:

factors (numpy.ndarray) – Scaling factors, XYZ.

Raises:

exceptions.LayoutError if the scaling needs to be rejected.

surface(chunk=None)[source]#

Calculate the surface of the partition in μm^2.

Parameters:

chunk (bsb.storage._chunks.Chunk) – If given, limit the surface of the partition inside of the chunk.

Returns:

Surface of the partition (in the chunk)

Return type:

float

to_chunks(chunk_size)[source]#

Calculate all the chunks this partition occupies when cut into chunk_sized pieces.

Parameters:

chunk_size (numpy.ndarray) – Size per chunk (in μm). The slicing always starts at [0, 0, 0].

Returns:

Chunks occupied by this partition

Return type:

List[bsb.storage._chunks.Chunk]

translate(translation)[source]#

Translate the partition by the given offset.

Parameters:

offset (numpy.ndarray) – Offset, XYZ.

Raises:

exceptions.LayoutError if the translation needs to be rejected.

volume(chunk=None)[source]#

Calculate the volume of the partition in μm^3.

Parameters:

chunk (bsb.storage._chunks.Chunk) – If given, limit the volume of the partition inside of the chunk.

Returns:

Volume of the partition (in the chunk)

Return type:

float

class bsb.topology.partition.Voxels(*args, _parent=None, _key=None, **kwargs)[source]#

Bases: Partition, ABC

Partition based on a set of voxels.

chunk_to_voxels(chunk)[source]#

Voxelize the partition’s occupation in this chunk. Required to fill the partition with cells by the placement module.

Parameters:

chunk (bsb.storage._chunks.Chunk) – The chunk to calculate voxels for.

Returns:

The set of voxels that together make up the shape of this partition in this chunk.

Return type:

bsb.voxels.VoxelSet

get_layout(hint)[source]#

Given a Layout as hint to begin from, create a Layout object that describes how this partition would like to be laid out.

Parameters:

hint (bsb.topology._layout.Layout) – The layout space that this partition should place itself in.

Returns:

The layout describing the space this partition takes up.

Return type:

bsb.topology._layout.Layout

get_node_name()#
abstract get_voxelset()[source]#
rotate(rotation)[source]#

Rotate the partition by the given rotation object.

Parameters:

rotation (scipy.spatial.transform.Rotation) – Rotation object.

Raises:

exceptions.LayoutError if the rotation needs to be rejected.

scale(factor)[source]#

Scale up/down the partition according to the given factors.

Parameters:

factors (numpy.ndarray) – Scaling factors, XYZ.

Raises:

exceptions.LayoutError if the scaling needs to be rejected.

surface(chunk=None)[source]#

Calculate the surface of the partition in μm^2.

Parameters:

chunk (bsb.storage._chunks.Chunk) – If given, limit the surface of the partition inside of the chunk.

Returns:

Surface of the partition (in the chunk)

Return type:

float

to_chunks(chunk_size)[source]#

Calculate all the chunks this partition occupies when cut into chunk_sized pieces.

Parameters:

chunk_size (numpy.ndarray) – Size per chunk (in μm). The slicing always starts at [0, 0, 0].

Returns:

Chunks occupied by this partition

Return type:

List[bsb.storage._chunks.Chunk]

translate(offset)[source]#

Translate the partition by the given offset.

Parameters:

offset (numpy.ndarray) – Offset, XYZ.

Raises:

exceptions.LayoutError if the translation needs to be rejected.

volume(chunk=None)[source]#

Calculate the volume of the partition in μm^3.

Parameters:

chunk (bsb.storage._chunks.Chunk) – If given, limit the volume of the partition inside of the chunk.

Returns:

Volume of the partition (in the chunk)

Return type:

float

property voxelset#

bsb.topology.region module#

Module for the Region types.

class bsb.topology.region.Region(*args, _parent=None, _key=None, **kwargs)[source]#

Bases: ABC

Base region.

When arranging will simply call arrange/layout on its children but won’t cause any changes itself.

children: list[Region | Partition]#
property data#
do_layout(hint)[source]#
get_dependencies()[source]#
get_layout(hint)[source]#
get_node_name()#
name: str#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

abstract rotate(rotation)[source]#
scaffold: Scaffold#
abstract scale(factors)[source]#
abstract translate(offset)[source]#
type#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

class bsb.topology.region.RegionGroup(*args, _parent=None, _key=None, **kwargs)[source]#

Bases: Region

get_node_name()#
rotate(rotation)[source]#
scale(factors)[source]#
translate(offset)[source]#
class bsb.topology.region.Stack(*args, _parent=None, _key=None, **kwargs)[source]#

Bases: RegionGroup

Stack components on top of each other based on their stack_index and adjust its own height accordingly.

axis: Literal['x'] | Literal['y'] | Literal['z']#

Base implementation of all the different configuration attributes. Call the factory function attr() instead.

get_layout(hint)[source]#
get_node_name()#
rotate(rotation)[source]#
scale(factors)[source]#
translate(offset)[source]#

Module contents#

Topology module

bsb.topology.box_layout(ldc, mdc)[source]#
bsb.topology.create_topology(regions, ldc, mdc)[source]#

Create a topology from group of regions. Will check for root regions, if there’s not exactly 1 root region a RegionGroup will be created as new root.

Parameters:
  • regions (Iterable) – Any iterable of regions.

  • ldc – Least dominant corner of the topology. Forms the suggested outer bounds of the topology together with the mdc.

  • mdc – Most dominant corner of the topology. Forms the suggested outer bounds of the topology together with the mdc.

bsb.topology.get_partitions(regions)[source]#

Get all of the partitions belonging to the group of regions and their subregions.

Parameters:

regions (Iterable) – Any iterable of regions.

bsb.topology.get_root_regions(regions)[source]#

Get all of the root regions, not belonging to any other region in the given group.

Parameters:

regions (Iterable) – Any iterable of regions.

bsb.topology.is_partition(obj)[source]#

Checks if an object is a partition.

bsb.topology.is_region(obj)[source]#

Checks if an object is a region.