Skip to content

webknossos.dataset

LayerExport

LayerExport(layer: AbstractLayer)

Exports a layer's data to common bioimaging file formats.

Accessible via layer.export, e.g.:

layer.export.as_ozx(output_path=UPath("out.ozx"))
layer.export.as_tiff_stack(output_path=UPath("out_tiffs"))
layer.export.as_ome_tiff(output_path=UPath("out.ome.tif"))

as_ome_tiff

as_ome_tiff(
    *,
    output_path: str | PathLike | UPath,
    bounding_box: NDBoundingBox | None = None,
    mag: Mag | None = None,
    downsample: bool = True,
    access_mode: RemoteAccessMode | None = None
) -> None

Exports the layer as a single OME-TIFF file.

Only layers whose axes are a subset of c, t, z, y, x are supported (OME-TIFF's own dimension model doesn't extend to other axes).

If downsample is True, the file also contains a pyramid of downsampled levels (by factors of 2 in x and y).

access_mode selects how a remote layer's data is read, defaulting to the dataset's access mode. It can't be passed for local layers.

as_ozx

as_ozx(
    *,
    output_path: str | PathLike | UPath,
    bounding_box: NDBoundingBox | None = None,
    mag: Mag | None = None,
    downsample: bool = True,
    access_mode: RemoteAccessMode | None = None,
    shard_shape: Vec3IntLike | int | None = None,
    executor: Executor | None = None
) -> None

Exports the layer as a single, zipped OME-Zarr archive compliant with NGFF RFC-9, "Zipped OME-Zarr" (.ozx). Layers with additional axes (e.g. time) are supported - the OME axes/scale metadata is derived from the layer's own axes.

If bounding_box is given, the export is cropped to it (intersected with the layer's own bounding box). Only mag (the finest mag if None) is read from the layer. If downsample is True, the archive also contains a pyramid of coarser mags computed by downsampling the exported data (like Layer.downsample with the anisotropic sampling mode), independent of which mags the layer itself has.

The output bounding box is translated to origin.

access_mode selects how a remote layer's data is read, defaulting to the dataset's access mode. It can't be passed for local layers.

shard_shape fixes the shard shape used for every exported mag. If omitted, a shard shape is picked per mag that just covers the exported region (searching upward from the default chunk shape), capped at the default shard shape (or the wider from-images default for flat data with few z sections).

as_tiff_stack

as_tiff_stack(
    *,
    output_path: str | PathLike | UPath,
    bounding_box: NDBoundingBox | None = None,
    mag: Mag | None = None,
    filename_prefix: str = "",
    access_mode: RemoteAccessMode | None = None
) -> None

Exports the layer as a directory of per-slice TIFF files, one file per z-section (and per combination of any additional axes, e.g. time), under output_path.

Files are named {NNNNNN}.tiff (or {filename_prefix}_{NNNNNN}.tiff) for plain 3D layers, or {axis}NNN_..._zNNN.tiff (one segment per additional axis, sorted by name, plus z; still prefixed with filename_prefix if given) for layers with additional axes. Each number is the slice's absolute coordinate along that axis (z in Mag(1) coordinates), zero-padded to the width of the layer's largest coordinate along it.