Skip to content

PEEP trial segmentation (layer 2b)

pipeline

segment_peep_trial(): split a preprocessed PEEP trial into PEEP steps (layer 2b).

Steps (notebooks/06_peep_trial_segmentation.ipynb, section 7): 1. breaths of the PEEP trial phase, with the PEEP and plateau read in layer 2 (EITRecording.breaths); 2. PEEP steps: placed by hand if given, otherwise found from the PEEP of each breath; 3. breaths analysed in each step, and the step table.

segment_peep_trial

segment_peep_trial(recording: EITRecording, config: SegmentationConfig | None = None, peep_steps: Sequence[Segment] = (), phase: Segment | None = None, tidal_volumes: Sequence[float | None] | None = None) -> PeepTrial

Split a preprocessed PEEP trial into PEEP steps and choose the breaths analysed.

A recording can contain more than one protocol, e.g. a tidal baseline and then a PEEP trial: phase limits the segmentation to the PEEP trial. A part that is not analysed at all (e.g. a maneuver) is an exclusion of preprocess() instead: its breaths are never analysed and do not count when the steps are found.

Parameters:

Name Type Description Default
recording EITRecording

Output of preprocess().

required
config SegmentationConfig | None

Parameters; defaults of SegmentationConfig if None.

None
peep_steps Sequence[Segment]

Steps placed by hand: segments with category="peep_step", the PEEP level in parameters["peep"] (cmH2O) and optionally the plateau (parameters["plateau"]) or the driving pressure (parameters["driving_pressure"]) read on the ventilator, and the tidal volume (parameters["tidal_volume"], mL). If given, they replace the steps found from the pressure, and the breaths analysed are the valid breaths inside them.

()
phase Segment | None

The PEEP trial part of the recording: a segment with category="phase" and label="peep_trial". If None, the whole recording.

None
tidal_volumes Sequence[float | None] | None

Tidal volume typed for each step (mL), in time order, e.g. the mean of each step on the case report form; None for a step without it. One volume for the whole recording goes in RecordingContext.tidal_volume_ml instead.

None

Returns:

Type Description
PeepTrial

The PEEP trial. Breaths outside the phase or the steps have peep_step -1.

Raises:

Type Description
ValueError

if there are no steps placed by hand and no pressure to find them, a step placed by hand or the phase is not usable, no breath is inside the phase or the steps placed by hand, or tidal_volumes does not have one positive value per step.

peep_steps

PEEP steps of a PEEP trial and the breaths analysed in each step.

Steps come from the PEEP of each breath (EITRecording.breaths) or are placed by hand as segments with their PEEP level; steps placed by hand win over the automatic ones (notebooks/06_peep_trial_segmentation.ipynb, sections 3, 5 and 7).

find_steps

find_steps(peep: ndarray, threshold: float, min_breaths: int, agreement: float) -> np.ndarray

First breath of each PEEP step.

A new step starts when min_breaths breaths in a row are further than threshold from the level of the current step and within agreement of each other; the level of the current step is the median PEEP of its breaths so far (of the first min_breaths breaths at the start). With min_breaths of 2 or more a single odd breath (a maneuver) cannot open a step. A breath without PEEP (NaN) takes the PEEP of the next breath that has one.

Parameters:

Name Type Description Default
peep ndarray

PEEP of each breath.

required
threshold float

Half of the step of the protocol (e.g. 1 for steps of 2).

required
min_breaths int

Breaths in a row needed to open a step.

required
agreement float

Largest spread of those breaths.

required

Returns:

Type Description
ndarray

Index of the first breath of each step; the first is always 0.

Raises:

Type Description
ValueError

if no breath has a PEEP.

step_of_each_breath

step_of_each_breath(step_starts: ndarray, n_breaths: int) -> np.ndarray

Step number of each breath, from the first breath of each step.

A breath belongs to the last step that starts at or before it: searchsorted counts the steps that start at or before each breath, minus one gives the step number.

protocol_levels

protocol_levels(levels: ndarray, protocol: Sequence[float] | None, tolerance: float) -> np.ndarray

PEEP level of the protocol of each step.

The measured PEEP of every step can be off the set level by about the same amount (mbar to cmH2O, PEEP valve: +0.6 cmH2O in every step of a trial of notebook 06, 1.1 cmH2O at PEEP 0, nearer to 2 than to 0). That offset, the median distance of the steps from their nearest level, is removed first; then each step gets the nearest level. A step further than tolerance from every level (a level that is not in the protocol) gets NaN. An offset of half a step or more cannot be told apart from the next level.

Parameters:

Name Type Description Default
levels ndarray

PEEP of each step, measured or typed (cmH2O).

required
protocol Sequence[float] | None

PEEP levels of the protocol, or None.

required
tolerance float

Largest distance from a level of the protocol (cmH2O).

required

Returns:

Type Description
ndarray

One level per step; NaN where no level of the protocol is near enough, and for

ndarray

every step without the levels of the protocol.

steps_from_segments

steps_from_segments(breath_starts: ndarray, breath_ends: ndarray, segments: Sequence[Segment]) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]

Steps placed by hand: the breaths inside each segment, its PEEP and plateau.

A breath belongs to a segment when it starts and ends inside it: a breath cut by the edge of a segment is left out. Segments are numbered in time order. The plateau, or directly the driving pressure, is optional (e.g. read on the ventilator during an inspiratory hold), for recordings without a pressure signal; so is the tidal volume of the step (e.g. its mean on the case report form).

Parameters:

Name Type Description Default
breath_starts ndarray

Start time of each breath, in seconds.

required
breath_ends ndarray

End time of each breath, in seconds.

required
segments Sequence[Segment]

Segments with category="peep_step", the PEEP level in parameters["peep"] (cmH2O) and optionally parameters["plateau"] or parameters["driving_pressure"] (the plateau wins if both are given) and parameters["tidal_volume"] (mL).

required

Returns:

Type Description
ndarray

step: step number of each breath (-1 outside every segment);

ndarray

levels: PEEP level of each step; plateaus: plateau typed for each step,

ndarray

or PEEP + driving pressure typed (NaN if neither is given); volumes: tidal

ndarray

volume typed for each step (NaN if not given).

Raises:

Type Description
ValueError

if a segment is not a PEEP step, has no PEEP level, overlaps another one, or no breath is inside any segment.

analysed_breaths

analysed_breaths(breath_starts: ndarray, step: ndarray, valid: ndarray, skip_seconds: float, max_breaths: int) -> np.ndarray

Breaths analysed in each automatic step.

The breaths in the first skip_seconds of the step (from its first breath) are left out, as EELI is still moving; then the last max_breaths valid breaths of the step are analysed (notebook 06, section 5).

Parameters:

Name Type Description Default
breath_starts ndarray

Start time of each breath, in seconds.

required
step ndarray

Step number of each breath (-1 = no step).

required
valid ndarray

is_valid of each breath.

required
skip_seconds float

Time left out after the change of PEEP.

required
max_breaths int

Most breaths analysed per step.

required

Returns:

Type Description
ndarray

Boolean array, True for the analysed breaths.

Raises:

Type Description
ValueError

if max_breaths is less than 1.