API Documentation for Data¶
TODO write something about the data model
File¶
A File represents a specific data source of a NIX back-end for example an NIX HDF5 file. All entities of the nix data model (except the Value entity) must exist in the context of an open File object. Therefore NIX entities can’t be initialized via their constructors but only through the factory methods of their respective parent entity.
Working with files¶
1 2 3 | file = File.open("test.h5", FileMode.ReadWrite)
# do some work
file.close()
|
File API¶
-
class
nixio.
File
(h5file, compression)¶ -
blocks
¶ A property containing all blocks of a file. Blocks can be obtained by their id or their index. Blocks can be deleted from the list, when a block is deleted all its content (data arrays, tags and sources) will be also deleted from the file. Adding new Block is done via the create_block method of File. This is a read-only attribute.
Type: ProxyList of Block entities.
-
close
()¶ Closes an open file.
-
create_block
(name, type_)¶ Create a new block inside the file.
Parameters: Returns: The newly created block.
Return type:
-
create_section
(name, type_)¶ Create a new metadata section inside the file.
Parameters: Returns: The newly created section.
Return type:
-
created_at
¶ The creation time of the file. This is a read-only property. Use force_created_at in order to change the creation time.
Return type: int
-
find_sections
(filtr=<function FileMixin.<lambda>>, limit=None)¶ Get all sections and their child sections recursively.
This method traverses the trees of all sections. The traversal is accomplished via breadth first and can be limited in depth. On each node or section a filter is applied. If the filter returns true the respective section will be added to the result list. By default a filter is used that accepts all sections.
Parameters: - filtr (function) – A filter function
- limit (int) – The maximum depth of traversal
Returns: A list containing the matching sections.
Return type: list of Section
-
flush
()¶
-
force_created_at
(t=None)¶ Sets the creation time created_at to the given time (default: current time).
Parameters: t (int) – The time to set
-
force_updated_at
(t=None)¶ Sets the update time updated_at to the given time. (default: current time)
Parameters: t (int) – The time to set (default: now)
-
format
¶ The format of the file. This read only property should always have the value ‘nix’.
Type: str
-
is_open
()¶ Checks whether a file is open or closed.
Returns: True if the file is open, False otherwise. Return type: bool
-
classmethod
open
(path, mode='a', backend=None, compression='Auto')¶ Open a NIX file, or create it if it does not exist.
Parameters: - path – Path to file
- mode – FileMode ReadOnly, ReadWrite, or Overwrite. (default: ReadWrite)
- backend – Either “hdf5” or “h5py”. Defaults to “hdf5” if available, or “h5py” otherwise
Returns: nixio.File object
-
sections
¶ A property containing all root sections of a file. Specific root sections can be obtained by their id or their index. Sections can be deleted from this list. Notice: when a section is deleted all its child section and properties will be removed too. Adding a new Section is done via the crate_section method of File. This is a read-only property.
Type: ProxyList of Section entities.
-
updated_at
¶ The time of the last update of the file. This is a read-only property. Use force_updated_at in order to change the update time.
Return type: int
-
validate
()¶ Checks if the File is a valid NIX file. This method is only available when using the “hdf5” backend.
Returns: Result object
-
version
¶ The file format version.
Type: tuple
-
Block¶
The Block entity is a top-level, summarizing element that allows to group the other data entities belonging for example to the same recording session. All data entities such as Source, DataArray, Tag and MultiTag have to be associated with one Block.
Create a new Block¶
A block can only be created on an existing file object. Do not use the blocks constructors for this purpose.
1 | block = file.create_block("session one", "recordingsession");
|
Working with blocks¶
After a block was created it can be used to create further entities. See the documentation of Source, DataArray, Tag and MultiTag for more information. The next example shows how some properties of a block can be accessed.
1 2 3 4 5 6 7 8 9 10 11 | block = file.blocks[some_id]
# add metadata to a block
section = file.sections[sec_id]
block.metadata = section
# get associated metadata from a block
block.metadata
# remove associated metadata from a block
block.metadata = None
|
Deleting a block¶
When a block is deleted from a file all contained data e.g. sources, data arrays and tags will be removed too.
1 | del file.blocks[some_id]
|
Block API¶
-
class
nixio.pycore.
Block
(nixparent, h5group, compression='Auto')¶ -
create_data_array
(name, array_type, dtype=None, shape=None, data=None, compression='Auto')¶ Create a new data array for this block. Either
shape
ordata
must be given. If both are given their shape must agree. Ifdtype
is not specified it will default to 64-bit floating points.Parameters: - name (str) – The name of the data array to create.
- array_type (str) – The type of the data array.
- dtype (
numpy.dtype
) – Which data-type to use for storage - shape (tuple of int or long) – Layout (dimensionality and extent)
- data (array-like data) – Data to write after storage has been created
- compression (
Compression
) – En-/disable dataset compression.
Returns: The newly created data array.
Return type: DataArray
-
create_group
(name, type_)¶ Create a new group on this block.
Parameters: Returns: The newly created group.
Return type:
-
create_multi_tag
(name, type_, positions)¶ Create a new multi tag for this block.
Parameters: Returns: The newly created tag.
Return type:
-
create_source
(name, type_)¶ Create a new source on this block.
Parameters: Returns: The newly created source.
Return type:
-
create_tag
(name, type_, position)¶ Create a new tag for this block.
Parameters: Returns: The newly created tag.
Return type:
-
created_at
¶ The creation time of the entity. This is a read-only property. Use force_created_at in order to change the creation time.
Return type: int
-
data_arrays
¶ A property containing all data arrays of a block. DataArray entities can be obtained via their index or by their id. Data arrays can be deleted from the list. Adding a data array is done using the Blocks create_data_array method. This is a read only attribute.
Type: ProxyList of DataArray entities.
-
definition
¶ The definition of the entity. The definition can contain a textual description of the entity. This is an optional read-write property, and can be None if no definition is available.
Type: str
-
find_sources
(filtr=<function BlockMixin.<lambda>>, limit=None)¶ Get all sources in this block recursively.
This method traverses the tree of all sources in the block. The traversal is accomplished via breadth first and can be limited in depth. On each node or source a filter is applied. If the filter returns true the respective source will be added to the result list. By default a filter is used that accepts all sources.
Parameters: - filtr (function) – A filter function
- limit (int) – The maximum depth of traversal
Returns: A list containing the matching sources.
Return type: list of Source
-
force_created_at
(t=None)¶ Sets the creation time created_at to the given time (default: current time).
Parameters: t (int) – The time to set.
-
force_updated_at
(t=None)¶ Sets the update time updated_at to the given time. (default: current time)
Parameters: t (int) – The time to set.
-
groups
¶ A property containing all groups of a block. Group entities can be obtained via their index or by their id. Groups can be deleted from the list. Adding a Group is done using the Blocks create_group method. This is a read only attribute.
Type: ProxyList of Group entities.
-
id
¶ A property providing the ID of the Entity. The id is generated automatically, therefore the property is read-only.
Return type: str
-
metadata
¶ Associated metadata of the entity. Sections attached to the entity via this attribute can provide additional annotations. This is an optional read-write property, and can be None if no metadata is available.
Type: Section
A property containing all multi tags of a block. MultiTag entities can be obtained via their index or by their id. Tags can be deleted from the list. Adding tags is done using the Blocks create_multi_tag method. This is a read only attribute.
Type: ProxyList of MultiTag entities.
-
name
¶ The name of an entity. The name serves as a human readable identifier. This is a read-only property; entities cannot be renamed.
Type: str
-
sources
¶ A property containing all sources of a block. Sources can be obtained via their index or by their id. Sources can be deleted from the list. Adding sources is done using the Blocks create_source method. This is a read only attribute.
Type: ProxyList of Source entities.
A property containing all tags of a block. Tag entities can be obtained via their index or by their id. Tags can be deleted from the list. Adding tags is done using the Blocks create_tag method. This is a read only attribute.
Type: ProxyList of Tag entities.
-
DataArray¶
The DataArray is the core entity of the NIX data model, its purpose is to store arbitrary n-dimensional data. In addition to the common fields id, name, type, and definition the DataArray stores sufficient information to understand the physical nature of the stored data.
A guiding principle of the data model is provides enough information to create a plot of the stored data. In order to do so, the DataArray defines a property dataType which provides the physical type of the stored data (for example 16 bit integer or double precision IEEE floatingpoint number). The property unit specifies the SI unit of the values stored in the DataArray whereas the label defines what is given in this units. Together, both specify what corresponds to the the y-axis of a plot.
In some cases it is much more efficient or convenient to store data not as floating point numbers but rather as (16 bit) integer values as, for example read from a data acquisition board. In order to convert such data to the correct values, we follow the approach taken by the comedi data-acquisition library (http://www.comedi.org) and provide polynomCoefficients and an expansionOrigin.
Create and delete a DataArray¶
A DataArray can only be created at an existing block. Do not use the DataArrays constructors for this purpose.
1 2 | data_array = block.crate_data_array("matrix", "data");
del block.data_arrays[data_array]
|
DataArray API¶
-
class
nixio.pycore.
DataArray
(nixparent, h5group)¶ -
append
(data, axis=0)¶ Append
data
to the DataSet along theaxis
specified.Parameters: data – The data to append. Shape must agree except for the specified axis :param axis: Along which axis to append the data to
-
append_alias_range_dimension
()¶ Append a new RangeDimension that uses the data stored in this DataArray as ticks. This works only(!) if the DataArray is 1-D and the stored data is numeric. A ValueError will be raised otherwise.
Returns: The created dimension descriptor. Return type: RangeDimension
-
append_range_dimension
(ticks)¶ Append a new RangeDimension to the list of existing dimension descriptors.
Parameters: ticks (list of float) – The ticks of the RangeDimension to create. Returns: The newly created RangeDimension. Return type: RangeDimension
-
append_sampled_dimension
(sampling_interval)¶ Append a new SampledDimension to the list of existing dimension descriptors.
Parameters: sampling_interval (float) – The sampling interval of the SetDimension to create. Returns: The newly created SampledDimension. Return type: SampledDimension
-
append_set_dimension
()¶ Append a new SetDimension to the list of existing dimension descriptors.
Returns: The newly created SetDimension. Return type: SetDimension
-
created_at
¶ The creation time of the entity. This is a read-only property. Use force_created_at in order to change the creation time.
Return type: int
-
data
¶ DEPRECATED DO NOT USE ANYMORE! Returns self
Type: DataArray
-
data_extent
¶ The size of the data.
Type: set of int
-
data_type
¶ The data type of the data stored in the DataArray. This is a read only property.
Type: DataType
-
definition
¶ The definition of the entity. The definition can contain a textual description of the entity. This is an optional read-write property, and can be None if no definition is available.
Type: str
-
delete_dimensions
()¶ Delete all the dimension descriptors for this DataArray.
-
dimensions
¶ A property containing all dimensions of a DataArray. Dimensions can be obtained via their index. Adding dimensions is done using the respective append methods for dimension descriptors. This is a read only attribute.
Type: ProxyList of dimension descriptors.
-
dtype
¶ The data type of the data stored in the DataArray. This is a read only property.
Returns: DataType
-
expansion_origin
¶ The expansion origin of the calibration polynomial. This is a read-write property and can be set to None. The default value is 0.
Type: float
-
force_created_at
(t=None)¶ Sets the creation time created_at to the given time (default: current time).
Parameters: t (int) – The time to set.
-
force_updated_at
(t=None)¶ Sets the update time updated_at to the given time. (default: current time)
Parameters: t (int) – The time to set.
-
get_slice
(positions, extents=None, mode=<DataSliceMode.Index: 1>)¶
-
id
¶ A property providing the ID of the Entity. The id is generated automatically, therefore the property is read-only.
Return type: str
-
label
¶ The label of the DataArray. The label corresponds to the label of the x-axis of a plot. This is a read-write property and can be set to None.
Type: str
-
metadata
¶ Associated metadata of the entity. Sections attached to the entity via this attribute can provide additional annotations. This is an optional read-write property, and can be None if no metadata is available.
Type: Section
-
name
¶ The name of an entity. The name serves as a human readable identifier. This is a read-only property; entities cannot be renamed.
Type: str
-
polynom_coefficients
¶ The polynomial coefficients for the calibration. By default this is set to a {0.0, 1.0} for a linear calibration with zero offset. This is a read-write property and can be set to None
Type: list of float
-
read_direct
(data)¶ Directly read all data stored in the
DataSet
intodata
. The supplied data must be anumpy.ndarray
that matches the DataSet’s shape, must have C-style contiguous memory layout and must be writeable (seenumpy.ndarray.flags
andndarray
for more information).Parameters: data ( numpy.ndarray
) – The array where data is being read into
-
shape
¶ Type: tuple of data array dimensions.
-
sources
¶ Getter for sources.
-
type
¶ The type of the entity. The type is used in order to add semantic meaning to the entity. This is a read-write property, but it can’t be set to None.
Type: str
-
unit
¶ The unit of the values stored in the DataArray. This is a read-write property and can be set to None.
Type: str
-
updated_at
¶ The time of the last update of the entity. This is a read-only property. Use force_updated_at in order to change the update time.
Return type: int
-
write_direct
(data)¶ Directly write all of
data
to theDataSet
. The supplied data must be anumpy.ndarray
that matches the DataSet’s shape and must have C-style contiguous memory layout (seenumpy.ndarray.flags
andndarray
for more information).Parameters: data ( numpy.ndarray
) – The array which contents is being written
-
DataSet¶
The DataSet object is used for data input/output to the underlying storage.
-
class
nixio.pycore.data_array.
DataSet
¶ -
append
(data, axis=0)¶ Append
data
to the DataSet along theaxis
specified.Parameters: data – The data to append. Shape must agree except for the specified axis :param axis: Along which axis to append the data to
-
data_extent
¶ The size of the data.
Type: set of int
-
data_type
¶ The data type of the data stored in the DataArray. This is a read only property.
Type: DataType
-
dtype
¶ Type: numpy.dtype
object holding type infromation about the data stored in the DataSet.
-
read_direct
(data)¶ Directly read all data stored in the
DataSet
intodata
. The supplied data must be anumpy.ndarray
that matches the DataSet’s shape, must have C-style contiguous memory layout and must be writeable (seenumpy.ndarray.flags
andndarray
for more information).Parameters: data ( numpy.ndarray
) – The array where data is being read into
-
shape
¶ Type: tuple of data array dimensions.
-
write_direct
(data)¶ Directly write all of
data
to theDataSet
. The supplied data must be anumpy.ndarray
that matches the DataSet’s shape and must have C-style contiguous memory layout (seenumpy.ndarray.flags
andndarray
for more information).Parameters: data ( numpy.ndarray
) – The array which contents is being written
-
Tags¶
Besides the DataArray the tag entities can be considered as the other core entities of the data model. They are meant to attach annotations directly to the data and to establish meaningful links between different kinds of stored data. Most importantly tags allow the definition of points or regions of interest in data that is stored in other DataArray entities. The data array entities the tag applies to are defined by its property references.
Further the referenced data is defined by an origin vector called position and an optional extent vector that defines its size. Therefore position and extent of a tag, together with the references field defines a group of points or regions of interest collected from a subset of all available DataArray entities.
Further tags have a field called features which makes it possible to associate other data with the tag. Semantically a feature of a tag is some additional data that contains additional information about the points of hyperslabs defined by the tag. This could be for example data that represents a stimulus (e.g. an image or a signal) that was applied in a certain interval during the recording.
Tag API¶
-
class
nixio.pycore.
Tag
(nixparent, h5group)¶ -
create_feature
(data, link_type)¶ Create a new feature.
Parameters: - data (DataArray) – The data array of this feature.
- link_type (LinkType) – The link type of this feature.
Returns: The created feature object.
Return type: Feature
-
created_at
¶ The creation time of the entity. This is a read-only property. Use force_created_at in order to change the creation time.
Return type: int
-
definition
¶ The definition of the entity. The definition can contain a textual description of the entity. This is an optional read-write property, and can be None if no definition is available.
Type: str
-
extent
¶ The extent defined by the tag. This is an optional read-write property and may be set to None.
Type: list of float
-
features
¶ A property containing all features of the tag. Features can be obtained via their index or their id. Features can be deleted from the list. Adding new features to the tag is done using the create_feature method. This is a read only attribute.
Type: ProxyList of Feature.
-
force_created_at
(t=None)¶ Sets the creation time created_at to the given time (default: current time).
Parameters: t (int) – The time to set.
-
force_updated_at
(t=None)¶ Sets the update time updated_at to the given time. (default: current time)
Parameters: t (int) – The time to set.
-
id
¶ A property providing the ID of the Entity. The id is generated automatically, therefore the property is read-only.
Return type: str
-
metadata
¶ Associated metadata of the entity. Sections attached to the entity via this attribute can provide additional annotations. This is an optional read-write property, and can be None if no metadata is available.
Type: Section
-
name
¶ The name of an entity. The name serves as a human readable identifier. This is a read-only property; entities cannot be renamed.
Type: str
-
position
¶ The position defined by the tag. This is a read-write property.
Type: list of float
-
references
¶ A property containing all data arrays referenced by the tag. Referenced data arrays can be obtained by index or their id. References can be removed from the list, removing a referenced DataArray will not remove it from the file. New references can be added using the append method of the list. This is a read only attribute.
Type: RefProxyList of DataArray
-
retrieve_data
(refidx)¶
-
retrieve_feature_data
(featidx)¶
-
sources
¶ Getter for sources.
-
type
¶ The type of the entity. The type is used in order to add semantic meaning to the entity. This is a read-write property, but it can’t be set to None.
Type: str
-
units
¶ Property containing the units of the tag. The tag must provide a unit for each dimension of the position or extent vector. This is a read-write property.
Type: list of str
-
MultiTag API¶
-
class
nixio.pycore.
MultiTag
(nixparent, h5group)¶ -
create_feature
(data, link_type)¶ Create a new feature.
Parameters: - data (DataArray) – The data array of this feature.
- link_type (LinkType) – The link type of this feature.
Returns: The created feature object.
Return type: Feature
-
created_at
¶ The creation time of the entity. This is a read-only property. Use force_created_at in order to change the creation time.
Return type: int
-
definition
¶ The definition of the entity. The definition can contain a textual description of the entity. This is an optional read-write property, and can be None if no definition is available.
Type: str
-
extents
¶ The extents defined by the tag. This is an optional read-write property and may be set to None.
Type: DataArray or None
-
features
¶ A property containing all features of the tag. Features can be obtained via their index or their id. Features can be deleted from the list. Adding new features to the tag is done using the create_feature method. This is a read only attribute.
Type: ProxyList of Feature.
-
force_created_at
(t=None)¶ Sets the creation time created_at to the given time (default: current time).
Parameters: t (int) – The time to set.
-
force_updated_at
(t=None)¶ Sets the update time updated_at to the given time. (default: current time)
Parameters: t (int) – The time to set.
-
id
¶ A property providing the ID of the Entity. The id is generated automatically, therefore the property is read-only.
Return type: str
-
metadata
¶ Associated metadata of the entity. Sections attached to the entity via this attribute can provide additional annotations. This is an optional read-write property, and can be None if no metadata is available.
Type: Section
-
name
¶ The name of an entity. The name serves as a human readable identifier. This is a read-only property; entities cannot be renamed.
Type: str
-
references
¶ A property containing all data arrays referenced by the tag. Referenced data arrays can be obtained by index or their id. References can be removed from the list, removing a referenced DataArray will not remove it from the file. New references can be added using the append method of the list. This is a read only attribute.
Type: RefProxyList of DataArray
-
retrieve_data
(posidx, refidx)¶
-
retrieve_feature_data
(posidx, featidx)¶
-
sources
¶ Getter for sources.
-
type
¶ The type of the entity. The type is used in order to add semantic meaning to the entity. This is a read-write property, but it can’t be set to None.
Type: str
-
units
¶ Property containing the units of the tag. The tag must provide a unit for each dimension of the position or extent vector. This is a read-write property.
Type: list of str
-
Source¶
-
class
nixio.pycore.
Source
(nixparent, h5group)¶ -
create_source
(name, type_)¶ Create a new source as a child of the current Source.
Parameters: Returns: The newly created source.
Return type:
-
created_at
¶ The creation time of the entity. This is a read-only property. Use force_created_at in order to change the creation time.
Return type: int
-
definition
¶ The definition of the entity. The definition can contain a textual description of the entity. This is an optional read-write property, and can be None if no definition is available.
Type: str
-
find_sources
(filtr=<function SourceMixin.<lambda>>, limit=None)¶ Get all child sources of this source recursively.
This method traverses the tree of all sources. The traversal is accomplished via breadth first and can be limited in depth. On each node or source a filter is applied. If the filter returns true the respective source will be added to the result list. By default a filter is used that accepts all sources.
Parameters: - filtr (function) – A filter function
- limit (int) – The maximum depth of traversal
Returns: A list containing the matching sources.
Return type: list of Source
-
force_created_at
(t=None)¶ Sets the creation time created_at to the given time (default: current time).
Parameters: t (int) – The time to set.
-
force_updated_at
(t=None)¶ Sets the update time updated_at to the given time. (default: current time)
Parameters: t (int) – The time to set.
-
id
¶ A property providing the ID of the Entity. The id is generated automatically, therefore the property is read-only.
Return type: str
-
metadata
¶ Associated metadata of the entity. Sections attached to the entity via this attribute can provide additional annotations. This is an optional read-write property, and can be None if no metadata is available.
Type: Section
-
name
¶ The name of an entity. The name serves as a human readable identifier. This is a read-only property; entities cannot be renamed.
Type: str
-
referring_data_arrays
¶
-
referring_objects
¶
-
sources
¶ A property containing all sources of a block. Sources can be obtained via their index or by their id. Sources can be deleted from the list. Adding sources is done using the Blocks create_source method. This is a read only attribute.
Type: ProxyList of Source entities.
-
Group¶
Groups establish a simple way of grouping entities that in some way belong together. The Group exists inside a Block and can contain (link) DataArrays, Tags, and MultiTags. As any other nix-entity, the Groups is named, has a type, and a definition property. Additionally, it contains data_arrays, tags, and multi_tags lists. As indicated before, the group does only link the entities. Thus, deleting elements from the lists does not remove them from file, it merely removes the link from the group.
1 2 3 4 5 6 7 8 | data_array = block.crate_data_array("matrix", "data");
tag = block.create_tag("a tag", "event", [0.0, 1.0])
group = block.create_group("things that belong together", "group")
group.tags.append(tag)
group.data_arrays.append(data_array)
del group.data_arrays[data_array]
del group.tags[tag]
|
Group API¶
-
class
nixio.pycore.
Group
(nixparent, h5group)¶ -
created_at
¶ The creation time of the entity. This is a read-only property. Use force_created_at in order to change the creation time.
Return type: int
-
data_arrays
¶ A property containing all data arrays referenced by the group. Referenced data arrays can be obtained by index or their id. References can be removed from the list, removing a referenced DataArray will not remove it from the file. New references can be added using the append method of the list. This is a read only attribute.
Type: DataArrayProxyList of DataArray
-
definition
¶ The definition of the entity. The definition can contain a textual description of the entity. This is an optional read-write property, and can be None if no definition is available.
Type: str
-
force_created_at
(t=None)¶ Sets the creation time created_at to the given time (default: current time).
Parameters: t (int) – The time to set.
-
force_updated_at
(t=None)¶ Sets the update time updated_at to the given time. (default: current time)
Parameters: t (int) – The time to set.
-
id
¶ A property providing the ID of the Entity. The id is generated automatically, therefore the property is read-only.
Return type: str
-
metadata
¶ Associated metadata of the entity. Sections attached to the entity via this attribute can provide additional annotations. This is an optional read-write property, and can be None if no metadata is available.
Type: Section
A property containing all MultiTags referenced by the group. MultiTags can be obtained by index or their id. Tags can be removed from the list, removing a referenced MultiTag will not remove it from the file. New MultiTags can be added using the append method of the list. This is a read only attribute.
Type: MultiTagProxyList of MultiTags
-
name
¶ The name of an entity. The name serves as a human readable identifier. This is a read-only property; entities cannot be renamed.
Type: str
-
sources
¶ Getter for sources.
A property containing all tags referenced by the group. Tags can be obtained by index or their id. Tags can be removed from the list, removing a referenced Tag will not remove it from the file. New Tags can be added using the append method of the list. This is a read only attribute.
Type: TagProxyList of Tags
-