Skip to content

Data layers

See Data layers for an introduction to data layers.

Layer

Layer(
    name: str = "",
    data: Any = None,
    meta: Optional[Dict] = None,
    position: Optional[Tuple] = None,
    tile_meta: Optional[TileMeta] = None,
    description: str = "",
    merger: str = "default",
    **meta_kwargs,
)

Base class of data layers.

A data layer holds a single piece of data (an image, a mask, a numeric value, etc.) together with metadata. Layers represent both the inputs and the outputs of algorithms.

Parameters:

Name Type Description Default
name str

Name of the layer.

""
data object

Data held by the layer. Its type depends on the subclass.

None
meta dict

Metadata dictionary. It is merged with description, merger, position, and extra keyword arguments (explicit meta keys take precedence).

None
position tuple

Position of the layer in global pixel coordinates.

None
tile_meta TileMeta

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

None
description str

Description of the layer, displayed on the algorithm documentation page.

""
merger str

Strategy used to merge the layer when it is assembled from tiles. Only Mask supports another strategy: "instances".

"default"
**meta_kwargs

Extra metadata, added to meta. In Napari, metadata keys are applied as properties of the displayed layer (e.g. colormap="viridis").

{}

Attributes:

Name Type Description
data Any

Data held by the layer.

name str

Name of the layer.

meta dict

Metadata about the layer.

kind str

A short string identifying the layer type, e.g. "mask".

position tuple

Position of the layer in global pixel coordinates.

extent Domain

Region covered by the data in global pixel coordinates. For objects such as points, it is the bounding box of the objects.

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.

shape tuple

Shape of the data, if it is array-like.

tile_meta TileMeta

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

select

select(domain: Domain) -> Layer

Select the part of the layer inside a domain.

Parameters:

Name Type Description Default
domain Domain

The region to select, in global pixel coordinates.

required

Returns:

Type Description
Layer

A new layer with the selected data, positioned in global coordinates.

Image

Image(
    data: Optional[ndarray] = None,
    name="Image",
    description="Input image",
    dimensionality: Optional[List[int]] = None,
    rgb: bool = False,
    channel_axis: Optional[int] = None,
    **kwargs,
)

Bases: Layer

Data layer for images: 2D or 3D arrays, optionally multichannel or RGB.

Parameters:

Name Type Description Default
data ndarray

The image array.

None
name str

Name of the layer.

"Image"
description str

Description of the layer, displayed on the algorithm documentation page.

"Input image"
dimensionality list of int

Accepted numbers of dimensions, for example [2, 3]. By default, any number of dimensions is accepted.

None
rgb bool

Set to True for RGB images.

False
channel_axis int

