Modifiers
Modifier
Demux
- class crappy.modifier.demux.Demux(labels: str | List[str] | Tuple[str, ...], stream_label: str = 'stream', mean: bool = False, time_label: str = 't(s)', transpose: bool = False)[source]
Modifier converting a stream into a regular Crappy
dict
giving for each label a single value.The single value is either the first value of a column/row, or the average of the row/column values. This Modifier is mainly meant for linking streaming IOBlock blocks to Grapher blocks, as it is otherwise impossible to plot their data.
- __init__(labels: str | List[str] | Tuple[str, ...], stream_label: str = 'stream', mean: bool = False, time_label: str = 't(s)', transpose: bool = False) None [source]
Sets the args and initializes the parent class.
- Parameters:
labels – The labels corresponding to the rows or columns of the stream. It can be either a single label, or a
list
of labels, or atuple
of labels. They must be given in the same order as they appear in the stream. If fewer labels are given than there are rows or columns in the stream, only the data from the first rows/columns will be retrieved.stream_label – The label carrying the stream.
mean – If
True
, the returned value will be the average of the stream data. Otherwise, it will be the first value.time_label – The label carrying the time information.
transpose – If
True
, each label corresponds to a row in the stream. Otherwise, a label corresponds to a column in the stream.
Differentiate
- class crappy.modifier.differentiate.Diff(label: str, time_label: str = 't(s)', out_label: str | None = None)[source]
This modifier differentiates the data of a label over time and adds the differentiation value to the returned data.
- __init__(label: str, time_label: str = 't(s)', out_label: str | None = None) None [source]
Sets the args and initializes the parent class.
- Parameters:
label – The label whose data to differentiate over time.
time_label – The label carrying the time information.
out_label – The label carrying the differentiation value. If not given, defaults to
'd_<label>'
.
Integrate
- class crappy.modifier.integrate.Integrate(label: str, time_label: str = 't(s)', out_label: str | None = None)[source]
This modifier integrates the data of a label over time and adds the integration value to the returned data.
- __init__(label: str, time_label: str = 't(s)', out_label: str | None = None) None [source]
Sets the args and initializes the parent class.
- Parameters:
label – The label whose data to integrate over time.
time_label – The label carrying the time information.
out_label – The label carrying the integration value. If not given, defaults to
'i_<label>'
.
Mean
- class crappy.modifier.mean.Mean(n_points: int = 100)[source]
Modifier waiting for a given number of data points to be received, then returning their average, and starting all over again.
Unlike Moving average, it only returns a value once every
n_points
points.- __init__(n_points: int = 100) None [source]
Sets the args and initializes the parent class.
- Parameters:
n_points – The number of points on which to compute the average.
- evaluate(data: Dict[str, Any]) Dict[str, Any] | None [source]
Receives data from the upstream block, and computes the average of every label once the right number of points have been received. Then empties the buffer and returns the averages.
If there are not enough points, doesn’t return anything.
Median
- class crappy.modifier.median.Median(n_points: int = 100)[source]
Modifier waiting for a given number of data points to be received, then returning their median, and starting all over again.
Unlike Moving med, it only returns a value once every
n_points
points.
Moving average
- class crappy.modifier.moving_avg.Moving_avg(n_points: int = 100)[source]
Modifier replacing the data of each label with its average value over a chosen number of points.
Unlike Mean, it returns a value each time a message is received from the upstream link.
Moving med
- class crappy.modifier.moving_med.Moving_med(n_points: int = 100)[source]
Modifier replacing the data of each label with its median value over a chosen number of points.
Unlike Median, it returns a value each time a message is received from the upstream link.
Offset
- class crappy.modifier.offset.Offset(labels: str | List[str] | Tuple[str, ...], offsets: float | List[float] | Tuple[float, ...])[source]
This Modifier offsets every value of the given labels by a constant. This constant is calculated so that for each label the first returned value is equal to a user-defined target.
For example if for a given label the target is 6 and the first received value is 3, the Modifier will add 3 to each value received over this label.
This Modifier can be used for example when measuring a variable that should start at 0 (like a force) but doesn’t because of a sensor offset. It can also just be used to plot nicer figures. It is not very accurate as it is only based on a single data point for the offset calculation. The
make_zero
argument of the IOBlock is a better alternative if precision is required when offsetting the data.
Trig on change
- class crappy.modifier.trig_on_change.Trig_on_change(label: str)[source]
Modifier passing the data to the downstream block only when the value of a given label changes.
It also transmits the first received data. Can be used to trig a block upon change of a label value.
Trig on value
- class crappy.modifier.trig_on_value.Trig_on_value(label: str, values: Any | Tuple[Any, ...] | List[Any])[source]
Modifier passing the data to the downstream only if the value carried by a given label matches a given set of accepted values.
Mostly useful to trig blocks.