Repository: mne-tools/mne-bids-pipeline

Issue:
Missing Baseline interval Check 
I think there is a missing check which should have followed the reading of the config file:

![image](https://user-images.githubusercontent.com/38733898/120214697-1ff2e780-c235-11eb-90fa-bfcb71f401d6.png)

After having set the baseline to (-1, 0), I should have been warned immediately that this won't be compatible with the epochs data.


Discussion:
Ok, I've been looking at how we can correct this.  At first, it seemed to me that fixing this problem would be quite easy since the `_check_baseline` function is a utility function that already exists in mne-python: it would be enough to add a check just after the declaration of the config file, and not just wait until the last moment. 

But we would need to use the `_read_evoked` function (because read_evoked returns among other things `times` and `info[sfreq]` which are necessary arguments of `_check_baseline`), i.e. we would read all the data by looping over the subjects. I don't know if this is desirable. What do you think?

Also, to be consistent this would mean that all the other checks of the other parameters of the config file would have to be done right after the configuration file, which is not possible.

you can make it simple just do

evoked = epochs.average()
# check baseline here
evoked = evoked.apply_baseline(baseline)

>

Wait wait wait, am I missing something here? To me it seems we could do an extremely simple check within `config.py`, something like:

```python
if baseline[0] < epochs_tmin or baseline[1] > epochs_tmax:
    raise
```

No?

Resolving patch:
diff --git a/config.py b/config.py
--- a/config.py
+++ b/config.py
@@ -2,6 +2,7 @@
 but instead create a new configuration changing only the settings you need to
 alter for your specific analysis.
 """
+
 import importlib
 import pathlib
 import functools
@@ -1386,6 +1387,48 @@ def get_t1_from_meeg(bids_path):
     raise ValueError(msg)
 
 
+def check_baseline(
+    *,
+    baseline: Tuple[Optional[float], Optional[float]],
+    epochs_tmin: float,
+    epochs_tmax: float
+) -> None:
+    """Raises error if baseline not compatible with [epochs_tmin, epochs_tmax].
+
+    Parameters
+    ----------
+    baseline
+        Tuple indicating the beginning and end of the baseline interval.
+    epochs_tmin
+        Beginning of Epochs.
+    epochs_tmax
+        End of Epochs.
+
+    Raises
+    ------
+    ValueError
+        if baseline not contained in [epochs_tmin, epochs_tmax].
+        if baseline is not a correct time-interval.
+    """
+    if ((baseline[0] is not None and baseline[0] < epochs_tmin) or
+            (baseline[1] is not None and baseline[1] > epochs_tmax)):
+        msg = (f'baseline {baseline} outside of epochs interval '
+               f'{[epochs_tmin, epochs_tmax]}.')
+
+        raise ValueError(msg)
+
+    if ((baseline[0] is not None) and
+            (baseline[1] is not None) and
+            (baseline[0] >= baseline[1])):
+        msg = (f'The end of the baseline period must occur after its start, '
+               f'but you set baseline={baseline}')
+        raise ValueError(msg)
+
+
+check_baseline(baseline=baseline, epochs_tmin=epochs_tmin,
+               epochs_tmax=epochs_tmax)
+
+
 ###############################################################################
 # Helper functions
 # ----------------


Test patch: