The session#
A session (M3Session) holds the recordings and all the results of one analysis. Make one session for each set of recordings that were made at the same time on one patient. Each method that you call stores its result in the session, so the next method in your workflow can use it.
Make a session and load recordings#
from m3resp import M3Session
session = M3Session()
session.load_eit("recording.bin", vendor="draeger")
session.load_emg("recording.Poly5")
session.load_ventilator("ventilator.txt", source="ventilator")
Each load method stores the loaded recording in session.raw, under "eit", "emg" or "ventilator".
Process the recordings#
Each processing method reads its input from the session and writes its results back to the session:
session.preprocess_eit()
session.detect_eit_breaths()
print(len(session.events["eit_breaths"]))
The EIT calculations come from the package eitprocessing and the EMG calculations from resurfemg. M3Resp calls these packages through adapters, and converts their results to M3Resp objects. The ventilator calculations are part of M3Resp.
Where the session stores the results#
Attribute |
Filled by |
Contains |
|---|---|---|
|
|
|
|
|
Lists of breaths and events, by name |
|
|
|
|
|
Values per breath, for example TIV and EELI |
|
The EIT lung region workflow steps |
|
|
|
|
|
|
|
|
|
The start time of each recording on the shared clock, in seconds |
|
|
How each recording was synchronized: |
|
Each session method |
A log of the method calls (see Provenance and processing history) |
|
Each workflow step |
The processing steps of a workflow run (see Provenance and processing history) |
|
You, with |
The stored data model (see Provenance and processing history) |
To find the results of one modality, use for_modality:
for signal in session.signals.for_modality("eit"):
print(signal.name, signal.unit)
The result dictionaries#
The session also keeps the results in the format returned by the outside packages and stores them in four dictionaries: session.raw, session.processed, session.events and session.parameters. In each dictionary, you can access the specific modality’s results by the modality’s own key: for example session.processed["eit"] or session.parameters["emg"].
The collections in the table above (signals, parameter_results, interval_data, pixel_masks, quality, linked_breaths) use the same objects for all modalities, making it easy to compare modalities and to export results.
preprocess_eit can receive custom preprocessing functions as input: if you pass it a function of your own with preprocess=, M3Resp stores its output in session.processed instead than in the collections, which will therefore not contain anything for that specific step.
Ventilator data#
The ventilator is a modality, as EIT and EMG are:
session.load_ventilator("ventilator.txt", source="ventilator")
session.preprocess_ventilator() # airway pressure, flow and volume
session.detect_ventilator_breaths() # session.events["ventilator_breaths"]
load_ventilatorreads multi-channel files (for example a Biopac.txtexport) with the EMG loader, and EIT.binfiles with the EIT loader.preprocess_ventilatortakes the airway pressure, flow and volume channels. It filters them only if you give a cutoff, for examplelowpass_hz=20.0. The result keeps the original values too.Each ventilator signal has
modality="ventilator"and acategory:"airway_pressure","airflow"or"volume"(see Signals).detect_ventilator_breathsfinds the breaths in the volume signal.
Use source="ventilator" for a ventilator file with its own clock. Ventilator data inside an EIT or EMG file uses the clock of that file (see Synchronization and breath timing).
All session methods#
Method |
What it does |
|---|---|
|
Loads an EIT recording |
|
Loads an EMG recording |
|
Loads a ventilator recording |
|
Keeps only a time window of the EIT recording. Run it before |
|
Keeps only a time window of the EMG recording. Run it before |
|
Keeps only a time window of each separate ventilator recording. Run it before |
|
Filters the EIT data and calculates rates, TIV and EELI |
|
Filters the EMG channel and calculates the envelope |
|
Takes the airway pressure, flow and volume channels |
|
Stores the EIT breaths in |
|
Finds the EMG breaths and stores them in |
|
Finds the ventilator breaths and stores them in |
|
Calculates the EMG parameters and quality flags |
|
Stores or reads a list of events by name |
|
Sets the start time of each recording on the shared clock |
|
Records that the recordings started together |
|
Shifts the detected breaths by an extra offset |
|
Puts the breaths of different modalities that belong together into linked breaths |
|
Calculates the timing between modalities from the linked breaths |
|
Runs the |
|
Writes all results to a folder (see How to export the results of a session) |