4.5.3. pde.storage.memory module

Defines a class storing data in memory.

class MemoryStorage(times: Optional[Sequence[float]] = None, data: Optional[List[ndarray]] = None, field_obj: Optional[FieldBase] = None, info: Optional[Dict[str, Any]] = None, write_mode: str = 'truncate_once')[source]

Bases: StorageBase

store discretized fields in memory

Parameters
  • times (ndarray) – Sequence of times for which data is known

  • data (list of ndarray) – The field data at the given times

  • field_obj (FieldBase) – An instance of the field class store data for a single time point.

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

  • write_mode (str) – Determines how new data is added to already existing data. 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 appended subsequently). Alternatively, specifying ‘readonly’ will disable writing completely.

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.

data: Any
classmethod from_collection(storages: Sequence[StorageBase], label: str = None, *, rtol: float = 1e-05, atol: float = 1e-08) MemoryStorage[source]

combine multiple memory storages into one

This method can be used to combine multiple time series of different fields into a single representation. This requires that all time series contain data at the same time points.

Parameters
  • storages (list) – A collection of instances of StorageBase whose data will be concatenated into a single MemoryStorage

  • label (str, optional) – The label of the instances of FieldCollection that represent the concatenated data

  • rtol (float) – Relative tolerance used when checking times for merging

  • atol (float) – Absolute tolerance used when checking times for merging

Returns

Storage containing all the data.

Return type

MemoryStorage

classmethod from_fields(times: Optional[Sequence[float]] = None, fields: Optional[Sequence[FieldBase]] = None, info: Optional[Dict[str, Any]] = None, write_mode: str = 'truncate_once') MemoryStorage[source]

create MemoryStorage from a list of fields

Parameters
  • times (ndarray) – Sequence of times for which data is known

  • fields (list of FieldBase) – The fields at all given time points

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

  • write_mode (str) – Determines how new data is added to already existing data. 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 appended subsequently). Alternatively, specifying ‘readonly’ will disable writing completely.

start_writing(field: FieldBase, info: Optional[Dict[str, Any]] = None) None[source]

initialize the storage for writing data

Parameters
  • field (FieldBase) – An instance of the field class store data for a single time point.

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

times: Sequence[float]
write_mode: str
get_memory_storage(field: FieldBase, info: Optional[Dict[str, Any]] = None)[source]

a context manager that can be used to create a MemoryStorage

Example

This can be used to quickly store data:

with get_memory_storage(field_class) as storage:
    storage.append(numpy_array0, 0)
    storage.append(numpy_array1, 1)

# use storage thereafter
Parameters
  • field (FieldBase) – An instance of the field class store data for a single time point.

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

Yields

MemoryStorage