Skip to content

Stacks and domains

Stack

Stack(
    layers: Optional[List[Layer]] = None,
    tile_meta: Optional[TileMeta] = None,
    position: Optional[Tuple] = None,
)

An ordered collection of data layers.

Access layers by index (stack[0]) or by name (stack.read("Layer name")). Further indices are spatial, as with NumPy arrays: stack[:, 50:150] selects rows 50 to 150 of all layers.

Parameters:

Name Type Description Default
layers list of Layer

Initial layers of the stack.

None
tile_meta TileMeta

Metadata about the stack's position and role in a set of tiles.

None
position tuple

Position of the stack in global pixel coordinates.

None

Attributes:

Name Type Description
layers list of Layer

The layers in the stack.

position tuple

Position of the stack in global pixel coordinates. Setting it offsets the positions of all layers.

extent Domain

Smallest region containing all layers, in global pixel coordinates.

size tuple

Size of the extent.

coords_min tuple

Lower corner of the extent.

coords_max tuple

Upper corner of the extent.

ndim int

Number of spatial dimensions of the extent.

tile_meta TileMeta

Metadata about the stack's position and role in a set of tiles.

add

add(layer: Layer) -> Layer

Add a layer to the stack.

Parameters:

Name Type Description Default
layer Layer

The layer to add. If a layer with the same name already exists, a suffix is appended to the name of the new layer (e.g. Image-01).

required

Returns:

Type Description
Layer

The added layer.

read

read(name: str) -> Optional[Layer]

Get a layer by name.

Parameters:

Name Type Description Default
name str

Name of the layer.

required

Returns:

Type Description
Layer or None

The layer, or None if there is no layer with that name.

delete

delete(name: str) -> None

Delete a layer by name.

Parameters:

Name Type Description Default
name str

Name of the layer to delete.

required

select

select(domain: Domain) -> Stack

Select the part of the stack inside a domain.

Parameters:

Name Type Description Default
domain Domain

The region to select, in global pixel coordinates.

required

Returns:

Type Description
Stack

A new stack with the selected part of each layer.

merge

merge(
    stack: Optional[Stack],
    reinitialize_domain: Optional[Domain] = None,
) -> None

Merge another stack into this one, in place.

Incoming layers with the same name as an existing layer are merged into that layer, following the merging strategy of the layer type. Other incoming layers are added to the stack.

Parameters:

Name Type Description Default
stack Stack

The stack to merge. If None, nothing happens.

required
reinitialize_domain Domain

A region of the existing layers to reinitialize before merging the first tile of the incoming stack.

None

Domain

Domain(
    size: Optional[Union[Tuple, List]] = None,
    position: Optional[Union[Tuple, List]] = None,
)

An n-D box defined by a size and a position in global pixel coordinates.

Domains represent regions of interest and tile extents, and are used to restrict the computation of an algorithm to a region.

Parameters:

Name Type Description Default
size tuple

Size of the domain in pixels, one value per dimension.

None
position tuple

Position of the lower corner of the domain (top-left in 2D), in global pixel coordinates. Defaults to the origin if only size is provided.

None

Attributes:

Name Type Description
size tuple

Size of the domain in pixels.

coords_min tuple

Lower corner of the domain (top-left in 2D).

coords_max tuple

Upper corner of the domain (bottom-right in 2D).

ndim int

Number of dimensions.

Examples:

>>> roi = sk.Domain(position=(20, 30), size=(60, 80))
>>> roi.coords_max
(80.0, 110.0)

merge_layers

merge_layers(layers: List[Layer]) -> Layer

Merge a list of data layers of the same kind into a new layer.

The layers are merged as successive tiles, following the merging strategy of the layer type (see the "Merging tiles" section of the documentation). The input layers are not modified.

Parameters:

Name Type Description Default
layers list of Layer

The layers to merge. They must all be of the same kind.

required

Returns:

Type Description
Layer

A new layer containing the merged data. If a single layer is given, it is returned as is.

Raises:

Type Description
ValueError

If layers is empty, or if the layers are not all of the same kind.