resurfemg.postprocessing.event_detection module¶
Copyright 2022 Netherlands eScience Center and University of Twente Licensed under the Apache License, version 2.0. See LICENSE for details.
This file contains functions to extract detect peak, on- and offset samples.
- resurfemg.postprocessing.event_detection.detect_emg_breaths(emg_env, emg_baseline=None, threshold=0, prominence_factor=0.5, min_peak_width_s=1)¶
Identify the electrophysiological breaths from the EMG envelope and return an array breath peak indices. Input of baseline threshold, peak prominence factor, and minimal peak width are optional. ————————————————————————— :param emg_env: 1D EMG envelope signal :type emg_env: ~numpy.ndarray :param emg_baseline: EMG baseline. If none provided, 0 baseline is used. :type emg_baseline: ~numpy.ndarray :param threshold: required threshold of peaks, vertical threshold to neighbouring samples :type threshold: ~float :param prominence_factor: required prominence of peaks, relative to the 75th - 50th percentile of the emg_env above the baseline :type prominence_factor: ~float :param min_peak_width_s: required width of peak in samples :type min_peak_width_s: ~int
- Returns peak_idxs:
list of EMG breath peak indices
- Rtype peak_idxs:
list[int]
- resurfemg.postprocessing.event_detection.detect_ventilator_breath(v_vent, start_idx, end_idx, width_s, threshold=None, prominence=None, threshold_new=None, prominence_new=None)¶
Identify the breaths from the ventilator signal and return an array of ventilator peak breath indices, in two steps of peak detection. Input of threshold and prominence values is optional. ————————————————————————— :param v_vent: Ventilator volume signal :type v_vent: ~numpy.ndarray :param start_idx: start sample of the window in which to be searched :type start_idx: ~int :param end_idx: end sample of the window in which to be searched :type end_idx: ~int :param width_s: required width of peak in samples :type width_s: :param threshold: required threshold of peaks, vertical threshold to neighbouring samples :type threshold: ~int :param prominence: required prominence of peaks :type prominence: ~int :param threshold_new: :type threshold_new: ~int :param prominence_new: :type prominence_new: ~int
- Returns ventilator_breath_idxs:
list of ventilator breath peak indices
- Rtype ventilator_breath_idxs:
list[int]
- resurfemg.postprocessing.event_detection.find_linked_peaks(signal_1_t_peaks, signal_2_t_peaks)¶
Find the indices of the peaks in signal 2 closest to the time of the peaks in signal 1 :param signal_1_t_peaks: list of timing of peaks in signal 1 :type signal_1_t_peaks: ~numpy.ndarray :param signal_2_t_peaks: list of timing of peaks in signal 2 :type signal_2_t_peaks: ~numpy.ndarray
- Returns peaks_idxs_signal_1_in_2:
Peak indices of signal 2 closest to the peaks in signal 1
- Rtype peaks_idxs_signal_1_in_2:
~numpy.ndarray[int]
- resurfemg.postprocessing.event_detection.find_occluded_breaths(p_vent, fs, peep, start_idx=0, end_idx=None, prominence_factor=0.8, min_width_s=None, distance_s=None)¶
Find end-expiratory occlusion manoeuvres (Pocc) in ventilator pressure timeseries data. start_idx and end_idx specify the samples to look into. The prominence_factor, min_width_s, and distance_s specify the minimal peak prominence relative to the PEEP level, peak width in samples, and distance to other peaks. ————————————————————————— :param p_vent: ventilator pressure signal :type p_vent: ~nd.array :param fs: sampling rate :type fs: int :param peep: positive end-expiratory pressure :type peep: ~float :param start_idx: start index to start looking for Pocc manoeuvres :type start_idx: int :param end_idx: end index to start looking for Pocc manoeuvres :type end_idx: int :param prominence_factor: multiplier in setting the minimum peak prominence :type prominence_factor: ~float :param min_width_s: minimum peak width in samples :type min_width_s: int :param distance_s: mininum interpeak distance in samples :type distance_s: int
- Returns peak_idxs:
list of Pocc peak indices
- Rtpe peak_idxs:
~nd.array[int]
- resurfemg.postprocessing.event_detection.onoffpeak_baseline_crossing(signal_env, baseline, peak_idxs)¶
This function calculates the peaks of each breath using the slopesum baseline of envelope data. ————————————————————————— :param signal_env: envelope signal :type signal_env: ~numpy.ndarray :param baseline: baseline signal of EMG data for baseline detection :type baseline: ~numpy.ndarray :param peak_idxs: list of peak indices for which to find on- and offset :type peak_idxs: ~numpy.ndarray
- Returns peak_start_idxs:
list of start indices of the peaks
- Rtype peak_start_idxs:
~numpy.ndarray[int]
- Returns peak_end_idxs:
list of end indices of the peaks
- Rtype peak_end_idxs:
~numpy.ndarray[int]
- Returns valid_starts_bools:
list of boolean values for valid starts
- Rtype valid_starts_bools:
~numpy.ndarray[bool]
- Returns valid_ends_bools:
list of boolean values for valid ends
- Rtype valid_ends_bools:
~numpy.ndarray[bool]
- Returns valid_peaks:
list of boolean values for valid peaks
- Rtype valid_peaks:
~numpy.ndarray[bool]
- resurfemg.postprocessing.event_detection.onoffpeak_slope_extrapolation(signal_env, fs, peak_idxs, slope_window_s)¶
This function calculates the peak on- and offsets of a signal by extra- polating the maximum slopes in de slope_window_s to the zero crossings. The validity arrays provide feedback on the validity of the detected on- and offsets, aiming to prevent onsets after peak indices, offsets before peak indices, and overlapping peaks. ————————————————————————— :param signal_env: signal to identify on- and offsets in :type signal_env: ~numpy.ndarray :param fs: sampling rate :type fs: int :param peak_idxs: list of peak indices for which to find on- and offset :type peak_idxs: ~numpy.ndarray :slope_window_s: how many samples on each side to use for the comparison to consider for detecting the local maximum slope :type fs: int
- Returns peak_start_idxs:
list of start indices of the peaks
- Rtype peak_start_idxs:
~numpy.ndarray[int]
- Returns peak_end_idxs:
list of end indices of the peaks
- Rtype peak_end_idxs:
~numpy.ndarray[int]
- Returns valid_starts_bools:
list of boolean values for valid starts
- Rtype valid_starts_bools:
~numpy.ndarray[bool]
- Returns valid_ends_bools:
list of boolean values for valid ends
- Rtype valid_ends_bools:
~numpy.ndarray[bool]
- Returns valid_peaks:
list of boolean values for valid peaks
- Rtype valid_peaks:
~numpy.ndarray[bool]