Migration guide#
These pages help you change analysis code that calls eitprocessing or resurfemg into M3Resp code. Each page lists the direct calls and the M3Resp calls that do the same work.
How M3Resp uses the two packages#
M3Resp calls eitprocessing and resurfemg to load, filter and detect breaths. Some functions of both packages are copied into m3resp.processing, and NOTICE.md lists them. The tests in tests/regression/ check that M3Resp gives the same results as the direct calls with the same settings.
Both packages stay separate. You can still use them without M3Resp.
Tasks for all modalities#
Some tasks that you did by hand have one M3Resp call:
Task |
M3Resp call |
|---|---|
Keep a note of the settings and the package versions |
|
Shift the times of one recording to the clock of another |
|
Put a signal on the time points of another signal |
|
Find the breaths of two modalities that belong together |
|
Calculate the time between the breaths of two modalities |
|
Write the results to CSV and JSON files |
|
interpolate_to_time uses linear interpolation. The two signals must be on the same clock. To lower the sampling rate, filter the signal with a low-pass filter first.
session.link_breaths only matches breaths. Detect the breaths of each modality first.
Use clock times of the devices#
If you know the clock time at which each device started, compute_offsets_from_timestamps gives the start time of each recording:
from m3resp import compute_offsets_from_timestamps
# start of each recording, in seconds after midnight
offsets = compute_offsets_from_timestamps("eit", {"eit": 36000.0, "emg": 35998.0})
print(offsets) # {'eit': 0.0, 'emg': -2.0}
session.synchronize_raw_modalities(offset_seconds=offsets, reference_modality="eit")
Use a function of your own#
The session methods can run a function of your own in place of a processing step:
Argument |
Session methods |
|---|---|
|
|
|
|
|
|
A detector function gets the processed data and gives a list of breaths. M3Resp changes each breath into a BreathEvent. A breath can be a (start_time, end_time) pair or a dictionary:
def my_detector(data, **kwargs):
return [(1.0, 4.0), (4.0, 7.5)]
breaths = session.detect_eit_breaths(detector=my_detector)
Continue with Move from eitprocessing.