Adapters#
An adapter connects M3Resp to an outside package. It calls eitprocessing or resurfemg, and changes the results into the Layer 1 objects of the concept guides. The session, the workflow steps and the export read only these M3Resp objects.
eitprocessing or resurfemg result
|
v
EITProcessingAdapter, ReSurfEMGAdapter or VentilatorAdapter
| to_signals, to_parameters, to_interval_data, to_quality_flags
v
Signal, BreathEvent, ParameterResult, IntervalData, QualityFlag
The session has one adapter of each type: session.eit_adapter, session.emg_adapter and session.ventilator_adapter.
The conversion methods#
Each adapter has the same conversion methods. They read the result of preprocess or postprocess and give lists of M3Resp objects:
Method |
Gives |
|---|---|
|
|
|
|
|
|
|
|
|
|
EITProcessingAdapter#
The code is in src/m3resp/adapters/eitprocessing_adapter/.
Methods |
What they do |
|---|---|
|
Load a vendor EIT file into an |
|
Get the pixel, global or regional impedance from a sequence |
|
Cut a sequence to a range of frames |
|
Run one |
|
Make and filter regions of interest |
|
Run rate detection, filter, breath detection, TIV, EELI and pixel TIV in one call. |
|
Run a TIV function that you give |
ReSurfEMGAdapter#
The code is in src/m3resp/adapters/resurfemg_adapter/, with one file per task: _core.py, _ecg.py, _baseline.py, _quality.py and _defaults.py.
The methods take plain arrays or the recording dictionary of load. This dictionary has the samples under "array", one row per channel, and the sampling rate in Hz under metadata["fs"]. The values keep the units of the recording. Times are in seconds, and positions are sample numbers. The last column says which package calculates the result. A resurfemg function runs with the settings and defaults of resurfemg.
Methods |
What they do |
Calculated by |
|---|---|---|
|
Load an EMG file into a recording dictionary. The |
|
|
Take one channel to analyse. Without |
M3Resp |
|
Remove one frequency and its harmonics, for example the mains hum or the frame rate of the EIT |
M3Resp ( |
|
Band-pass filter, 20 to 500 Hz by default. If 95% of the Nyquist frequency is below 500 Hz, the upper limit is 95% of the Nyquist frequency. |
|
|
RMS, ARV or median envelope over a moving window |
M3Resp ( |
|
The four methods above in one call. |
As above |
|
Find and remove the ECG |
|
|
Calculate the baseline of the envelope |
|
|
Find the breaths as envelope peaks above the baseline |
M3Resp ( |
|
Calculate the baselines, the start and end of each breath, the parameters of each breath and the quality checks in one call. |
M3Resp for the parameters, |
|
Run one quality check each |
|
|
List and call 23 functions of |
|
|
Run a feature function that you give |
Your function |
The workflow steps in workflows/steps/emg/ and workflows/steps/ventilator/ call these methods one by one.
VentilatorAdapter#
The code is in src/m3resp/adapters/ventilator_adapter/. The adapter reads ventilator data from three sources:
Source |
Read by |
|---|---|
An EMG file with ventilator channels |
|
An EIT |
|
A file type with a reader of its own |
The reader registered for its file extension |
source="eit", "emg" or "ventilator" selects the source. Without source, the adapter uses the reader registered for the file extension. Without a registered reader, it reads .bin files as EIT and all other files as EMG.
preprocess splits the recording into pressure, flow and volume channels. With lowpass_hz, it also filters them with a low-pass filter. to_parameters and to_quality_flags give empty lists. The ventilator.* workflow steps calculate the ventilator parameters and quality checks.
Comparison tests#
The tests in tests/regression/ compare the result of each adapter method with the direct call of eitprocessing or resurfemg, with the same settings. Most tests require exactly equal values. If one of these tests fails, look at the adapter method first. See Testing.
Add a function of eitprocessing or resurfemg#
Add a method to the adapter. Give it the same argument names and defaults as the original function.
To store the result in the session, change it into M3Resp objects in a
to_*method.Add a test in
tests/regression/that compares the method with the original function.To use the method in workflow files, add a step. See How to add a step of your own.
Continue with Preset contracts.