LessEqual#

Description#

LessEqual compares two aligned input streams element-wise and outputs 1.0 where a <= b and 0.0 otherwise.

NaN handling: if either input is NaN at step t, the output is NaN.

Parameters: LessEqual takes no parameters.

Examples#

Usage example#

import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from screamer import LessEqual

np.random.seed(1)
x = np.cumsum(np.random.normal(size=200))
threshold = np.full_like(x, 2.0)        # a constant threshold, as a stream
mask = LessEqual()(x, threshold)        # 1.0 where x <= threshold, else 0.0

fig = make_subplots(rows=2, cols=1, shared_xaxes=True,
                    row_heights=[0.65, 0.35], vertical_spacing=0.08)
fig.add_trace(go.Scatter(y=x, mode="lines", name="x"), row=1, col=1)
fig.add_trace(go.Scatter(y=threshold, mode="lines", name="threshold = 2.0",
                         line=dict(dash="dash")), row=1, col=1)
fig.add_trace(go.Scatter(y=mask, mode="lines", name="x <= threshold",
                         line=dict(color="red", shape="hv")), row=2, col=1)
fig.update_layout(title="At or below a threshold (LessEqual)",
                  margin=dict(l=20, r=20, t=60, b=20),
                  legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1))
fig.update_yaxes(title_text="signal", row=1, col=1)
fig.update_yaxes(title_text="mask (0/1)", range=[-0.1, 1.1], row=2, col=1)
fig.show()