Skip to content

webknossos.dataset

RemoteLayer

RemoteLayer(
    dataset: RemoteDataset,
    properties: LayerProperties,
    read_only: bool,
)

Bases: AbstractLayer

bounding_box property writable

bounding_box: NDBoundingBox

Gets the bounding box encompassing this layer's data.

Returns:

  • NDBoundingBox ( NDBoundingBox ) –

    Bounding box with layer dimensions

category property

category: LayerCategoryType

Gets the category type of this layer.

Returns:

  • LayerCategoryType ( LayerCategoryType ) –

    Layer category (e.g. COLOR_CATEGORY)

coordinate_transformations property writable

coordinate_transformations: tuple[
    CoordinateTransformation, ...
]

Gets the coordinate transformations that place this layer into the coordinate space of its dataset.

The transformations are applied in order. They only affect how WEBKNOSSOS renders the layer, the voxel data itself is not modified.

Returns:

  • tuple[CoordinateTransformation, ...]

    tuple[CoordinateTransformation, ...]: The transformations, empty if there are none.

data_format property

data_format: DataFormat

Gets the data storage format used by this layer.

Returns:

  • DataFormat ( DataFormat ) –

    Format used to store data

Raises:

  • AssertionError

    If data_format is not set in properties

dataset property

dataset: RemoteDataset

default_view_configuration property writable

default_view_configuration: LayerViewConfiguration | None

Gets the default view configuration for this layer.

Returns:

dtype property

dtype: dtype

Gets the data type used per channel.

Returns:

  • dtype

    np.dtype: NumPy data type for individual channels

dtype_per_channel property

dtype_per_channel: dtype

Deprecated. Use dtype instead. Gets the data type used per channel.

Returns:

  • dtype

    np.dtype: NumPy data type for individual channels

mags property

mags: Mapping[Mag, MagView]

Getter for dictionary containing all mags.

name property writable

name: str

Returns the name of the layer.

normalized_bounding_box property

normalized_bounding_box: NormalizedBoundingBox

Gets the bounding box with axes normalized to include the channel dimension.

Returns:

num_channels property

num_channels: int

Gets the number of channels in this layer.

Returns:

  • int ( int ) –

    Number of channels

Raises:

  • AssertionError

    If num_channels is not set in properties

read_only property

read_only: bool

Whether this layer is read-only.

Returns:

  • bool ( bool ) –

    True if layer is read-only, False if writable

view_configuration property writable

view_configuration: LayerViewConfiguration | None

The current view configuration for this layer as stored on the WEBKNOSSOS server.

This reflects the user-saved view settings (color, opacity, intensity range, etc.) and is distinct from default_view_configuration, which is default for all users accessing the dataset properties. The value is fetched from the server on every access.

Returns:

  • LayerViewConfiguration | None

    LayerViewConfiguration | None: The saved view configuration, or None if none is set.

Examples:

cfg = layer.view_configuration
if cfg is not None:
    print(cfg.color, cfg.alpha)

add_mag_as_copy

add_mag_as_copy(
    foreign_mag_view_or_path: (
        PathLike | UPath | str | MagView
    ),
    *,
    extend_layer_bounding_box: bool = True,
    transfer_mode: TransferMode = COPY,
    common_storage_path_prefix: str | None = None,
    overwrite_pending: bool = True
) -> MagView[RemoteLayer]

Copies the data at foreign_mag_view_or_path which can belong to another dataset to the current remote dataset. Additionally, the relevant information from the datasource-properties.json of the other dataset are copied, too.

add_mag_as_ref

add_mag_as_ref(
    foreign_mag_view_or_path: (
        PathLike | UPath | str | MagView
    ),
    *,
    mag: MagLike | None = None,
    extend_layer_bounding_box: bool = True
) -> MagView[RemoteLayer]

Add a mag from another remote dataset by reference.

Creates a mag that references data from a foreign remote layer without copying it.

Parameters:

  • foreign_mag_view_or_path (PathLike | UPath | str | MagView) –

    Foreign mag to add (path or MagView object)

  • mag (MagLike | None, default: None ) –

    Target mag level; uses the foreign mag level if None

  • extend_layer_bounding_box (bool, default: True ) –

    If True, extends this layer's bounding box to include the foreign layer's bounding box

Returns:

  • MagView ( MagView[RemoteLayer] ) –

    The newly created mag view referencing the foreign data

Raises:

  • ValueError

    If the foreign mag belongs to a local layer or a different WEBKNOSSOS instance

as_segmentation_layer

as_segmentation_layer() -> RemoteSegmentationLayer

Casts into SegmentationLayer.

delete_mag

delete_mag(mag: MagLike) -> None

downsample

