4.8.1 pde.trackers.base module

Base classes for trackers.

TrackerBase

Base class for implementing trackers.

TrackerCollection

List of trackers providing methods to handle them efficiently.

TransformedTrackerBase

Tracker that allows modifying incoming data.

FinishedSimulation

Exception for signaling that simulation finished successfully.

exception FinishedSimulation[source]

Bases: StopIteration

Exception for signaling that simulation finished successfully.

add_note()

Exception.add_note(note) – add a note to the exception

args
value

generator return value

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class TrackerBase(interrupts: InterruptsBase | int | float | str | Sequence[float] | ndarray[Any, dtype[number]] = 1)[source]

Bases: object

Base class for implementing trackers.

Parameters:

interrupts – Determines when the tracker interrupts the simulation. A single numbers determines an interval (measured in the simulation time unit) of regular interruption. A string is interpreted as a duration in real time assuming the format ‘hh:mm:ss’. A list of values is taken as explicit simulation time points. More fine- grained control is possible by passing an instance of classes defined in interrupts.

finalize(info: dict[str, Any] | None = None) → None[source]

Finalize the tracker, supplying additional information.

Parameters:

info (dict) – Extra information from the simulation

classmethod from_data(data: TrackerBase | str, **kwargs) → TrackerBase[source]

Create tracker class from given data.

Parameters:
  • data (str or TrackerBase) – Data describing the tracker

  • **kwargs – Additional keyword arguments passed to the tracker constructor

Returns:

An instance representing the tracker

Return type:

TrackerBase

abstractmethod 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[str, Any] | None = None) → float[source]

Initialize the tracker with information about the simulation.

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

class TrackerCollection(trackers: list[TrackerBase] | None = None)[source]

Bases: object

List of trackers providing methods to handle them efficiently.

trackers

List of the trackers in the collection

Type:

list

Parameters:

trackers – List of trackers that are to be handled.

finalize(info: dict[str, Any] | None = None) → None[source]

Finalize the tracker, supplying additional information.

Parameters:

info (dict) – Extra information from the simulation

classmethod from_data(data: Sequence[TrackerBase | str] | TrackerBase | str | None, **kwargs) → TrackerCollection[source]

Create tracker collection from given data.

Parameters:
  • data – Data describing the tracker collection

  • **kwargs – Additional keyword arguments passed to tracker constructors

Returns:

An instance representing the tracker collection

Return type:

TrackerCollection

handle(state: FieldBase, t: float, atol: float = 1e-08) → float[source]

Handle all trackers.

Parameters:
  • state (FieldBase) – The current state of the simulation

  • t (float) – The associated time

  • atol (float) – An absolute tolerance that is used to determine whether a tracker should be called now or whether the simulation should be carried on more timesteps. This is basically used to predict the next time to decided which one is closer.

Returns:

The next time the simulation needs to be interrupted to handle a tracker.

Return type:

float

initialize(field: FieldBase, info: dict[str, Any] | None = None) → float[source]

Initialize the tracker with information about the simulation.

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

class TransformedTrackerBase(interrupts: InterruptsBase | int | float | str | Sequence[float] | ndarray[Any, dtype[number]] = 1, *, transformation: Callable[[FieldBase, float], FieldBase] | None = None)[source]

Bases: TrackerBase

Tracker that allows modifying incoming data.

To support the transformations sub-classes need to call self._transform(field, t) to obtain the transformed field.

Parameters:
  • interrupts – Determines when the tracker interrupts the simulation. A single numbers determines an interval (measured in the simulation time unit) of regular interruption. A string is interpreted as a duration in real time assuming the format ‘hh:mm:ss’. A list of values is taken as explicit simulation time points. More fine- grained control is possible by passing an instance of classes defined in interrupts.

  • transformation (callable, optional) – A function that transforms the current state into a new field or field collection, which is then used in the tracker. This allows to process derived quantities of the field during calculations. The argument needs to be a callable function taking 1 or 2 arguments. The first argument always is the current field, while the optional second argument is the associated time.

finalize(info: dict[str, Any] | None = None) → None

Finalize the tracker, supplying additional information.

Parameters:

info (dict) – Extra information from the simulation

classmethod from_data(data: TrackerBase | str, **kwargs) → TrackerBase

Create tracker class from given data.

Parameters:
  • data (str or TrackerBase) – Data describing the tracker

  • **kwargs – Additional keyword arguments passed to the tracker constructor

Returns:

An instance representing the tracker

Return type:

TrackerBase

abstractmethod handle(field: FieldBase, t: float) → None

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[str, Any] | None = None) → float

Initialize the tracker with information about the simulation.

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

registered_trackers() → dict[str, type[TrackerBase]][source]

Returns all trackers that are currently registered.

Returns:

a dictionary with the names of the trackers and the associated class

Return type:

dict