perda.core_data_structures.masking#

class perda.core_data_structures.masking.FilterOptions(*values)[source]#

Bases: Enum

Specifies which array(s) a filter function receives as input.

BOTH = 'both'#
TIMESTAMPS = 'right_only'#
VALUES = 'left_only'#
perda.core_data_structures.masking.apply_ufunc_filter(data, filter_func, apply_to=FilterOptions.VALUES)[source]#

Apply a filter function to a DataInstance.

Parameters:
  • data (DataInstance) – Input DataInstance

  • filter_func (Callable) – Function that takes in values and/or timestamps and returns a boolean mask

  • apply_to (FilterOptions, optional) – Whether to apply the filter to values, timestamps, or both. Default is values

Returns:

Filtered DataInstance

Return type:

DataInstance

Notes

The mask must come from this DataInstance’s own arrays. To filter one signal by another (e.g. torque only while moving), align them with left_join_data_instances first, since signals logged at different rates have different lengths.

Examples

>>> from perda.core_data_structures import FilterOptions, apply_ufunc_filter
>>> voltage = aly.data["bms.pack.voltage"]
>>> valid = apply_ufunc_filter(voltage, lambda values: values > 0)
>>> late = apply_ufunc_filter(
...     voltage, lambda ts: ts > ts[0] + 60_000_000, apply_to=FilterOptions.TIMESTAMPS
... )