From 6143e40986d71c945a8d6865776ddc1141c7e750 Mon Sep 17 00:00:00 2001 From: smathot Date: Tue, 26 Mar 2024 17:08:59 +0100 Subject: [PATCH] Check for duplicate triggers within trials --- eeg_eyetracking_parser/_triggers.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/eeg_eyetracking_parser/_triggers.py b/eeg_eyetracking_parser/_triggers.py index e45209a..d9d565e 100644 --- a/eeg_eyetracking_parser/_triggers.py +++ b/eeg_eyetracking_parser/_triggers.py @@ -68,4 +68,15 @@ def _validate_events(events): codes = events[:, 2] if np.any((codes < 1) | (codes > 255)): raise ValueError('trigger codes should be values between 1 and 255') + # Check for duplicate triggers within trials + trialid = -1 + triggers = [] + for code in codes: + if code >= 128: + trialid += 1 + triggers = [] + if code in triggers: + raise ValueError( + f'duplicate trigger {code} in trial {trialid}, label {hex(255 - 128 - trialid % 128)}') + triggers.append(code) return events