Scope

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

Bases: Block

Block for recording time domain data with variable sampling period.

A time threshold can be set by t_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.

The block uses an internal Schedule event, when sampling_period is provided, otherwise it just samples at every simulation timestep.

Parameters:
  • sampling_period (float, None) – time between samples, 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_time

recorded time points

Type:

list[float]

recording_data

recorded data points

Type:

list[float]

_incremental_idx

index for incremental reading of accumulated data since last call of incremental read

Type:

int

_sample_next_timestep

flag to indicate this is a timestep to sample, only used for event based sampling when sampling_period is provided as an arg

Type:

bool

events

internal scheduled event for periodic input sampling when sampling_period is provided

Type:

list[Schedule]

reset()[source]

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

read(incremental=False)[source]

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

Parameters:

incremental (bool) – read the data incrementally, only return new data that has accumulated after the last incremental read call

Returns:

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

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

collect()[source]

Yield (category, id, data) tuples for recording blocks to simplify

Deprecated since version 1.0.0: its against pathsims philosophy

global data collection from all recording blocks.

sample(t, dt)[source]

Sample the data from all inputs. Skips duplicate timestamps to maintain unique time points in the recording.

If sampling_period is provided, this depends on the flag _sample_next_timestep, set by the internal Schedule event.

Parameters:

t (float) – evaluation time for sampling

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

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

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

  • kwargs (dict) – kwargs for ax.plot

Returns:

  • fig (matplotlib.figure) – internal figure instance

  • ax (matplotlib.axis) – internal axis instance

plot2D(*args, axes=(0, 1), **kwargs)[source]

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

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

  • axes (tuple[int]) – axes / ports to select for 2d plot

  • kwargs (dict) – kwargs for ax.plot

Returns:

  • fig (matplotlib.figure) – internal figure instance

  • ax (matplotlib.axis) – internal axis instance

plot3D(*args, axes=(0, 1, 2), **kwargs)[source]

Directly create a 3D plot of the recorded data for quick visualization.

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

  • axes (tuple[int]) – indices of the three data channels (ports) to plot (default: (0, 1, 2)).

  • kwargs (dict) – kwargs for ax.plot

Returns:

  • fig (matplotlib.figure) – internal figure instance.

  • ax (matplotlib.axes._axes.Axes3D) – internal 3D axis instance.

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 (does nothing)

Parameters:

t (float) – evaluation time

Returns:

error – absolute error to previous iteration for convergence control (always ‘0.0’ because sink-type)

Return type:

float

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

Bases: Scope

An extension of the ‘Scope’ block that initializes a realtime plotter.

Deprecated since version 1.0.0.

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_period (float, None) – time between samples, 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, dt)[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