pathsim.blocks.scope module

class pathsim.blocks.scope.Scope(sampling_rate=None, t_wait=0.0, labels=[])[source]

Bases: Block

Block for recording time domain data with variable sampling sampling rate.

A time threshold can be set by ‘wait’ to start recording data after the simulation time is larger then the specified waiting time, i.e. ‘t - t_wait > 0’. This is useful for recording data only after all the transients have settled.

Parameters:
  • sampling_rate (int, None) – number of samples per time unit, default is every timestep

  • t_wait (float) – wait time before starting recording, optional

  • labels (list[str]) – labels for the scope traces, and for the csv, optional

recording

recording, where key is time, and value the recorded values

Type:

dict

reset()[source]

Reset the blocks inputs and outputs and also its internal solver, if the block has a solver instance.

read()[source]

Return the recorded time domain data and the corresponding time for all input ports

Returns:

  • time (array[float]) – recorded time points

  • data (array[obj]) – recorded data points

sample(t)[source]

Sample the data from all inputs, and overwrites existing timepoints, since we use a dict for storing the recorded data.

Parameters:

t (float) – evaluation time for sampling

plot(*args, **kwargs)[source]

Directly create a plot of the recorded data for quick visualization and debugging.

The ‘fig’ and ‘ax’ objects are accessible as attributes of the ‘Scope’ instance from the outside for saving, or modification, etc.

Parameters:
  • args (tuple) – args for ax.plot

  • kwargs (dict) – kwargs for ax.plot

save(path='scope.csv')[source]

Save the recording of the scope to a csv file.

Parameters:

path (str) – path where to save the recording as a csv file

update(t)[source]

update system equation for fixed point loop, here just setting the outputs

Note

Scope has no passthrough, so the ‘update’ method is optimized for this case

Parameters:

t (float) – evaluation time

Returns:

error – deviation to previous iteration for convergence control

Return type:

float

class pathsim.blocks.scope.RealtimeScope(sampling_rate=None, t_wait=0.0, labels=[], max_samples=None)[source]

Bases: Scope

An extension of the ‘Scope’ block that also initializes a realtime plotter that creates an interactive plotting window while the simulation is running.

Otherwise implements the same functionality as the regular ‘Scope’ block.

Note

Due to the plotting being relatively expensive, including this block slows down the simulation significantly but may still be valuable for debugging and testing.

Parameters:
  • sampling_rate (int, None) – number of samples time unit, default is every timestep

  • t_wait (float) – wait time before starting recording

  • labels (list[str]) – labels for the scope traces, and for the csv

  • max_samples (int, None) – number of samples for realtime display, all per default

plotter

instance of a RealtimePlotter

Type:

RealtimePlotter

sample(t)[source]

Sample the data from all inputs, and overwrites existing timepoints, since we use a dict for storing the recorded data.

Parameters:

t (float) – evaluation time for sampling