4.5.1. pde.storage.base module

Base classes for storing data

class StorageBase(info: dict = 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.

append(field: FieldBase, time: float = None) None[source]

add field to the storage

Parameters
  • field (FieldBase) – The field that is added to the storage

  • time (float, optional) – The time point

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 new MemoryStorage is used and returned

  • progress (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

StorageBase

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 new MemoryStorage is used and returned

  • progress (bool) – Flag indicating whether the progress is shown during the calculation

Returns

The new storage that contains the copied data

Return type

StorageBase

data: Any
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

end_writing() None[source]

finalize the storage after writing

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.

Parameters

t_range (float or tuple) – Determines the range of time points included in the result. If only a single number is given, all data up to this time point are included.

Returns

a storage instance that contains the extracted data.

Return type

MemoryStorage

property grid: Optional[pde.grids.base.GridBase]

the grid associated with this storage

This returns None if grid was not stored in self.info.

Type

GridBase

property has_collection: bool

whether the storage is storing a collection

Type

bool

items() Iterator[Tuple[float, FieldBase]][source]

iterate over all times and stored fields, returning pairs

property shape: Optional[Tuple[int, ...]]

the shape of the stored data

start_writing(field: FieldBase, info: dict = 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_shape

  • info (dict) – Supplies extra information that is stored in the storage

times: Sequence[float]
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

StorageTracker

write_mode: str
class StorageTracker(storage, interval: Union[ConstantIntervals, float, int, str] = 1)[source]

Bases: pde.trackers.base.TrackerBase

Tracker that stores data in special storage classes

storage

The underlying storage class through which the data can be accessed

Type

StorageBase

Parameters
  • storage (StorageBase) – Storage instance to which the data is written

  • 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.

finalize(info: dict = 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 simulation

  • t (float) – The associated time

initialize(field: FieldBase, info: dict = None) float[source]
Parameters
  • field (FieldBase) – An example of the data that will be analyzed by the tracker

  • info (dict) – Extra information from the simulation

Returns

The first time the tracker needs to handle data

Return type

float