moabb icon indicating copy to clipboard operation
moabb copied to clipboard

Merge p300 process_raw and base paradigm process_raw

Open jsosulski opened this issue 4 years ago • 1 comments
trafficstars

For some reason the process_raw method exists for base and p300 paradigms individually but both methods are highly similar. We should consider splitting the method and overwrite only a part of it in the p300.py file.

The current state makes writing patches somewhat tedious, as both locations in the code need to be updated simultaneously.

jsosulski avatar Apr 08 '21 14:04 jsosulski

When diffing only the relevant code sections I get the following diff:

--- <base.py>
+++ <p300.py>
@@ -6,22 +6,22 @@
         if len(stim_channels) > 0:
             events = mne.find_events(raw, shortest_event=0, verbose=False)
         else:
-            try:
-                events, _ = mne.events_from_annotations(
-                    raw, event_id=event_id, verbose=False
-                )
-            except ValueError:
-                log.warning("No matching annotations in {}".format(raw.filenames))
-                return
+            events, _ = mne.events_from_annotations(raw, verbose=False)
+
+        channels = () if self.channels is None else self.channels
 
         # picks channels
-        if self.channels is None:
-            picks = mne.pick_types(raw.info, eeg=True, stim=False)
-        else:
-            picks = mne.pick_types(raw.info, stim=False, include=self.channels)
+        picks = mne.pick_types(raw.info, eeg=True, stim=False, include=channels)
+
+
 
         # pick events, based on event_id
         try:
+            if type(event_id["Target"]) is list and type(event_id["NonTarget"]) == list:
+                event_id_new = dict(Target=1, NonTarget=0)
+                events = mne.merge_events(events, event_id["Target"], 1)
+                events = mne.merge_events(events, event_id["NonTarget"], 0)
+                event_id = event_id_new
             events = mne.pick_events(events, include=list(event_id.values()))
         except RuntimeError:
             # skip raw if no event found
@@ -64,7 +64,6 @@
                 preload=True,
                 verbose=False,
                 picks=picks,
-                event_repeated="drop",
                 on_missing="ignore",
             )
             if bmin < tmin or bmax > tmax:

As far as I can tell only the part where Target/NonTarget events are picked are specific to P300. The remaining differences seem to be caused by updates to only one of the files, or is there another reason I do not see here @sylvchev ?

jsosulski avatar Apr 09 '21 06:04 jsosulski