Repository: cbinyu/bidsphysio

Issue:
Request: CMRR .log files
Hello all,

I would like to use this package to convert physio files exported from CMRR multi-Band sequences to the BIDS format. However, when the data were acquired, the physio files were exported as .log files (*_ECG.log, *_RESP.log, *_PULS.log, *_Info.log).

Would it be possible to have these files as input for physio2bidsphysio?

Thank you in advance for your help,

Discussion:

Patch:
diff --git a/bidsphysio.dcm2bids/bidsphysio/dcm2bids/dcm2bidsphysio.py b/bidsphysio.dcm2bids/bidsphysio/dcm2bids/dcm2bidsphysio.py
index 335251b..254a31c 100644
--- a/bidsphysio.dcm2bids/bidsphysio/dcm2bids/dcm2bidsphysio.py
+++ b/bidsphysio.dcm2bids/bidsphysio/dcm2bids/dcm2bidsphysio.py
@@ -213,10 +213,13 @@ def parse_log(physio_log, verbose=False):
                 waveform_name = p3
 
             if 'SampleTime' in p1:
-                dt = float(p3)
+                # 'SampleTime' is in units of 2.5 ms
+                # 'dt' is in ms:
+                dt = 2.5 * float(p3)
 
             if 'PULS' in p2 or 'RESP' in p2:
-                t_list.append(int(p1))
+                # The times are in multiples of 2.5 ms
+                t_list.append(2.5 * int(p1))
                 # in principle, these will also be int, but let's make them
                 #  float to support more general signals:
                 s_list.append(float(p3))
@@ -230,7 +233,8 @@ def parse_log(physio_log, verbose=False):
                     header_read = True
                 elif parts[4] == '0':
                     # (we only save trigger data for the first echo: the other echoes are the same)
-                    t_list.append(int(parts[2]))
+                    # The times are in multiples of 2.5 ms
+                    t_list.append(2.5 * int(parts[2]))
                     if parts[0] == vol:
                         # same volume as before:
                         s_list.append(0)


Test patch:
diff --git a/bidsphysio.dcm2bids/tests/test_dcm2bidsphysio.py b/bidsphysio.dcm2bids/tests/test_dcm2bidsphysio.py
index b558b3b..65d90f4 100644
--- a/bidsphysio.dcm2bids/tests/test_dcm2bidsphysio.py
+++ b/bidsphysio.dcm2bids/tests/test_dcm2bidsphysio.py
@@ -106,9 +106,9 @@ def test_parse_log():
     waveform_name, t, s, dt = d2bp.parse_log(physio_log_lines)
 
     assert waveform_name == expected_LogDataType
-    assert all(t == expected_times)
+    assert all(t == [2.5 * e for e in expected_times])    # the "SampleTime" is in units of 2.5 ms
     assert all(s == expected_signals)
-    assert dt == expected_SampleTime
+    assert dt == 2.5 * expected_SampleTime   # the "SampleTime" is in units of 2.5 ms
 
     ###   Test trigger signal   ###
     expected_LogDataType = 'ACQUISITION_INFO'
@@ -131,9 +131,9 @@ def test_parse_log():
     waveform_name, t, s, dt = d2bp.parse_log(physio_log_lines)
 
     assert waveform_name == expected_LogDataType
-    assert all(t == expected_times)
+    assert all(t == [2.5 * e for e in expected_times])    # the "SampleTime" is in units of 2.5 ms
     assert all(s == expected_signals)
-    assert dt == expected_SampleTime
+    assert dt == 2.5 * expected_SampleTime   # the "SampleTime" is in units of 2.5 ms
 
     # Note: if parse_log tried to incorrectly add the "don't log this: repeated echo"
     #       as time, it would give a "ValueError: invalid literal for int() with base 10"
@@ -171,8 +171,8 @@ def test_dcm2bids(
     # Check that we have as many signals as expected (2, for this file):
     check_bidsphysio_outputs(outbids,
                              ['cardiac', 'respiratory'],
-                             [500, 125],
-                             -1.632,
+                             [200, 50],
+                             -4.082,
                              TESTS_DATA_PATH / 'dcm_')
 
     # 2) Two DICOM infiles: It should give an error:
@@ -209,6 +209,6 @@ def test_dcm2bids(
     # (we don't check the content of the .tsv file):
     check_bidsphysio_outputs(outbids,
                              ['cardiac', 'respiratory'],
-                             [500, 125],
-                             -2.83,
+                             [200, 50],
+                             -7.077,
                              None)