Index of the channel axis, for multichannel images. The channel axis is not counted as a spatial dimension (it doesn't affect ndim and extent), and it is never split into tiles. With rgb=True, the last axis is always the channel axis.

None
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

Examples:

>>> image = sk.Image(np.zeros((100, 200)), name="Blurred", colormap="viridis")

Mask

Mask(
    data: Optional[ndarray] = None,
    name: str = "Mask",
    description: str = "Segmentation mask",
    dimensionality: Optional[List[int]] = None,
    channel_axis: Optional[int] = None,
    **kwargs,
)

Bases: Layer

Data layer for segmentation masks.

Masks are label images, where integer values encode either object classes (e.g. for pixel classification) or object instances.

Parameters:

Name Type Description Default
data ndarray

The label image. Boolean arrays are accepted for binary masks.

None
name str

Name of the layer.

"Mask"
description str

Description of the layer, displayed on the algorithm documentation page.

"Segmentation mask"
dimensionality list of int

Accepted numbers of dimensions, for example [2, 3]. By default, any number of dimensions is accepted.

None
channel_axis int

Index of the channel axis, if any. The channel axis is not counted as a spatial dimension, and it is never split into tiles.

None
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties. Use merger="instances" for instance segmentation masks, so that labels stay unique when the mask is assembled from tiles.

{}

Examples:

>>> mask = sk.Mask(labels, name="Nuclei", merger="instances")

Points

Points(
    data: Optional[ndarray] = None,
    name="Points",
    description="Input points (2D, 3D)",
    dimensionality: Optional[List[int]] = None,
    **kwargs,
)

Bases: Layer

Data layer for sets of points (2D, 3D).

Parameters:

Name Type Description Default
data ndarray

Point coordinates, as an array of shape (N, D), where D is the number of dimensions.

None
name str

Name of the layer.

"Points"
description str

Description of the layer, displayed on the algorithm documentation page.

"Input points (2D, 3D)"
dimensionality list of int

Accepted numbers of dimensions, for example [2, 3]. By default, any number of dimensions is accepted.

None
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

Vectors

Vectors(
    data: Optional[ndarray] = None,
    name="Vectors",
    description="Input vectors (2D, 3D)",
    dimensionality: Optional[List[int]] = None,
    **kwargs,
)

Bases: Layer

Data layer for sets of vectors (2D, 3D).

Each vector is defined by an origin point and a displacement.

Parameters:

Name Type Description Default
data ndarray

An array of shape (N, 2, D), where D is the number of dimensions. data[:, 0, :] holds the origins of the vectors, and data[:, 1, :] the displacements from the origins.

None
name str

Name of the layer.

"Vectors"
description str

Description of the layer, displayed on the algorithm documentation page.

"Input vectors (2D, 3D)"
dimensionality list of int

Accepted numbers of dimensions, for example [2, 3]. By default, any number of dimensions is accepted.

None
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

Boxes

Boxes(
    data: Optional[ndarray] = None,
    name="Boxes",
    description="Bounding boxes",
    dimensionality: Optional[List[int]] = None,
    **kwargs,
)

Bases: Layer

Data layer for bounding boxes (2D, 3D).

Boxes can be oriented (OBB).

Parameters:

Name Type Description Default
data ndarray

The coordinates of the four corners of each box, as an array of shape (N, 4, D), where D is the number of dimensions.

None
name str

Name of the layer.

"Boxes"
description str

Description of the layer, displayed on the algorithm documentation page.

"Bounding boxes"
dimensionality list of int

Accepted numbers of dimensions, for example [2, 3]. By default, any number of dimensions is accepted.

None
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

Paths

Paths(
    data: Optional[List] = None,
    name="Paths",
    description="Input paths (2D, 3D)",
    dimensionality: Optional[List[int]] = None,
    serializer: str = "default",
    **kwargs,
)

Bases: Layer

Data layer for paths (2D, 3D), for example spline curves.

Parameters:

Name Type Description Default
data list of numpy.ndarray

One array per path, each of shape (N, D), where N is the number of points in the path and D the number of dimensions.

None
name str

Name of the layer.

"Paths"
description str

Description of the layer, displayed on the algorithm documentation page.

"Input paths (2D, 3D)"
dimensionality list of int

Accepted numbers of dimensions, for example [2, 3]. By default, any number of dimensions is accepted.

None
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

Tracks

Tracks(
    data: Optional[ndarray] = None,
    name="Tracks",
    description="Input tracks (2D, 3D)",
    dimensionality: Optional[List[int]] = None,
    **kwargs,
)

Bases: Layer

Data layer for object tracks: point detections linked over time by a track ID.

Parameters:

Name Type Description Default
data ndarray

An array of shape (N, D+1), with columns [ID, T, (Z), Y, X].

None
name str

Name of the layer.

"Tracks"
description str

Description of the layer, displayed on the algorithm documentation page.

"Input tracks (2D, 3D)"
dimensionality list of int

Accepted numbers of dimensions, for example [2, 3]. By default, any number of dimensions is accepted.

None
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

Float

Float(
    data: Optional[float] = None,
    name="Float",
    min: float = float(min),
    max: float = float(max),
    step: float = 0.1,
    default: float = 0.0,
    required: bool = True,
    auto_call: bool = False,
    **kwargs,
)

Bases: Layer

Data layer for floating-point values.

Parameters:

Name Type Description Default
data float

The value.

None
name str

Name of the layer.

"Float"
min float

Minimum accepted value.

float(min)
max float

Maximum accepted value.

float(max)
step float

Step size of the spin box in user interfaces.

0.1
default float

Default value, used when data is not provided.

0.0
auto_call bool

Re-run the algorithm when the value changes in user interfaces.

False
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

Examples:

>>> sigma = sk.Float(name="Sigma", min=0, default=1.0, step=0.5)

Integer

Integer(
    data: Optional[int] = None,
    name="Int",
    default: int = 0,
    required: bool = True,
    auto_call: bool = False,
    min: int = int(min),
    max: int = int(max),
    step: int = 1,
    **kwargs,
)

Bases: Layer

Data layer for integer values.

Parameters:

Name Type Description Default
data int

The value.

None
name str

Name of the layer.

"Int"
min int

Minimum accepted value.

int(min)
max int

Maximum accepted value.

int(max)
step int

Step size of the spin box in user interfaces.

1
default int

Default value, used when data is not provided.

0
auto_call bool

Re-run the algorithm when the value changes in user interfaces.

False
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

Examples:

>>> threshold = sk.Integer(name="Threshold", min=0, max=255, default=128)

Bool

Bool(
    data: Optional[bool] = None,
    name="Bool",
    default: bool = False,
    required: bool = True,
    auto_call: bool = False,
    **kwargs,
)

Bases: Layer

Data layer for boolean values, shown as a checkbox in user interfaces.

Parameters:

Name Type Description Default
data bool

The value.

None
name str

Name of the layer.

"Bool"
default bool

Default value, used when data is not provided.

False
auto_call bool

Re-run the algorithm when the value changes in user interfaces.

False
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

String

String(
    data: Optional[str] = None,
    name="String",
    default: str = "",
    required: bool = True,
    **kwargs,
)

Bases: Layer

Data layer for strings of text.

Parameters:

Name Type Description Default
data str

The text.

None
name str

Name of the layer.

"String"
default str

Default value, used when data is not provided.

""
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

Choice

Choice(
    data: Optional[str] = None,
    name="Choice",
    items: Optional[List] = None,
    required: bool = True,
    default: str = "",
    auto_call: bool = False,
    **kwargs,
)

Bases: Layer

Data layer for a choice among items, shown as a dropdown in user interfaces.

Can be used to represent labels for classification.

Parameters:

Name Type Description Default
data str

The selected item.

None
name str

Name of the layer.

"Choice"
items list of str

The available items.

None
default str

Default item, used when data is not provided.

""
auto_call bool

Re-run the algorithm when the selection changes in user interfaces.

False
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

Examples:

>>> mode = sk.Choice(items=["reflect", "constant"], default="reflect")

Notification

Notification(
    data: Optional[str] = None,
    level: Optional[str] = "info",
    name="Notification",
    required: bool = True,
    default: str = "",
    **kwargs,
)

Bases: Layer

Data layer for text notifications.

Notifications are printed to the terminal, or shown in user interfaces (as Napari notifications, for example).

Parameters:

Name Type Description Default
data str

The notification text.

None
level str

Notification level: "info", "warning", or "error".

"info"
name str

Name of the layer.

"Notification"
**kwargs

Passed to Layer.

{}

Examples:

>>> notif = sk.Notification("Warning!", level="warning")

Progress

Progress(
    data: Optional[int] = None,
    max_val: Optional[int] = 1,
    name="Progress",
    **kwargs,
)

Bases: Layer

Data layer for progress bars.

Progress is shown in the terminal, or as a progress bar in user interfaces.

Parameters:

Name Type Description Default
data int

Number of completed steps.

None
max_val int

Total number of steps.

1
name str

Name of the layer.

"Progress"
**kwargs

Passed to Layer.

{}

Examples:

>>> max_val = 10
>>> for k in range(max_val):
...     yield sk.Progress(k, max_val=max_val)

Null

Null(
    data: Optional[Any] = None,
    name="None",
    default=None,
    serializer: str = "default",
    **kwargs,
)

Bases: Layer

Data layer for None, or the absence of data.

Parameters:

Name Type Description Default
data None

Always None; accepted for consistency with other layers.

None
name str

Name of the layer.

"None"
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}

Any

Any(
    data: Optional[Any] = None,
    name="Any",
    default=None,
    serializer: str = "default",
    **kwargs,
)

Bases: Layer

Data layer for any other kind of data, such as custom Python objects.

Parameters with types that cannot be resolved, and outputs of unrecognized types, are represented by this layer. They are not shown in user interfaces.

Since this layer can hold arbitrary objects, it is generally not serializable, and only works locally (not with servers). Exceptions are simple JSON-compatible types (int, float, bool, str, numpy.ndarray), and lists, tuples, or dictionaries of these types.

Parameters:

Name Type Description Default
data object

Any kind of data.

None
name str

Name of the layer.

"Any"
**kwargs

Passed to Layer, e.g. position, meta, or extra metadata such as display properties (colormap="viridis").

{}