Repository: physiopy/phys2bids

Issue:
Add (resampled) trigger channel in every multifreq output
<!--- Provide a general summary of the issue in the Title above -->
This comes from #219. It would be a good idea (not mandatory, but good) to add a refactored trigger channel in each output in case of multiple outputs due to multifrequency files.
At the moment we're not doing it!

## Context / Motivation
<!--- Why is this change important to you? How would you use it? -->
<!--- How can it benefit other users? -->
It would help improving (visual) comparison between traces and fMRI trigger!

## Possible Implementation
<!--- Not obligatory, but suggest an idea for implementing addition or change -->
<!--- If you already have worked on the idea, please share a link to the branch in your forked project -->
- [ ] Create a resampled trigger channel for each (unique) frequency encountered in `BlueprintInput.freq` list (e.g. with `set(BlueprintInput.freq)` or `np.unique(BlueprintInput.freq)`) and append it to the channel list. This could be a class method.

Discussion:

Patch:
diff --git a/phys2bids/phys2bids.py b/phys2bids/phys2bids.py
index 1860e84..006ce80 100644
--- a/phys2bids/phys2bids.py
+++ b/phys2bids/phys2bids.py
@@ -377,6 +377,13 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None,
                 phys_out[key].timeseries.insert(0, np.linspace(phys_in[run].timeseries[0][0],
                                                 phys_in[run].timeseries[0][-1],
                                                 num=phys_out[key].timeseries[0].shape[0]))
+            # Add trigger channel in the proper frequency.
+            if uniq_freq != phys_in[run].freq[chtrig]:
+                phys_out[key].ch_name.insert(1, phys_in[run].ch_name[chtrig])
+                phys_out[key].units.insert(1, phys_in[run].units[chtrig])
+                phys_out[key].timeseries.insert(1, np.interp(phys_out[key].timeseries[0],
+                                                             phys_in[run].timeseries[0],
+                                                             phys_in[run].timeseries[chtrig]))
             phys_out[key] = BlueprintOutput.init_from_blueprint(phys_out[key])
 
         # Preparing output parameters: name and folder.


Test patch:
diff --git a/phys2bids/tests/test_integration.py b/phys2bids/tests/test_integration.py
index 07bd323..6afc152 100644
--- a/phys2bids/tests/test_integration.py
+++ b/phys2bids/tests/test_integration.py
@@ -45,7 +45,7 @@ def test_integration_acq(skip_integration, samefreq_full_acq_file):
         assert isfile(join(test_path, 'Test_belt_pulse_samefreq' + suffix))
 
     # Check files in extra are generated
-    for suffix in ['.log']:  #, '_trigger_time.png']:
+    for suffix in ['.log']:
         assert isfile(join(conversion_path, 'Test_belt_pulse_samefreq' + suffix))
 
     # Read log file (note that this file is not the logger file)
@@ -168,7 +168,7 @@ def test_integration_heuristic(skip_integration, multifreq_lab_file):
     # Compares values in json file with ground truth
     assert math.isclose(json_data['SamplingFrequency'], 40.0,)
     assert math.isclose(json_data['StartTime'], 3.6960,)
-    assert json_data['Columns'] == ['time', 'O2']
+    assert json_data['Columns'] == ['time', 'Trigger', 'O2']
 
     # ##### Checks for 100 Hz files
     # Read log file (note that this file is not the logger file)
@@ -195,7 +195,7 @@ def test_integration_heuristic(skip_integration, multifreq_lab_file):
     # Compares values in json file with ground truth
     assert math.isclose(json_data['SamplingFrequency'], 100.0,)
     assert math.isclose(json_data['StartTime'], 3.6960,)
-    assert json_data['Columns'] == ['time', 'CO2']
+    assert json_data['Columns'] == ['time', 'Trigger', 'CO2']
 
     # Remove generated files
     shutil.rmtree(test_path_output)