Skip to content

webknossos.dataset.mag_view

A MagView contains all information about the data of a single magnification of a Layer. MagView inherits from View. The main difference is that the MagViewhas a reference to its Layer

Therefore, a MagView can write outside the specified bounding box (unlike a normal View), resizing the layer's bounding box. If necessary, the properties are automatically updated (e.g. if the bounding box changed).

# &nbsp MagView( layer: webknossos.dataset.layer.Layer, mag: webknossos.geometry.mag.Mag, chunk_shape: webknossos.geometry.vec3_int.Vec3Int, chunks_per_shard: webknossos.geometry.vec3_int.Vec3Int, compression_mode: bool, create: bool = False )

Do not use this constructor manually. Instead use webknossos.dataset.layer.Layer.add_mag().

⚠️ Deprecated, use Vec3Int.zeros() instead.

⚠️ Deprecated, use mag_view.bounding_box.in_mag(mag_view.mag).bottomright instead.

# &nbsp path: pathlib.Path
# &nbsp name: str
# &nbsp def get_zarr_array(self) -> zarr.core.Array:

Directly access the underlying Zarr array. Only available for Zarr-based datasets.

# &nbsp def write( self, data: numpy.ndarray, offset: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None, *, relative_offset: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None, absolute_offset: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None ) -> None:

Writes the data at the specified relative_offset or absolute_offset, both specified in Mag(1).

⚠️ The offset parameter is deprecated. This parameter used to be relative for View and absolute for MagView, and specified in the mag of the respective view.

Note that writing compressed data which is not aligned with the blocks on disk may result in diminished performance, as full blocks will automatically be read to pad the write actions.

# &nbsp def read( self, offset: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None, size: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None, *, relative_offset: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None, absolute_offset: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None, relative_bounding_box: Union[webknossos.geometry.bounding_box.BoundingBox, NoneType] = None, absolute_bounding_box: Union[webknossos.geometry.bounding_box.BoundingBox, NoneType] = None ) -> numpy.ndarray:

The user can specify which data should be read. The default is to read all data of the view's bounding box. Alternatively, one can supply one of the following keyword argument combinations:

  • relative_offset and size, both in Mag(1)
  • absolute_offset and size, both in Mag(1)
  • relative_bounding_box in Mag(1)
  • absolute_bounding_box in Mag(1)
  • ⚠️ deprecated: offset and size, both in the current Mag. offset used to be relative for View and absolute for MagView

If the specified bounding box exceeds the data on disk, the rest is padded with 0.

Returns the specified data as a np.array.

Example:

import numpy as np

# ...
# let mag1 be a MagView
view = mag1.get_view(absolute_offset=(10, 20, 30), size=(100, 200, 300))

assert np.array_equal(
    view.read(absolute_offset=(0, 0, 0), size=(100, 200, 300)),
    view.read(),
)
# &nbsp def get_view( self, offset: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None, size: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None, *, relative_offset: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None, absolute_offset: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None, read_only: Union[bool, NoneType] = None ) -> webknossos.dataset.view.View:

Returns a view that is limited to the specified bounding box. The new view may exceed the bounding box of the current view only if read_only is set to True.

The default is to return the same view as the current bounding box, in case of a MagView that's the layer bounding box. One can supply one of the following keyword argument combinations:

  • relative_offset and size, both in Mag(1)
  • absolute_offset and size, both in Mag(1)
  • ⚠️ deprecated: offset and size, both in the current Mag. offset used to be relative for View and absolute for MagView

Example:

# ...
# let mag1 be a MagView
view = mag1.get_view(absolute_offset=(10, 20, 30), size=(100, 200, 300))

# works because the specified sub-view is completely in the bounding box of the view
sub_view = view.get_view(relative_offset=(50, 60, 70), size=(10, 120, 230))

# fails because the specified sub-view is not completely in the bounding box of the view
invalid_sub_view = view.get_view(relative_offset=(50, 60, 70), size=(999, 120, 230))

# works because `read_only=True`
valid_sub_view = view.get_view(relative_offset=(50, 60, 70), size=(999, 120, 230), read_only=True)
# &nbsp def get_bounding_boxes_on_disk(self) -> Iterator[webknossos.geometry.bounding_box.BoundingBox]:

Returns a Mag(1) bounding box for each file on disk.

This differs from the bounding box in the properties, which is an "overall" bounding box, abstracting from the files on disk.

# &nbsp def get_views_on_disk( self, read_only: Union[bool, NoneType] = None ) -> Iterator[webknossos.dataset.view.View]:

Yields a view for each file on disk, which can be used for efficient parallelization.

# &nbsp def compress( self, target_path: Union[str, pathlib.Path, NoneType] = None, args: Union[argparse.Namespace, NoneType] = None, executor: Union[cluster_tools.schedulers.cluster_executor.ClusterExecutor, cluster_tools.executors.multiprocessing.MultiprocessingExecutor, NoneType] = None ) -> None:

Compresses the files on disk. This has consequences for writing data (see write).

The data gets compressed inplace, if target_path is None. Otherwise it is written to target_path/layer_name/mag.

Compressing mags on remote file systems requires a target_path.