downsample(
    *,
    from_mag: Mag | None = None,
    coarsest_mag: Mag | None = None,
    interpolation_mode: str = "default",
    compress: bool | Zarr3Config = True,
    sampling_mode: str | SamplingModes = ANISOTROPIC,
    align_with_other_layers: bool = True,
    buffer_shape: Vec3IntLike | int | None = None,
    chunk_shape: Vec3IntLike | int | None = None,
    shard_shape: Vec3IntLike | int | None = None,
    force_sampling_scheme: bool = False,
    transfer_mode: TransferMode = COPY,
    common_storage_path_prefix: str | None = None,
    overwrite_pending: bool = True,
    executor: Executor | None = None
) -> None

Downsample data from a source magnification to coarser magnifications.

Downsamples the data starting from from_mag until a magnification is >= max(coarsest_mag). Different sampling modes control how dimensions are downsampled.

Note that the data is written temporarily on the local disk and uploaded afterwards so some local disk space is required.

Parameters:

  • from_mag (Mag | None, default: None ) –

    Source magnification to downsample from. Defaults to highest existing mag.

  • coarsest_mag (Mag | None, default: None ) –

    Target magnification to stop at. Defaults to calculated value.

  • interpolation_mode (str, default: 'default' ) –

    Interpolation method to use. Defaults to "default". Supported modes: "median", "mode", "nearest", "bilinear", "bicubic"

  • compress (bool | Zarr3Config, default: True ) –

    Whether to compress the generated magnifications. For Zarr3 datasets, codec configuration and chunk key encoding may also be supplied. Defaults to True.

  • sampling_mode (str | SamplingModes, default: ANISOTROPIC ) –

    How dimensions should be downsampled. Defaults to ANISOTROPIC.

  • align_with_other_layers (bool, default: True ) –

    Whether to align the mag selection with the dataset’s other layers. True by default.

  • buffer_shape (Vec3IntLike | int | None, default: None ) –

    Shape of processing buffer. Defaults to None.

  • chunk_shape (Vec3IntLike | int | None, default: None ) –

    Shape of chunks for storage.

  • shard_shape (Vec3IntLike | int | None, default: None ) –

    Shape of shards for storage.

  • force_sampling_scheme (bool, default: False ) –

    Force invalid sampling schemes. Defaults to False.

  • common_storage_path_prefix (str | None, default: None ) –

    Optional path prefix used when transfer_mode is either COPY or MOVE_AND_SYMLINK to select one of the available WEBKNOSSOS storages.

  • executor (Executor | None, default: None ) –

    Executor for parallel processing. None by default.

Raises:

  • AssertionError

    If from_mag does not exist

  • RuntimeError

    If sampling scheme produces invalid magnifications

  • AttributeError

    If sampling_mode is invalid

get_finest_mag

get_finest_mag() -> MagView[RemoteLayer]

get_mag

get_mag(mag: MagLike) -> MagView[RemoteLayer]

upsample

upsample(
    from_mag: Mag,
    *,
    finest_mag: Mag = Mag(1),
    compress: bool | Zarr3Config = True,
    sampling_mode: str | SamplingModes = ANISOTROPIC,
    align_with_other_layers: bool = True,
    buffer_shape: Vec3IntLike | None = None,
    transfer_mode: TransferMode = COPY,
    common_storage_path_prefix: str | None = None,
    overwrite_pending: bool = True,
    executor: Executor | None = None
) -> None

Upsample data to finer magnifications.

Upsamples from a coarser magnification to a sequence of finer magnifications, stopping at finest_mag. The data is written temporarily on the local disk and uploaded afterwards, so some local disk space is required.

Parameters:

  • from_mag (Mag) –

    Source coarse magnification.

  • finest_mag (Mag, default: Mag(1) ) –

    Target finest magnification. Defaults to Mag(1).

  • compress (bool | Zarr3Config, default: True ) –

    Whether to compress upsampled data. For Zarr3 datasets, codec configuration and chunk key encoding may also be supplied. Defaults to True.

  • sampling_mode (str | SamplingModes, default: ANISOTROPIC ) –

    How dimensions should be upsampled. Defaults to ANISOTROPIC.

  • align_with_other_layers (bool, default: True ) –

    Whether to align mags with the dataset's other layers. Defaults to True.

  • buffer_shape (Vec3IntLike | None, default: None ) –

    Shape of processing buffer. Defaults to None.

  • transfer_mode (TransferMode, default: COPY ) –

    How new mags are transferred to the remote storage. Defaults to COPY.

  • common_storage_path_prefix (str | None, default: None ) –

    Optional path prefix used when transfer_mode is COPY or MOVE_AND_SYMLINK.

  • overwrite_pending (bool, default: True ) –

    If there are already pending/unfinished committed mags on the server, overwrite them. Defaults to True.

  • executor (Executor | None, default: None ) –

    Executor for parallel processing. Defaults to None.

Raises:

  • KeyError

    If from_mag doesn't exist is invalid.

  • AssertionError

    If finest_mag is invalid.

  • AttributeError

    If sampling_mode is invalid.