modelrunner.storage.trajectory module

Classes that describe time-dependent data, i.e., trajectories.

TrajectoryWriter

writes trajectories into a storage

Trajectory

Reads trajectories written with TrajectoryWriter

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.

times

Time points at which data is available

Type:

ndarray

Parameters:
  • storage (MutableMapping or string) – 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 read.

close()[source]

close the openend storage

Return type:

None

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) –

append(data, time=None)[source]

append data to the trajectory

Parameters:
  • data (Any) – The data to append to the trajectory

  • time (float, optional) – The associated time point. If omitted, the last time point is incremented by one.

Return type:

None

close()[source]
property times: ndarray

Time points written so far

Type:

ndarray