Skip to content

webknossos.dataset.mag_view

A MagView contains all information about the data of a single magnification of a webknossos.dataset.layer.Layer. MagView inherits from webknossos.dataset.view.View. Therefore, the main difference between them is that a MagView handles the whole magnification, whereas the View only handles a sub-region.

A MagView can read/write outside the specified bounding box (unlike a normal View). If necessary, the properties are automatically updated (e.g. if the bounding box changed). This is possible because a MagView does have a reference to the webknossos.dataset.layer.Layer.

The global_offset of a MagView is always (0, 0, 0) and its size is chosen so that the bounding box from the properties is fully inside this View.

#   MagView( layer: webknossos.dataset.layer.Layer, mag: webknossos.geometry.mag.Mag, block_len: int, file_len: int, block_type: int, create: bool = False )

Do not use this constructor manually. Instead use webknossos.dataset.layer.Layer.add_mag() to create a MagView.

#   path: pathlib.Path
#   name: str
#   def write( self, data: numpy.ndarray, offset: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], Tuple[int, ...], numpy.ndarray, List[int], Iterable[int]] = Vec3Int(0,0,0) ) -> None:

Writes the data at the specified offset to disk (like webknossos.dataset.view.View.write()).

The offset refers to the absolute position, regardless of the offset in the properties (because the global_offset is set to (0, 0, 0)). If the data exceeds the original bounding box, the properties are updated.

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.

#   def get_view( self, offset: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], Tuple[int, ...], numpy.ndarray, List[int], Iterable[int], NoneType] = None, size: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], Tuple[int, ...], numpy.ndarray, List[int], 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 offset refers to the absolute position, regardless of the offset in the properties (because the global_offset is set to (0, 0, 0)). The default value for offset is the offset that is specified in the properties. The default value for size is calculated so that the bounding box ends where the bounding box from the properties ends. Therefore, if both (offset and size) are not specified, then the bounding box of the view is equal to the bounding box specified in the properties.

The offset and size may only exceed the bounding box from the properties, if read_only is set to True.

If read_only is True, write operations are not allowed for the returned sub-view.

Example:

# ...
# Let 'mag1' be a `MagView` with offset (0, 0, 0) and size (100, 200, 300)

# Properties are used to determine the default parameter
view_with_bb_from_properties = mag1.get_view()

# Sub-view where the specified bounding box is completely in the bounding box of the MagView
sub_view1 = mag1.get_view(offset=(50, 60, 70), size=(10, 120, 230))

# Fails because the specified view is not completely in the bounding box from the properties.
sub_view2 = mag1.get_view(offset=(50, 60, 70), size=(999, 120, 230), read_only=True)

# Sub-view where the specified bounding box is NOT completely in the bounding box of the MagView.
# This still works because `read_only=True`.
sub_view2 = mag1.get_view(offset=(50, 60, 70), size=(999, 120, 230), read_only=True)
#   def get_bounding_boxes_on_disk( self ) -> Generator[Tuple[Tuple[int, int, int], Tuple[int, int, int]], NoneType, NoneType]:

Returns a bounding box for each file on disk. A bounding box is represented as a tuple of the offset and the size.

This differs from the bounding box in the properties in two ways:

  • the bounding box in the properties is always specified in mag 1
  • the bounding box in the properties is an "overall" bounding box, which abstracts from the files on disk
#   def compress( self, target_path: Union[str, pathlib.Path, NoneType] = None, args: Union[argparse.Namespace, 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.

Back to top