Feature extraction¶
eitprocessing.features.breath_detection.BreathDetection
dataclass
¶
BreathDetection(
*,
minimum_duration: float = 2 / 3,
averaging_window_duration: float = 15,
averaging_window_function: Callable[[int], ArrayLike] | None = blackman,
amplitude_cutoff_fraction: float | None = 0.25,
invalid_data_removal_window_length: float = 0.5,
invalid_data_removal_percentile: int = 5,
invalid_data_removal_multiplier: int = 4
)
Algorithm for detecting breaths in data representing respiration.
This algorithm detects the position of breaths in data by detecting valleys (local minimum values) and peaks (local maximum values) in data. BreathDetection has a default minimum duration of breaths to be detected. The minimum duration should be short enough to include the shortest expected breath in the data. The minimum duration is implemented as the minimum time between peaks and between valleys.
Examples:
>>> bd = BreathDetection(minimum_duration=0.5)
>>> breaths = bd.find_breaths(
... sequency=seq,
... continuousdata_label="global_impedance_(raw)"
... )
>>> global_impedance = seq.continuous_data["global_impedance_(raw)"]
>>> breaths = bd.find_breaths(continuous_data=global_impedance)
PARAMETER | DESCRIPTION |
---|---|
minimum_duration
|
minimum expected duration of breaths, defaults to 2/3 of a second
TYPE:
|
averaging_window_duration
|
duration of window used for averaging the data, defaults to 15 seconds
TYPE:
|
averaging_window_function
|
function used to create a window for averaging the data, defaults to np.blackman |
amplitude_cutoff_fraction
|
fraction of the median amplitude below which breaths are removed, defaults to 0.25
TYPE:
|
invalid_data_removal_window_length
|
window around invalid data in which breaths are removed, defaults to 0.5
TYPE:
|
invalid_data_removal_percentile
|
the nth percentile of values used to remove outliers, defaults to 5
TYPE:
|
invalid_data_removal_multiplier
|
the multiplier used to remove outliers, defaults to 4
TYPE:
|
find_breaths
¶
find_breaths(
continuous_data: ContinuousData,
result_label: str = "breaths",
sequence: Sequence | None = None,
store: bool | None = None,
) -> IntervalData
Find breaths based on peaks and valleys, removing edge cases and breaths during invalid data.
First, it naively finds any peaks that are a certain distance apart and higher than the moving average, and similarly valleys that are a certain distance apart and below the moving average.
Next, valleys at the start and end of the signal are removed to ensure the first and last valleys are actual valleys, and not just the start or end of the signal. Peaks before the first or after the last valley are removed, to ensure peaks always fall between two valleys.
At this point, it is possible multiple peaks exist between two valleys. Lower peaks are removed leaving only the highest peak between two valleys. Similarly, multiple valleys between two peaks are reduced to only the lowest valley.
As a last step, breaths with a low amplitude (the average between the inspiratory and expiratory amplitudes) are removed.
Breaths are constructed as a valley-peak-valley combination, representing the start of inspiration, the end of inspiration/start of expiration, and end of expiration.
PARAMETER | DESCRIPTION |
---|---|
continuous_data
|
optional, a ContinuousData object that contains the data
TYPE:
|
result_label
|
label of the returned IntervalData object, defaults to
TYPE:
|
sequence
|
optional, Sequence that contains the object to detect breaths in, and/or to store the result in
TYPE:
|
store
|
whether to store the result in the sequence, defaults to
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
IntervalData
|
An IntervalData object containing Breath objects. |
eitprocessing.features.pixel_breath.PixelBreath
dataclass
¶
Algorithm for detecting timing of pixel breaths in pixel impedance data.
This algorithm detects the position of start of inspiration, end of inspiration and end of expiration in pixel impedance data. It uses BreathDetection to find the global start and end of inspiration and expiration. These points are then used to find the start/end of pixel inspiration/expiration in pixel impedance data.
Example:
>>> pi = PixelBreath()
>>> eit_data = sequence.eit_data['raw']
>>> continuous_data = sequence.continuous_data['global_impedance_(raw)']
>>> pixel_breaths = pi.find_pixel_breaths(eit_data, continuous_data, sequence)
breath_detection_kwargs (dict): A dictionary of keyword arguments for breath detection. The available keyword arguments are: minimum_duration: minimum expected duration of breaths, defaults to 2/3 of a second averaging_window_duration: duration of window used for averaging the data, defaults to 15 seconds averaging_window_function: function used to create a window for averaging the data, defaults to np.blackman amplitude_cutoff_fraction: fraction of the median amplitude below which breaths are removed, defaults to 0.25 invalid_data_removal_window_length: window around invalid data in which breaths are removed, defaults to 0.5 invalid_data_removal_percentile: the nth percentile of values used to remove outliers, defaults to 5 invalid_data_removal_multiplier: the multiplier used to remove outliers, defaults to 4
find_pixel_breaths
¶
find_pixel_breaths(
eit_data: EITData,
continuous_data: ContinuousData,
sequence: Sequence | None = None,
store: bool | None = None,
result_label: str = "pixel_breaths",
) -> IntervalData
Find pixel breaths in the data.
This method finds the pixel start/end of inspiration/expiration based on the start/end of inspiration/expiration as detected in the continuous data.
If pixel impedance is in phase (within 180 degrees) with the continuous data, the start of breath of that pixel is defined as the local minimum between two end-inspiratory points in the continuous signal. The end of expiration of that pixel is defined as the local minimum between two consecutive end-inspiratory points in the continuous data. The end of inspiration of that pixel is defined as the local maximum between the start of inspiration and end of expiration of that pixel.
If pixel impedance is out of phase with the continuous signal, the start of inspiration of that pixel is defined as the local maximum between two end-inspiration points in the continuous data. The end of expiration of that pixel is defined as the local maximum between two consecutive end-inspiratory points in the continuous data. The end of inspiration of that pixel is defined as the local minimum between the start of inspiration and end of expiration of that pixel.
Pixel breaths are constructed as a valley-peak-valley combination, representing the start of inspiration, the end of inspiration/start of expiration, and end of expiration.
PARAMETER | DESCRIPTION |
---|---|
eit_data
|
EITData to apply the algorithm to
TYPE:
|
continuous_data
|
ContinuousData to use for global breath detection
TYPE:
|
result_label
|
label of the returned IntervalData object, defaults to
TYPE:
|
sequence
|
optional, Sequence that contains the object to detect pixel breaths in,
TYPE:
|
store
|
whether to store the result in the sequence, defaults to
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
IntervalData
|
An IntervalData object containing Breath objects. |
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
If store is set to true but no sequence is provided. |
ValueError
|
If the provided sequence is not an instance of the Sequence dataclass. |
eitprocessing.features.moving_average.MovingAverage
dataclass
¶
MovingAverage(
window_size: int,
window_function: Callable | None = None,
padding_type: str = "edge",
)
Algorithm for calculating the moving average of the data.
This class provides a method for calculating of the moving average of a 1D signal by convolution with a window with a given size. If not window function is provided, all samples within that window contribute equally to the moving average. If a window function is provided, the samples are weighed according to the values in the window function.
Before convolution the data is padded. The padding type is 'edge' by default. See np.pad()
for more information.
Padding adds values at the start and end with the first/last value, to more accurately determine the average at the
boundaries of the data.
PARAMETER | DESCRIPTION |
---|---|
window_size
|
the number of data points in the averaging window. Should be odd; is increased by 1 if even.
TYPE:
|
window_function
|
window function, e.g. np.blackman.
TYPE:
|
padding_type
|
see
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
np.ndarray: moving average of data with the same shape as |