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 MagView
has 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).
Do not use this constructor manually. Instead use webknossos.dataset.layer.Layer.add_mag()
.
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.
Writing data to a segmentation layer manually does not automatically update the largest_segment_id. To set
the largest segment id properly run the refresh_largest_segment_id
method on your layer or set the
largest_segment_id
property manually..
Example:
ds = Dataset(DS_PATH, voxel_size=(1, 1, 1))
segmentation_layer = cast(
SegmentationLayer,
ds.add_layer("segmentation", SEGMENTATION_CATEGORY),
)
mag = segmentation_layer.add_mag(Mag(1))
mag.write(data=MY_NP_ARRAY)
segmentation_layer.refresh_largest_segment_id()
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.
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
andsize
, both in Mag(1)absolute_offset
andsize
, both in Mag(1)relative_bounding_box
in Mag(1)absolute_bounding_box
in Mag(1)- ⚠️ deprecated:
offset
andsize
, both in the current Mag.offset
used to be relative forView
and absolute forMagView
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(),
)
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
andsize
, both in Mag(1)absolute_offset
andsize
, both in Mag(1)- ⚠️ deprecated:
offset
andsize
, both in the current Mag.offset
used to be relative forView
and absolute forMagView
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)
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.
Yields a view for each file on disk, which can be used for efficient parallelization.
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
.