Groups

class exdir.core.Group(root_directory, parent_path, object_name, file)[source]

Bases: exdir.core.exdir_object.Object

Container of other groups and datasets.

create_dataset(name, shape=None, dtype=None, data=None, fillvalue=None)[source]

Create a dataset. This will create a folder on the filesystem with the given name, an exdir.yaml file that identifies the folder as an Exdir Dataset, and a data.npy file that contains the data.

Parameters
  • name (str) – Name of the dataset to be created.

  • shape (tuple, semi-optional) – Shape of the dataset to be created. Must be set together with dtype. Cannot be set together with data, but must be set if data is not set.

  • dtype (numpy.dtype) – Data type of the dataset to be created. Must be set together with shape. Cannot be set together with data, but must be set if data is not set.

  • data (scalar, list, numpy.array or plugin-supported type, semi-optional) – Data to be inserted in the created dataset. Cannot be set together with dtype or shape, but must be set if dtype and shape are not set.

  • fillvalue (scalar) – Used to create a dataset with the given shape and type with the initial value of fillvalue.

Returns

Return type

The newly created Dataset.

Raises

FileExistsError – If an object with the same name already exists.

See also

require_dataset

create_group(name)[source]

Create a group. This will create a folder on the filesystem with the given name and an exdir.yaml file that identifies the folder as a group. A group can contain multiple groups and datasets.

Parameters

name (str) – Name of the subgroup. Must follow the naming convention of the parent Exdir File.

Raises

FileExistsError – If an object with the same name already exists.

Returns

Return type

The newly created Group.

See also

require_group

get(key)[source]

Get an object in the group. :Parameters: key (str) – The key of the desired object

Returns

Return type

Value or None if object does not exist.

items()[source]
Returns

A view of the keys and objects in the group.

Return type

ItemsView

keys()[source]
Returns

A view of the names of the objects in the group.

Return type

KeysView

require_dataset(name, shape=None, dtype=None, exact=False, data=None, fillvalue=None)[source]

Open an existing dataset or create it if it does not exist.

Parameters
  • name (str) – Name of the dataset. Must follow naming convention of parent Exdir File.

  • shape (np.array, semi-optional) – Shape of the dataset. Must be set together with dtype. Cannot be set together with data, but must be set if data is not set. Will be used to verify that an existing dataset has the same shape or to create a new dataset of the given shape. See also exact.

  • dtype (np.dtype, semi-optional) – NumPy datatype of the dataset. Must be set together with shape. Cannot be set together with data, but must be set if data is not set. Will be used to verify that an existing dataset has the same or a convertible dtype or to create a new dataset with the given dtype. See also exact.

  • exact (bool, optional) – Only used if the dataset already exists. If exact is False, the shape must match the existing dataset and the data type must be convertible between the existing and requested data type. If exact is True, the shape and dtype must match exactly. The default is False. See also shape, dtype and data.

  • data (list, np.array, semi-optional) – The data that will be used to create the dataset if it does not already exist. The shape and dtype of data will be compared to the existing dataset if it already exists. See shape, dtype and exact.

  • fillvalue (scalar) – Used to create a dataset with the given shape and type with the initial value of fillvalue.

require_group(name)[source]

Open an existing subgroup or create one if it does not exist. This might create a new subfolder on the file system.

Parameters

name (str) – Name of the subgroup. Must follow the naming convention of the parent Exdir File.

Returns

Return type

The existing or created group.

See also

create_group

values()[source]
Returns

A view of the objects in the group.

Return type

ValuesView