4.5.1. pde.storage.base module¶
Base classes for storing data
- class StorageBase(info: Optional[Dict[str, Any]] = None, write_mode: str = 'truncate_once')[source]¶
Bases:
object
base class for storing time series of discretized fields
These classes store time series of
FieldBase
, i.e., they store the values of the fields at particular time points. Iterating of the storage will return the fields in order and individual time points can also be accessed.- Parameters
info (dict) – Supplies extra information that is stored in the storage
write_mode (str) – Determines how new data is added to already existing one. Possible values are: ‘append’ (data is always appended), ‘truncate’ (data is cleared every time this storage is used for writing), or ‘truncate_once’ (data is cleared for the first writing, but subsequent data using the same instances are appended). Alternatively, specifying ‘readonly’ will disable writing completely.
- apply(func: Callable, out: Optional[StorageBase] = None, *, progress: bool = False) StorageBase [source]¶
applies function to each field in a storage
- Parameters
func (callable) – The function to apply to each stored field. The function must either take as a single argument the field or as two arguments the field and the associated time point. In both cases, it should return a field.
out (
StorageBase
) – Storage to which the output is written. If omitted, a newMemoryStorage
is used and returnedprogress (bool) – Flag indicating whether the progress is shown during the calculation
- Returns
The new storage that contains the data after the function func has been applied
- Return type
- clear(clear_data_shape: bool = False) None [source]¶
truncate the storage by removing all stored data.
- Parameters
clear_data_shape (bool) – Flag determining whether the data shape is also deleted.
- copy(out: Optional[StorageBase] = None, *, progress: bool = False) StorageBase [source]¶
copies all fields in a storage to a new one
- Parameters
out (
StorageBase
) – Storage to which the output is written. If omitted, a newMemoryStorage
is used and returnedprogress (bool) – Flag indicating whether the progress is shown during the calculation
- Returns
The new storage that contains the copied data
- Return type
- property data_shape: Tuple[int, ...]¶
the current data shape.
- Raises
RuntimeError – if data_shape was not set
- property dtype: Tuple[int, ...]¶
the current data type.
- Raises
RuntimeError – if data_type was not set
- extract_field(field_id: Union[int, str], label: str = None) MemoryStorage [source]¶
extract the time course of a single field from a collection
Note
This might return a view into the original data, so modifying the returned data can also change the underlying original data.
- Parameters
field_id (int or str) – The index into the field collection. This determines which field of the collection is returned. Instead of a numerical index, the field label can also be supplied. If there are multiple fields with the same label, only the first field is returned.
label (str) – The label of the returned field. If omitted, the stored label is used.
- Returns
a storage instance that contains the data for the single field
- Return type
MemoryStorage
- extract_time_range(t_range: Union[float, Tuple[float, float]] = None) MemoryStorage [source]¶
extract a particular time interval
Note
This might return a view into the original data, so modifying the returned data can also change the underlying original data.
- property grid: Optional[GridBase]¶
the grid associated with this storage
This returns None if grid was not stored in self.info.
- Type
- items() Iterator[Tuple[float, FieldBase]] [source]¶
iterate over all times and stored fields, returning pairs
- start_writing(field: FieldBase, info: Optional[Dict[str, Any]] = None) None [source]¶
initialize the storage for writing data
- Parameters
field (
FieldBase
) – An example of the data that will be written to extract the grid and the data_shapeinfo (dict) – Supplies extra information that is stored in the storage
- tracker(interval: Union[int, float, ConstantIntervals] = 1) StorageTracker [source]¶
create object that can be used as a tracker to fill this storage
- Parameters
interval – Determines how often the tracker interrupts the simulation. Simple numbers are interpreted as durations measured in the simulation time variable. Alternatively, a string using the format ‘hh:mm:ss’ can be used to give durations in real time. Finally, instances of the classes defined in
intervals
can be given for more control.- Returns
The tracker that fills the current storage
- Return type
- class StorageTracker(storage, interval: Union[ConstantIntervals, float, int, str] = 1)[source]¶
Bases:
TrackerBase
Tracker that stores data in special storage classes
- storage¶
The underlying storage class through which the data can be accessed
- Type
- Parameters
storage (
StorageBase
) – Storage instance to which the data is writteninterval – Determines how often the tracker interrupts the simulation. Simple numbers are interpreted as durations measured in the simulation time variable. Alternatively, a string using the format ‘hh:mm:ss’ can be used to give durations in real time. Finally, instances of the classes defined in
intervals
can be given for more control.
- finalize(info: Optional[Dict[str, Any]] = None) None [source]¶
finalize the tracker, supplying additional information
- Parameters
info (dict) – Extra information from the simulation
- handle(field: FieldBase, t: float) None [source]¶
handle data supplied to this tracker
- Parameters
field (
FieldBase
) – The current state of the simulationt (float) – The associated time