webknossos.dataset.dataset
A dataset is the entry point of the Dataset API. An existing dataset on disk can be opened or new datasets can be created.
A Dataset
stores the data in .wkw
files on disk.
Examples
Creating Datasets
from webknossos.dataset.dataset import Dataset
dataset = Dataset.create(<path_to_new_dataset>, scale=(1, 1, 1))
# Adds a new layer
layer = dataset.add_layer(
layer_name="color",
category=LayerCategories.COLOR_TYPE,
dtype_per_channel="uint8",
num_channels=3
)
# Adds an existing layer from a different dataset
sym_layer = dataset.add_symlink_layer(<foreign_layer_path>)
Opening Datasets
from webknossos.dataset.dataset import Dataset
dataset = Dataset(<path_to_dataset>)
# Assuming that the dataset has a layer called 'color'
layer = dataset.get_layer("color")
Copying Datasets
from webknossos.dataset.dataset import Dataset
dataset = Dataset(<path_to_dataset>)
# Copying the dataset with different block_len and file_len
copy_of_dataset = dataset.copy_dataset(
<path_to_new_dataset>,
block_len=8,
file_len=8
)
Functions
To open an existing dataset on disk, simply call the constructor of Dataset
.
This requires that the datasource-properties.json
exists. Based on the datasource-properties.json
,
a dataset object is constructed. Only layers and magnifications that are listed in the properties are loaded
(even though there might exists more layer or magnifications on disk).
The dataset_path
refers to the top level directory of the dataset (excluding layer or magnification names).
Location of the dataset
Getter for dictionary containing all layers.
Returns the layer called layer_name
of this dataset. The return type is webknossos.dataset.layer.Layer
.
This function raises an IndexError
if the specified layer_name
does not exist.
Creates a new layer called layer_name
and adds it to the dataset.
The dtype can either be specified per layer or per channel.
If neither of them are specified, uint8
per channel is used as default.
When creating a "Segmentation Layer" (category="segmentation"
),
the parameter largest_segment_id
also has to be specified.
Creates the folder layer_name
in the directory of self.path
.
The return type is webknossos.dataset.layer.Layer
.
This function raises an IndexError
if the specified layer_name
already exists.
Creates a new layer called layer_name
and adds it to the dataset, in case it did not exist before.
Then, returns the layer.
For more information see add_layer
.
Returns the only segmentation layer.
Fails with a IndexError if there are multiple segmentation layers or none.
Returns the only color layer.
Fails with a RuntimeError if there are multiple color layers or none.
Deletes the layer from the datasource-properties.json
and the data from disk.
Creates a symlink to the data at foreign_layer
which belongs to another dataset.
The relevant information from the datasource-properties.json
of the other dataset is copied to this dataset.
Note: If the other dataset modifies its bounding box afterwards, the change does not affect this properties
(or vice versa).
If make_relative is True, the symlink is made relative to the current dataset path.
If new_layer_name is None, the name of the foreign layer is used.
Copies the data at foreign_layer
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.
If new_layer_name is None, the name of the foreign layer is used.
Creates a new dataset at new_dataset_path
and copies the data from the current dataset to empty_target_ds
.
If not specified otherwise, the scale
, block_len
, file_len
and block_type
of the current dataset are also used for the new dataset.
Creates a new dataset and the associated datasource-properties.json
.
Creates a new Dataset
, in case it did not exist before, and then returns it.
The datasource-properties.json
is used to check if the dataset already exist.