modelrunner.storage.trajectory module
Classes that describe time-dependent data, i.e., trajectories.
writes trajectories into a storage |
|
Reads trajectories written with |
- class Trajectory(storage, loc='trajectory')[source]
Bases:
object
Reads trajectories written with
TrajectoryWriter
The class permits direct access to indivdual items in the trajcetory using the square bracket notation. It is also possible to iterate over all items.
- Parameters:
- class TrajectoryWriter(storage, loc='trajectory', *, attrs=None, mode=None)[source]
Bases:
object
writes trajectories into a storage
Stored data can then be read using
Trajectory
.Example
# write data using context manager with TrajectoryWriter("test.zarr") as writer: for t, data in simulation: writer.append(data, t) # append to same file using explicit class interface writer = TrajectoryWriter("test.zarr", mode="append") writer.append(data0) writer.append(data1) writer.close() # read data trajectory = Trajectory("test.zarr") assert trajectory[-1] == data1
- Parameters:
store – Store or path to directory in file system or name of zip file.
loc (str or list of str) – The location in the storage where the trajectory data is written.
attrs (dict) – Additional attributes stored in the trajectory.
mode (str or
AccessMode
) – The file mode with which the storage is accessed. Determines allowed operations. The meaning of the special (default) value None depends on whether the file given by store already exists. If yes, a RuntimeError is raised, otherwise the choice corresponds to mode=”full” and thus creates a new trajectory. If the file exists, use mode=”truncate” to overwrite file or mode=”append” to insert new data into the file.storage (str | Path | StorageGroup | StorageBase) –