Skip to content

webknossos.dataset.layer

#   class Layer:

A Layer consists of multiple webknossos.dataset.mag_view.MagViews, which store the same data in different magnifications.

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

#   path: pathlib.Path
#   name: str
#   dtype_per_channel: numpy.dtype
#   num_channels: int
#   default_view_configuration: Union[webknossos.dataset.properties.LayerViewConfiguration, NoneType]

Getter for dictionary containing all mags.

#   def get_mag( self, mag: Union[int, str, list, tuple, numpy.ndarray, webknossos.geometry.mag.Mag] ) -> webknossos.dataset.mag_view.MagView:

Returns the MagView called mag of this layer. The return type is webknossos.dataset.mag_view.MagView.

This function raises an IndexError if the specified mag does not exist.

#   def get_best_mag(self) -> webknossos.dataset.mag_view.MagView:
#   def add_mag( self, mag: Union[int, str, list, tuple, numpy.ndarray, webknossos.geometry.mag.Mag], block_len: int = 32, file_len: int = 32, compress: bool = False ) -> webknossos.dataset.mag_view.MagView:

Creates a new mag called and adds it to the layer. The parameter block_len, file_len and compress can be specified to adjust how the data is stored on disk. 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. Alternatively, you can call mag.compress() after all the data was written

The return type is webknossos.dataset.mag_view.MagView.

Raises an IndexError if the specified mag already exists.

#   def add_mag_for_existing_files( self, mag: Union[int, str, list, tuple, numpy.ndarray, webknossos.geometry.mag.Mag] ) -> webknossos.dataset.mag_view.MagView:

Creates a new mag based on already existing files.

Raises an IndexError if the specified mag does not exists.

#   def get_or_add_mag( self, mag: Union[int, str, list, tuple, numpy.ndarray, webknossos.geometry.mag.Mag], block_len: int = 32, file_len: int = 32, compress: bool = False ) -> webknossos.dataset.mag_view.MagView:

Creates a new mag called and adds it to the dataset, in case it did not exist before. Then, returns the mag.

See add_mag for more information.

#   def delete_mag( self, mag: Union[int, str, list, tuple, numpy.ndarray, webknossos.geometry.mag.Mag] ) -> None:

Deletes the MagView from the datasource-properties.json and the data from disk.

This function raises an IndexError if the specified mag does not exist.

#   def add_copy_mag( self, foreign_mag_view_or_path: Union[os.PathLike, str, webknossos.dataset.mag_view.MagView], extend_layer_bounding_box: bool = True ) -> webknossos.dataset.mag_view.MagView:

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

#   def downsample( self, from_mag: Union[webknossos.geometry.mag.Mag, NoneType] = None, max_mag: Union[webknossos.geometry.mag.Mag, NoneType] = None, interpolation_mode: str = 'default', compress: bool = True, sampling_mode: str = 'anisotropic', buffer_edge_len: Union[int, NoneType] = None, force_sampling_scheme: bool = False, args: Union[argparse.Namespace, NoneType] = None ) -> None:

Downsamples the data starting from from_mag until a magnification is >= max(max_mag). There are three different sampling_modes:

  • 'anisotropic' - The next magnification is chosen so that the width, height and depth of a downsampled voxel assimilate. For example, if the z resolution is worse than the x/y resolution, z won't be downsampled in the first downsampling step(s). As a basis for this method, the scale from the datasource-properties.json is used.
  • 'isotropic' - Each dimension is downsampled equally.
  • 'constant_z' - The x and y dimensions are downsampled equally, but the z dimension remains the same.

See downsample_mag for more information.

Example:

from webknossos.dataset.downsampling_utils import SamplingModes

# ...
# let 'layer' be a `Layer` with only `Mag(1)`
assert "1" in self.mags.keys()

layer.downsample(
    max_mag=Mag(4),
    sampling_mode=SamplingModes.ISOTROPIC
)

assert "2" in self.mags.keys()
assert "4" in self.mags.keys()
#   def downsample_mag( self, from_mag: webknossos.geometry.mag.Mag, target_mag: webknossos.geometry.mag.Mag, interpolation_mode: str = 'default', compress: bool = True, buffer_edge_len: Union[int, NoneType] = None, args: Union[argparse.Namespace, NoneType] = None, allow_overwrite: bool = False ) -> None:

Performs a single downsampling step from from_mag to target_mag.

The supported interpolation_modes are:

  • "median"
  • "mode"
  • "nearest"
  • "bilinear"
  • "bicubic"

The args can contain information to distribute the computation. If allow_overwrite is True, an existing Mag may be overwritten.

#   def redownsample( self, interpolation_mode: str = 'default', compress: bool = True, buffer_edge_len: Union[int, NoneType] = None, args: Union[argparse.Namespace, NoneType] = None ) -> None:

Use this method to recompute downsampled magnifications after mutating data in the base magnification.

#   def downsample_mag_list( self, from_mag: webknossos.geometry.mag.Mag, target_mags: List[webknossos.geometry.mag.Mag], interpolation_mode: str = 'default', compress: bool = True, buffer_edge_len: Union[int, NoneType] = None, args: Union[argparse.Namespace, NoneType] = None, allow_overwrite: bool = False ) -> None:

Downsamples the data starting at from_mag to each magnification in target_mags iteratively.

See downsample_mag for more information.

#   def upsample( self, from_mag: webknossos.geometry.mag.Mag, min_mag: Union[webknossos.geometry.mag.Mag, NoneType], compress: bool, sampling_mode: str = 'anisotropic', buffer_edge_len: Union[int, NoneType] = None, args: Union[argparse.Namespace, NoneType] = None ) -> None:

Upsamples the data starting from from_mag as long as the magnification is >= min_mag. There are three different sampling_modes:

  • 'anisotropic' - The next magnification is chosen so that the width, height and depth of a downsampled voxel assimilate. For example, if the z resolution is worse than the x/y resolution, z won't be downsampled in the first downsampling step(s). As a basis for this method, the scale from the datasource-properties.json is used.
  • 'isotropic' - Each dimension is downsampled equally.
  • 'constant_z' - The x and y dimensions are downsampled equally, but the z dimension remains the same.
#   category: Literal['color', 'segmentation']
#   dtype_per_layer: str
#   class SegmentationLayer(Layer):

A Layer consists of multiple webknossos.dataset.mag_view.MagViews, which store the same data in different magnifications.

#   largest_segment_id: int
#   category: Literal['color', 'segmentation']
Back to top