Skip to content

Commit c647153

Browse files
Supporting multimodal datasets. (#191)
* Supporting multimodal datasets. * Linting * Running ICALabel only for EEG.
1 parent 5236a77 commit c647153

File tree

4 files changed

+157
-61
lines changed

4 files changed

+157
-61
lines changed

pylossless/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
@pytest.fixture(scope="session")
2121
def pipeline_fixture():
22-
"""Return a namedTuple containing MNE eyetracking raw data and events."""
22+
"""Return a LosslessPipeline object."""
2323
raw, config, bids_path = load_openneuro_bids()
2424
# raw.crop(tmin=0, tmax=60) # Too short for ICA to converge in some tests.
2525
annots = Annotations(

pylossless/flagging.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ def add_flag_cat(self, kind, bad_ch_names, *args):
115115
logger.debug(f"NEW BAD CHANNELS {bad_ch_names}")
116116
if isinstance(bad_ch_names, xr.DataArray):
117117
bad_ch_names = bad_ch_names.values
118-
self[kind] = bad_ch_names
118+
if kind in self:
119+
self[kind] = list(np.unique(np.concatenate((self[kind], bad_ch_names))))
120+
else:
121+
self[kind] = bad_ch_names
122+
119123

120124
def get_flagged(self):
121125
"""Return a list of channels flagged by the lossless pipeline."""
@@ -138,9 +142,12 @@ def rereference(self, inst, **kwargs):
138142
"""
139143
# Concatenate and remove duplicates
140144
bad_chs = list(
141-
set(self.ll.find_outlier_chs(inst) + self.get_flagged() + inst.info["bads"])
145+
set(self.ll.find_outlier_chs(inst, picks="eeg") +
146+
self.get_flagged() +
147+
inst.info["bads"])
142148
)
143-
ref_chans = [ch for ch in inst.copy().pick("eeg").ch_names if ch not in bad_chs]
149+
ref_chans = [ch for ch in inst.copy().pick("eeg").ch_names
150+
if ch not in bad_chs]
144151
inst.set_eeg_reference(ref_channels=ref_chans, **kwargs)
145152

146153
def save_tsv(self, fname):
@@ -223,7 +230,10 @@ def add_flag_cat(self, kind, bad_epoch_inds, epochs):
223230
The :class:`mne.Epochs` object created from the Raw object that is
224231
being assessed by the LosslessPipeline.
225232
"""
226-
self[kind] = bad_epoch_inds
233+
if kind in self:
234+
self[kind] = list(np.unique(np.concatenate((self[kind], bad_epoch_inds))))
235+
else:
236+
self[kind] = bad_epoch_inds
227237
self.ll.add_pylossless_annotations(bad_epoch_inds, kind, epochs)
228238

229239
def load_from_raw(self, raw, events, config):

0 commit comments

Comments
 (0)