Skip to content

Commit 7323b97

Browse files
committed
more informative message for duplicate calibration events. calibration match string can now be user defined
1 parent a3385b4 commit 7323b97

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

mne_bids_pipeline/_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,11 @@
12161216
```
12171217
"""
12181218

1219+
sync_calibration_string: str | None = ".* Recalibration (start|end) \\| (.*)"
1220+
"""
1221+
Regular expression used for searching for calibration events
1222+
"""
1223+
12191224
# ### SSP, ICA, and artifact regression
12201225

12211226
regress_artifact: dict[str, Any] | None = None

mne_bids_pipeline/steps/preprocessing/_05b_sync_eyelink.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ def _check_HEOG_ET_vars(cfg):
3535

3636
return heog_ch, et_ch, bipolar
3737

38-
def _mark_calibration_as_bad(raw):
38+
def _mark_calibration_as_bad(raw, cfg):
3939
# marks recalibration beginnings and ends as one bad segment
4040
cur_idx = None
4141
cur_start_time = 0.
4242
last_status = None
4343
for annot in raw.annotations:
44-
calib_match = re.match(".* Recalibration (start|end) \\| (.*)", annot["description"])
44+
calib_match = re.match(cfg.sync_calibration_string, annot["description"])
4545
if not calib_match: continue
4646
calib_status, calib_idx = calib_match.group(1), calib_match.group(2)
4747
if calib_idx == cur_idx and calib_status == "end":
@@ -52,9 +52,10 @@ def _mark_calibration_as_bad(raw):
5252
cur_idx = calib_idx
5353
cur_start_time = annot["onset"]
5454
elif calib_status == last_status:
55-
logger.info(**gen_log_kwargs(message=f"Encountered apparent duplicate calibration event - skipping"))
55+
logger.info(**gen_log_kwargs(message=f"Encountered apparent duplicate calibration event ({calib_status}, {calib_idx}) - skipping"))
5656
elif calib_status == "start" and cur_idx is not None:
57-
raise ValueError(f"Annotation {annot["description"]} could not be assigned membership")
57+
raise ValueError(f"Annotation {annot["description"]} could not be assigned membership"
58+
f"")
5859
last_status = calib_status
5960

6061
return raw
@@ -249,7 +250,7 @@ def sync_eyelink(
249250
# create bipolar HEOG
250251
raw = mne.set_bipolar_reference(raw, *cfg.sync_heog_ch, ch_name=heog_ch, drop_refs=False)
251252
raw.filter(l_freq=cfg.sync_heog_highpass, h_freq=cfg.sync_heog_lowpass, picks=heog_ch) # get rid of drift and high freq noise
252-
_mark_calibration_as_bad(raw)
253+
_mark_calibration_as_bad(raw, cfg)
253254
# extract HEOG and ET as arrays
254255
heog_array = raw.get_data(picks=[heog_ch], reject_by_annotation="omit")
255256
et_array = raw.get_data(picks=et_ch, reject_by_annotation="omit")
@@ -347,6 +348,7 @@ def get_config(
347348
sync_heog_highpass = config.sync_heog_highpass,
348349
sync_heog_lowpass = config.sync_heog_lowpass,
349350
sync_plot_samps = config.sync_plot_samps,
351+
sync_calibration_string = config.sync_calibration_string,
350352
processing= "filt" if config.regress_artifact is None else "regress",
351353
_raw_split_size=config._raw_split_size,
352354

0 commit comments

Comments
 (0)