Reference#
IO#
Elastica IO Pipelines for data deserialization.
- elastica_pipelines.io.series(*, file_pattern=None, metadata=None, transforms=None)#
Make a Series from pattern or metadata file.
- Parameters:
- Returns:
Series object with temporal system evolution.
- Return type:
Example
>>> from elastica_pipelines.io import series >>> metadata_fn = "tests/io/data/elastica_metadata.h5" >>> for t, snapshot in series(metadata=metadata_fn).iterations(): >>> print("Iteration: {0} at time {1}".format(t.iterate, t.time))
- Raises:
RuntimeError – If none or both pattern and metadata is simultaneously specified.
NotImplementedError – For pattern-based iteration.
- Parameters:
- Return type:
Temporal#
Temporal IO types.
- class elastica_pipelines.io.temporal.Series(node, transforms=None)#
Temporally evolving data-series.
Has the same interface as a dictionary, and hence lookup, items() work.
- Parameters:
node (Node) – Node with series information.
transforms (Callable, Optional) – A function/transform that takes in an array data-structure and returns a transformed version. E.g,
transforms.ToArray
Example
>>> from elastica_pipelines.io import series >>> from elastica_pipelines.io.temporal import Series >>> >>> # ``series`` returns a ``Series`` object >>> metadata_filename = "tests/io/data/elastica_metadata.h5" >>> s : Series = series(metadata=metadata_filename)
>>> s[50] # lookup the data at iteration 50, iterates may not be continuous!
>>> for t in s.keys(): # obtain all iteration values >>> print(t.iterate, t.time, t.dt) >>> print(s[t])
- iterations()#
Obtain temporal iterations.
- temporal_select(indices)#
Obtain temporal evolution for a select subset of systems.
- Parameters:
indices (SystemIndices) – indices (with Traits) for system selection.
- Returns:
SeriesSelectionwith the same interface.- Return type:
Example
>>> from elastica_pipelines.io import series >>> from elastica_pipelines.io.temporal import Series >>> from elastica_pipelines.io import CosseratRodRecordIndex >>> >>> metadata_filename = "tests/io/data/elastica_metadata.h5" >>> s : Series = series(metadata=metadata_filename) >>> >>> # Select Cosserat rod with ID 1 >>> subset = s.temporal_select(CosseratRodRecordIndex(1)) >>> # Select Cosserat rod with list of indices >>> subset = s.temporal_select(CosseratRodRecordIndex([1, 3])) >>> # Select Cosserat rod range with indices >>> subset = s.temporal_select(CosseratRodRecordIndex(slice(1,5,2))) >>> >>> # Subset has same interface as Series, see SeriesSelection >>> for t in subset.keys(): # obtain all iteration values >>> print(t.iterate, t.time, t.dt) >>> print(subset[t])
- class elastica_pipelines.io.temporal.SeriesKey(iterate, time, dt)#
Key for a temporal series.
- class elastica_pipelines.io.temporal.SeriesKeys#
Union of integer and SeriesKey
- class elastica_pipelines.io.temporal.SeriesSelection(parent, indices)#
Temporally evolving data-series restricted to a subset of systems.
- Parameters:
parent (Series) – Series from which the selection is made.
indices (SystemIndices) – Selection of index subsets
Example
>>> from elastica_pipelines.io import series >>> from elastica_pipelines.io.temporal import Series, SeriesSelection >>> from elastica_pipelines.io import CosseratRodRecordIndex as RodIndex >>> >>> metadata_filename = "tests/io/data/elastica_metadata.h5" >>> s : Series = series(metadata=metadata_filename) >>> >>> # Select Cosserat rod with list of indices >>> subset : SeriesSelection = s.temporal_select(RodIndex([1, 4, 9])) >>> >>> # Subset has same interface as Series >>> subset[50] # lookup the data at iteration 50 >>> >>> for t in subset.keys(): # obtain all iteration values for subsets >>> print(t.iterate, t.time, t.dt) >>> print(subset[t])
- iterations()#
Obtain temporal iterations.
- Returns:
Temporal iteration
- Return type:
ItemsView[SeriesKeys, RecordLeafs]
- temporal_select(indices)#
Obtain temporal evolution for a select subset of systems.
- Parameters:
indices (SystemIndices) – indices (with Traits) for system selection.
- Returns:
SeriesSelectionwith the same interface.- Raises:
TypeError – If index is out of bounds.
- Return type:
Example
>>> from elastica_pipelines.io import series >>> from elastica_pipelines.io.temporal import Series, SeriesSelection >>> from elastica_pipelines.io import CosseratRodRecordIndex as RodIndex >>> >>> metadata_filename = "tests/io/data/elastica_metadata.h5" >>> ser : Series = series(metadata=metadata_filename) >>> >>> s : SeriesSelection = ser.temporal_select(RodIndex([1, 2, 3])) >>> >>> # Select Cosserat rod with list of indices >>> subset : SeriesSelection = s.temporal_select(RodIndex([1, 2])) >>> >>> # Subset has same interface as Series >>> subset[50] # lookup the data at iteration 50 >>> >>> for t in subset.keys(): # obtain all iteration values for subsets >>> print(t.iterate, t.time, t.dt) >>> print(subset[t])
Note
The subset of indices requested must be contained within the bounds alredy selected, else an error is thrown.
- class elastica_pipelines.io.temporal.Snapshot(node, transforms=None)#
Data access for a single snapshot of an Elastica++ simulation.
- Parameters:
node (Node) – Node in which to lookup the information at one time iterate.
transforms (Callable, Optional) – A function/transform that takes in an array data-structure and returns a transformed version. E.g,
transforms.ToArray
Example
>>> from elastica_pipelines.io import series >>> from elastica_pipelines.io.temporal import Snapshot >>> >>> # ``series`` returns a ``Series`` object >>> metadata_filename = "tests/io/data/elastica_metadata.h5" >>> s = series(metadata=metadata_filename)
>>> snap : Snapshot = s[50] # lookup the data at iteration 50
>>> cosserat_rod_records = snap["CosseratRod"] # dict-like interface >>> for system_type in snap.keys(): # obtain all system types >>> print(system_type, snap[system_type])
- spheres()#
Access sphere records
- cosserat_rods()#
Access cosserat rod records
- systems()#
Access all system records.
- Returns:
Records across all systems.
- Return type:
ChainMap[RecordsAdapterKey, RecordLeafs]
Example
>>> from elastica_pipelines.io import series >>> from elastica_pipelines.io.temporal import Snapshot >>> >>> # ``series`` returns a ``Series`` object >>> metadata_filename = "tests/io/data/elastica_metadata.h5" >>> s = series(metadata=metadata_filename) >>> snap : Snapshot = s[50] # lookup the data at iteration 50
>>> # Iterate over all systems regardless of the type >>> for sys_id, system in snap.systems().items(): >>> print(sys_id, system)
Transforms#
Transformations to apply when reading/writing Elastica IO.
- class elastica_pipelines.io.transforms.Compose(transforms)#
Composes several transforms together.
- Parameters:
transforms (list of
Transformobjects) – list of transforms to compose.
Example
>>> from elastica_pipelines.io.transforms import Compose, ToArray >>> Compose([ >>> ToArray(), >>> ])
- class elastica_pipelines.io.transforms.ToArray#
Convert a
HDF5 datasetornumpy.ndarraytonumpy.ndarray.Example
>>> from elastica_pipelines.io.transforms import ToArray >>> ToArray()([1, 2, 3, 4]).shape
Protocols#
Elastica IO protocols.
Typing#
Elastica IO typing.
- class elastica_pipelines.io.typing.Node#
Mapping from a string to any.
- class elastica_pipelines.io.typing.RecordLeafs#
Record objects that can be queried for physical data.