caput.containers#
A high-level in-memory data container format for caput.pipeline.
Containers are built on top of memdata’s MemDiskGroup and
provide a structured way to hold multi-dimensional data arrays. A basic interface is
provided through Container, while ContainerPrototype and
TableSpec act as base classes to define new containers based on named
axis and dataset specifications.
Examples
Containers are subclasses of ContainerPrototype. New containers are defined by
specifying the axes and datasets in the subclass:
>>> from caput.containers import ContainerPrototype
>>> import numpy as np
>>>
>>> class MyContainer(ContainerPrototype):
... _axes = (
... "time",
... "freq",
... )
... _dataset_spec = {
... "data": {
... "axes": [
... "time",
... "freq",
... ],
... "dtype": np.float32,
... "initialise": True,
... "compression": None,
... "distributed": False,
... },
... }
When a container is instantiated, the datasets defined in _dataset_spec
are created with the specified properties. The axes define the dimensions of the datasets,
and must be provided in the constructor, either by specifying the index_map directly
or by copying from another container.
>>> sample1 = MyContainer(time=100, freq=256)
>>> sample2 = MyContainer(copy_from=sample1)
>>> assert np.array_equal(sample1["data"][:], sample2["data"][:])
>>> assert np.array_equal(sample1.index_map["freq"][:], sample2.index_map["freq"][:])
Container Specification#
Axes#
A container must specify a set of named axes that define the dimensions of its
datasets. Each axis must be associated with a corresponding entry in the index_map
dataset. Axes are specified via the _axes class attribute, which is a list
of strings, and are inherited from parent classes.
Dataset Spec#
Each container must define a _dataset_spec class attribute, which is a dictionary
mapping dataset names to their specifications. Each specification is itself a dictionary
that defines properties such as axes, data type, and compression options. Dataset specs
are not inherited from parent classes; each container must define its own complete spec.
More information on dataset specifications can be found in ContainerPrototype.
Submodules#
Classes#
Basic high level data container. |
|
A prototype class used to design containers using axis and dataset specifications. |
|
A base class for containers with generic data/weight datasets. |
|
A simple container with a frequency axis. |
|
A base class for containers holding tables of data. |
Functions#
|
Copy datasets while filtering a given axis. |
|
Create an empty container with the same properties as cont. |