Skip to content

Commit 44d4807

Browse files
committed
skipping channels with bad edge detections
1 parent c3bea9f commit 44d4807

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

neo/rawio/openephysbinaryrawio.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ def _parse_header(self):
263263
rising_indices = []
264264
falling_indices = []
265265

266-
# all channels are packed into the same `states` array.
266+
# all channels are packed into the same `states` array.
267267
# So the states array includes positive and negative values for each channel:
268-
# for example channel one rising would be +1 and channel one falling would be -1,
268+
# for example channel one rising would be +1 and channel one falling would be -1,
269269
# channel two rising would be +2 and channel two falling would be -2, etc.
270270
# This is the case for sure for version >= 0.6.x.
271271
for channel in channels:
@@ -280,6 +280,15 @@ def _parse_header(self):
280280
if rising.size > falling.size:
281281
rising = rising[:-1]
282282

283+
# ensure that the number of rising and falling edges are the same:
284+
if len(rising) != len(falling):
285+
warn(
286+
f"Channel {channel} has {len(rising)} rising edges and "
287+
f"{len(falling)} falling edges. The number of rising and "
288+
f"falling edges should be equal. Skipping events from this channel."
289+
)
290+
continue
291+
283292
rising_indices.extend(rising)
284293
falling_indices.extend(falling)
285294

@@ -292,11 +301,11 @@ def _parse_header(self):
292301
falling_indices = falling_indices[sorted_order]
293302

294303
durations = None
295-
if len(rising_indices) == len(falling_indices):
296-
durations = timestamps[falling_indices] - timestamps[rising_indices]
297-
if not self._use_direct_evt_timestamps:
298-
timestamps = timestamps / info["sample_rate"]
299-
durations = durations / info["sample_rate"]
304+
# if len(rising_indices) == len(falling_indices):
305+
durations = timestamps[falling_indices] - timestamps[rising_indices]
306+
if not self._use_direct_evt_timestamps:
307+
timestamps = timestamps / info["sample_rate"]
308+
durations = durations / info["sample_rate"]
300309

301310
info["rising"] = rising_indices
302311
info["timestamps"] = timestamps[rising_indices]

0 commit comments

Comments
 (0)