webknossos.dataset.abstract_dataset
¶
AbstractDataset
¶
AbstractDataset(
dataset_properties: DatasetProperties, read_only: bool
)
Bases: Generic[LayerType, SegmentationLayerType]
default_view_configuration
property
writable
¶
default_view_configuration: DatasetViewConfiguration | None
Default view configuration for this dataset in webknossos.
Controls how the dataset is displayed in webknossos when first opened by a user, including position, zoom level, rotation etc.
Returns:
-
DatasetViewConfiguration | None
–DatasetViewConfiguration | None: Current view configuration if set
Examples:
ds.default_view_configuration = DatasetViewConfiguration(
zoom=1.5,
position=(100, 100, 100)
)
layers
property
¶
layers: Mapping[str, LayerType]
Dictionary containing all layers of this dataset.
Returns:
-
Mapping[str, LayerType]
–dict[str, Layer]: Dictionary mapping layer names to Layer objects
Examples:
for layer_name, layer in ds.layers.items():
print(layer_name)
name
property
writable
¶
name: str
Name of this dataset as specified in datasource-properties.json.
Can be modified to rename the dataset. Changes are persisted to the properties file.
Returns:
-
str
(str
) –Current dataset name
Examples:
ds.name = "my_renamed_dataset" # Updates the name in properties file
read_only
property
¶
read_only: bool
Whether this dataset is opened in read-only mode.
When True, operations that would modify the dataset (adding layers, changing properties, etc.) are not allowed and will raise RuntimeError.
Returns:
-
bool
(bool
) –True if dataset is read-only, False otherwise
voxel_size
property
¶
voxel_size: tuple[float, float, float]
Size of each voxel in nanometers along each dimension (x, y, z).
Returns:
-
tuple[float, float, float]
–tuple[float, float, float]: Size of each voxel in nanometers for x,y,z dimensions
Examples:
vx, vy, vz = ds.voxel_size
print(f"X resolution is {vx}nm")
voxel_size_with_unit
property
¶
voxel_size_with_unit: VoxelSize
Size of voxels including unit information.
Size of each voxel along each dimension (x, y, z), including unit specification. The default unit is nanometers.
Returns:
-
VoxelSize
(VoxelSize
) –Object containing voxel sizes and their units
calculate_bounding_box
¶
calculate_bounding_box() -> NDBoundingBox
Calculate the enclosing bounding box of all layers.
Finds the smallest box that contains all data from all layers in the dataset.
Returns:
-
NDBoundingBox
(NDBoundingBox
) –Bounding box containing all layer data
Examples:
bbox = ds.calculate_bounding_box()
print(f"Dataset spans {bbox.size} voxels")
print(f"Dataset starts at {bbox.topleft}")
get_color_layers
¶
get_color_layers() -> list[LayerType]
Get all color layers in the dataset.
Provides access to all layers with category 'color'. Useful when a dataset contains multiple color layers.
Returns:
-
list[LayerType]
–list[Layer]: List of all color layers in order
Examples:
Print all color layer names:
for layer in ds.get_color_layers():
print(layer.name)
Note
If you need only a single color layer, consider using
get_layer()
with the specific layer name instead.
get_layer
¶
get_layer(layer_name: str) -> LayerType
Get a specific layer from this dataset.
Parameters:
-
layer_name
(str
) –Name of the layer to retrieve
Returns:
-
Layer
(LayerType
) –The requested layer object
Raises:
-
IndexError
–If no layer with the given name exists
Examples:
color_layer = ds.get_layer("color")
seg_layer = ds.get_layer("segmentation")
Note
Use layers
property to access all layers at once.
get_segmentation_layer
¶
get_segmentation_layer(
layer_name: str,
) -> SegmentationLayerType
Get a segmentation layer by name.
Parameters:
-
layer_name
(str
) –Name of the layer to get
Returns:
-
SegmentationLayer
(SegmentationLayerType
) –The segmentation layer
get_segmentation_layers
¶
get_segmentation_layers() -> list[SegmentationLayerType]
Get all segmentation layers in the dataset.
Provides access to all layers with category 'segmentation'. Useful when a dataset contains multiple segmentation layers.
Returns:
-
list[SegmentationLayerType]
–list[SegmentationLayer]: List of all segmentation layers in order
Examples:
Print all segmentation layer names:
for layer in ds.get_segmentation_layers():
print(layer.name)
Note
If you need only a single segmentation layer, consider using
get_layer()
with the specific layer name instead.
- Get Help
- Community Forums
- Email Support