cellmap_data.utils.roi#

Classes

Roi(offset, shape)

A rectangular region of interest, defined by an offset and a shape. Special Cases: An infinite/unbounded ROI: offset = (None, None, ...) shape = (None, None, ...).

class cellmap_data.utils.roi.Roi(offset: Iterable[int | float | None], shape: Iterable[int | float | None])[source]#

A rectangular region of interest, defined by an offset and a shape. Special Cases:

An infinite/unbounded ROI:

offset = (None, None, …) shape = (None, None, …)

An empty ROI (e.g. output of intersecting two non overlapping Rois):

offset = (None, None, …) shape = (0, 0, …)

A ROI that only specifies a shape is not supported (just use Coordinate).

There is no guessing size of offset or shape (expanding to number of dims of the other).

Basic Operations:

Addition/subtraction (Coordinate, int, or float) - shifts the offset elementwise (alias for shift)

Multiplication/division (Coordinate, int, or float) - multiplies/divides the offset and the shape, elementwise

Roi Operations:

Intersect, union

Similar to Coordinate, supports simple arithmetics, e.g.:

roi = Roi((1., 1., 1), (10., 10., 10))
voxel_size = Coordinate((10, 5, 1))
roi * voxel_size = Roi((10, 5, 1), (100, 50, 10))
scale_shift = roi*voxel_size + 1 # == Roi((11, 6, 2), (101, 51, 11))
Parameters:
  • offset (array-like of int or float) – The offset of the ROI. Entries can be None to indicate there is no offset (either unbounded or empty).

  • shape (array-like of int or float) – The shape of the ROI. Entries can be None to indicate unboundedness.

squeeze(dim: int = 0) Roi[source]#
Parameters:

dim (int)

Return type:

Roi

property offset: Coordinate#
get_offset() Coordinate[source]#
Return type:

Coordinate

set_offset(new_offset: Iterable[int | float | None]) None[source]#
Parameters:

new_offset (Iterable[int | float | None])

Return type:

None

property shape: Coordinate#
get_shape() Coordinate[source]#
Return type:

Coordinate

set_shape(new_shape: Iterable[int | float | None]) None[source]#
Parameters:

new_shape (Iterable[int | float | None])

Return type:

None

property begin: Coordinate#

Smallest coordinate inside ROI.

get_begin() Coordinate[source]#
Return type:

Coordinate

property end: Coordinate#

Smallest coordinate which is component-wise larger than any inside ROI.

get_end() Coordinate[source]#
Return type:

Coordinate

property center: Coordinate#

Get the center of this ROI.

get_center() Coordinate[source]#
Return type:

Coordinate

to_slices(grid_size: Coordinate | int | float | Iterable[int | float] = 1) Tuple[slice, ...][source]#

Get a tuple of slice that represent this ROI and can be used to index arrays.

Parameters:
  • grid_size (Coordinate or int or float or None, optional)

  • None (The size of the grid to divide coordinates by. If)

Return type:

Tuple[slice, …]

:param : :param coordinates are simply rounded outward to ensure full ROI: :param coverage. If a number: :param it is used for all dimensions.:

get_bounding_box() Tuple[slice, ...][source]#

Alias for to_slices().

Return type:

Tuple[slice, …]

property dims: int#

The the number of dimensions of this ROI.

property size: float | None#

Get the volume of this ROI. Returns None if the ROI is unbounded.

get_size() float | None[source]#
Return type:

float | None

property empty: bool#

Test if this ROI is empty.

property unbounded: bool#

Test if this ROI is unbounded.

contains(other: Roi | Iterable[int | float | None]) bool[source]#

Test if this ROI contains other, which can be another Roi, Coordinate, or tuple.

Parameters:

other (Roi | Iterable[int | float | None])

Return type:

bool

intersects(other: Roi) bool[source]#

Test if this ROI intersects with another Roi.

Parameters:

other (Roi)

Return type:

bool

intersect(other: Roi) Roi[source]#

Get the intersection of this ROI with another Roi.

Parameters:

other (Roi)

Return type:

Roi

union(other: Roi) Roi[source]#

Get the union of this ROI with another Roi.

Parameters:

other (Roi)

Return type:

Roi

shift(by: Coordinate | int | float) Roi[source]#

Shift this ROI.

Parameters:

by (Coordinate | int | float)

Return type:

Roi

snap_to_grid(voxel_size: Iterable[int | float | None], mode: str = 'grow') Roi[source]#

Align a ROI with a given voxel size.

Parameters:
  • voxel_size (Coordinate or tuple) – The voxel size of the grid to snap to.

  • mode (string, optional) – How to align the ROI if it is not a multiple of the voxel size. Available modes are ‘grow’, ‘shrink’, and ‘closest’. Defaults to ‘grow’.

Return type:

Roi

grow(amount_neg: Iterable[int | float | None] | int | float = 0, amount_pos: Iterable[int | float | None] | int | float = 0) Roi[source]#

Grow a ROI by the given amounts in each direction:

Parameters:
  • amount_neg (Coordinate or int or float) – Amount (per dimension) to grow into the negative direction. Passing in a single integer grows that amount in all dimensions. Defaults to zero.

  • amount_pos (Coordinate or int or float) – Amount (per dimension) to grow into the positive direction. Passing in a single integer grows that amount in all dimensions. Defaults to zero.

Return type:

Roi

copy() Roi[source]#

Create a copy of this ROI.

Return type:

Roi