4.5.3 pde.storage.memory module

Defines a class storing data in memory.

class MemoryStorage(times=None, data=None, *, info=None, field_obj=None, write_mode='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=False)[source]

Truncate the storage by removing all stored data.

Parameters:

clear_data_shape (bool) – Flag determining whether the data shape is also deleted.

Return type:

None

classmethod from_collection(storages, label=None, *, rtol=1e-05, atol=1e-08)[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=None, fields=None, info=None, write_mode='truncate_once')[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.

Return type:

MemoryStorage

start_writing(field, info=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

Return type:

None

get_memory_storage(field, info=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