src.helpers.signal_processing.digitalization module
This module offers helper functions for binary signals.
They are important for the data-driven assessment, e.g., in the UNECE-R79 use case.
It includes the following functions: - pullup_glitches: sets short glitches of zeros in a binary signal to ones, - get_event_boundaries: determines the start and stop indices of a signal level of One, - select_longest_events: selects the longest event per test scenario. They are mainly based on numpy arrays for fast vectorized operations. See details in their respective documentations.
Contact person: Stefan Riedmaier Creation date: 24.06.2020 Python version: 3.8
- src.helpers.signal_processing.digitalization.get_event_boundaries(x, min_length=1, axis=-1)
This function determines the start and stop indices of a signal level of One, provided it exceeds the min_length.
It aims at getting the boundaries of true events.
Examples: x = np.array([1, 1, 1, 1, 1, 0, 0, 0, 0]) start_indices, stop_indices, event_length = digitalization.get_event_boundaries(x, min_length=1) start_indices_exp, stop_indices_exp, event_length_exp = (np.array([0]),), (np.array([5]),), np.array([5])
- Parameters:
x (np.ndarray) – binary signal
min_length – (optional) minimum length to be considered an event
axis (int) – (optional) axis parameter for multi-dimensional arrays
- Returns:
start (at first ones) and stop (after last ones) indices and event length
- Return type:
(tuple, tuple, np.ndarray)
- src.helpers.signal_processing.digitalization.pullup_glitches(x, max_glitch_duration, axis=-1)
This function sets short glitches of zeros in a binary signal to ones.
Examples: max_glitch_duration = 4 x = np.array([1, 1, 1, 0, 0, 0, 0, 1, 1]) -> np.array([1, 1, 1, 1, 1, 1, 1, 1, 1]) x = np.array([1, 1, 1, 0, 0, 0, 0, 0, 1, 1]) -> np.array([1, 1, 1, 0, 0, 0, 0, 0, 1, 1])
- Parameters:
x (np.ndarray) – binary signal with glitches
max_glitch_duration (int) – maximum number of samples to count as a short glitch
axis (int) – (optional) axis parameter for multi-dimensional arrays
- Returns:
binary signal without glitches
- Return type:
np.ndarray
- src.helpers.signal_processing.digitalization.select_longest_events(start_idx, stop_idx, event_length, idx_time, scenario_shape)
This function selects the longest event per test scenario.
Sometimes the experiments are planned to contain one event per test scenario / experiment, where the scenario conditions are met. However, it is possible that the condition check includes gaps and results in multiple events. Then, one option is to select only the longest event and discard the shorter ones, because they are not independent repetitions of a test scenario in multiple experiments.
- Parameters:
start_idx (tuple) – start indices
stop_idx (tuple) – stop indices
event_length (np.ndarray) – length of the events
idx_time (int) – index of the time dimension in the index tuples
scenario_shape (tuple) – shape of the scenario array
- Returns:
start indices, stop indices and event length of the longest events per test scenario
- Return type:
(tuple, tuple, np.ndarray)