Edges

The edges mixin, EdgesMixin, can be added to Signal to obtain different types, Type, of edges of a signal. Each of the resulting edges are returned as a Edge.

To configure how to calculate the intermediate point of the edge, refer to IntPointPolicy.

The edges mixin requires the StateLevelsMixin to also be added to the signal, the code snippet below shows how to add the edges functionality to a signal:

import signal_edges.signal as ses

class ExampleSignal(ses.state_levels.StateLevelsMixin, ses.edges.EdgesMixin, ses.Signal):
    pass

An example of its usage using VoltageSignal is described below:

import numpy as np
import signal_edges.signal as ses

# Create timestamps for the signal.
signal_timestamps = np.linspace(start=0, stop=112, num=112, endpoint=False)
# Create voltages for the signal, and add some noise to them.
pattern = [0, 0, 1.5, 2.5, 3.5, 5, 5, 5, 5, 3.5, 2.5, 1.5, 0, 0]
signal_voltages = np.asarray(pattern * (112 // len(pattern))) + \
                  np.random.normal(0, 0.1, 112)
# Create signal.
signal = ses.VoltageSignal(signal_timestamps, signal_voltages, "s", "V")
# Obtain state levels.
(state_levels, _) = signal.state_levels()
# Obtain edges.
edges = signal.edges(state_levels)

# Plot edges.
signal.edges_plot("signal.png", edges)

This code snippet generates the following plot:

../../_images/005_example_edges.png

The generated signal with the edges begin, intermediate and end points marked.

class EdgesMixin

Edges mixin for Signal derived classes that implements the calculation of edges in a signal.

Caution

This mixin requires the StateLevelsMixin in the signal derived from Signal.

__init__(*args, **kwargs)

Class constructor.

edges(levels, int_policy=IntPointPolicy.POLICY_0)

Extracts the edges in the signal from the state levels given.

Parameters:
  • levels (StateLevels) – State levels.

  • int_policy (IntPointPolicy) – The policy to use for intermediate point calculation.

Raises:
  • EdgesError – Invalid state levels.

  • EdgesError – Assertion error in the algorithm for the signal provided.

Return type:

tuple[Edge, …]

Returns:

The edges found in order of appearance in the signal.

edges_to_array(edges, array_id)

Converts values in a sequence of edges to relevant arrays.

Note that for intermediate, if two edges share the same intermediate point, two times that value will be included in the array to keep the length of the arrays consistent.

Parameters:
  • edges (Sequence[Edge]) – The sequence of edges.

  • array_id (Literal['begin', 'intermediate', 'end']) – The array identifier, which defines the type of values to take.

Raises:
  • EdgesError – The sequence of edges given has no edges.

  • EdgesError – The array identifier provided is not valid.

Return type:

tuple[ndarray[Any, dtype[float64]], ndarray[Any, dtype[float64]]]

Returns:

The values of the horizontal axis and the values of the vertical axis for the sequence of edges.

edges_plot(path, edges, *args, begin=None, end=None, munits=0, points=(), **kwargs)

Performs a plot of the edges of the signal.

Parameters:
  • path (str) – The path where to store the plot, see Plotter.plot().

  • edges (Sequence[Edge]) – The edges to plot, if there are no edges, then no points will be plotted for edges.

  • args – Additional arguments to pass to the plotting function, see Plotter.plot().

  • begin (Optional[float]) – The begin value of the horizontal axis where the plot starts, see Plotter.plot().

  • end (Optional[float]) – The end value of the horizontal axis where the plot ends, see Plotter.plot().

  • munits (float) – Margin units for the plot, see Plotter.plot().

  • points (Sequence[Literal['begin', 'intermediate', 'end']]) – The type of edge points to plot, defaults to all edge points.

  • kwargs – Additional keyword arguments to pass to the plotting function, see Plotter.plot().

Return type:

Self

Returns:

Instance of the class.

class IntPointPolicy

Policies that dictate how to calculate the intermediate point of edges.

By default, the intermediate point of any edge, both normal or runt edge, is the point within the edge the nearest to the intermediate value in the StateLevels provided by the user.

This behaviour can be modified by using intermediate point policies.

POLICY_0 = 1

Use the data point in the edge, including begin and end, that is nearest to the intermediate level.

POLICY_1 = 2

Force use of begin for falling edges and end for rising edges.

POLICY_2 = 3

Force use of end for falling edges and begin for rising edges.

class Type

Type of an edge.

The StateLevels provided for calculation of edges define the following logical areas for edges:

  • The high area, high_a, for values that satisfy value > high.

  • The intermediate high area, int_high_a, for values that satisfy intermediate < value <= high.

  • The intermediate low area, int_low_a, for values that satisfy low < value <= intermediate.

  • The low area, low_a, for values that satisfy value < low.

  • The runt low area, runt_low_a, for values that satisfy low <= value <= high_runt.

  • The runt high area, runt_high_a, for values that satisfy runt_low <= value <= high.

The runt areas and the intermediate areas overlap between each other, and the high and low areas do not overlap with any other area. The type of an edge is defined by how it transitions between these areas.

Runt edges can only be found in pairs, since until a high or low logical level has been reached it is not possible to determine whether edges are truly runt edges or normal edges.

FALLING = 1

A normal falling edge, from high_a to low_a.

FALLING_RUNT = 2

A runt falling edge, from high_a to runt_low_a or from runt_high_a to low_a.

RISING = 3

A normal rising edge, from low_a to high_a.

RISING_RUNT = 4

A runt rising edge, from low_a to runt_high_a or from runt_low_a to high_a.

class Edge

Definition of an edge in a signal.

Parameters:
  • edge_type – The type of edge.

  • ibegin – Index of the beginning of the edge in the signal.

  • hbegin – Value of the horizontal axis of the signal at the beginning of the edge.

  • vbegin – Value of the vertical axis of the signal at the beginning of the edge.

  • iintermediate – Index of the intermediate point of the edge in the signal.

  • hintermediate – Value of the horizontal axis of the signal at the intermediate of the edge.

  • vintermediate – Value of the vertical axis of the signal at the intermediate of the edge.

  • iend – Index of the end of the edge in the signal.

  • hend – Value of the horizontal axis of the signal at the end of the edge.

  • vend – Value of the vertical axis of the signal at the end of the edge.

exception EdgesError

Edges exception class.