From 19362394f18fac1a945e292f7a20ec5361bd6bb9 Mon Sep 17 00:00:00 2001 From: Samuel Garcia Date: Sun, 17 Mar 2024 15:31:00 +0100 Subject: [PATCH 1/2] Protect against corrupted channels in legacy openephys. --- neo/rawio/openephysrawio.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/neo/rawio/openephysrawio.py b/neo/rawio/openephysrawio.py index 38824d4f7..e9a8f29bc 100644 --- a/neo/rawio/openephysrawio.py +++ b/neo/rawio/openephysrawio.py @@ -141,6 +141,12 @@ def _parse_header(self): np.median(diff) == RECORD_SIZE ), f"This file has a non valid data block size for channel {chan_id}, this case cannot be handled" + diff = np.diff(data_chan["timestamp"]) + channel_has_corrupted_timestamps = np.any(diff <= 0) + if channel_has_corrupted_timestamps: + # protect against corrupted timestamp in channel + raise ValueError(f"{ch_name} has corrputed timestamps, this channels need to be moved away from the folder") + if seg_index == 0: # add in channel list if ch_name[:2].upper() == "CH": From 784b3f9bad1637308b3d816b84a3931a32f30e1f Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Fri, 5 Apr 2024 16:06:52 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Szonja Weigl --- neo/rawio/openephysrawio.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/neo/rawio/openephysrawio.py b/neo/rawio/openephysrawio.py index e9a8f29bc..3d4b781d3 100644 --- a/neo/rawio/openephysrawio.py +++ b/neo/rawio/openephysrawio.py @@ -141,11 +141,10 @@ def _parse_header(self): np.median(diff) == RECORD_SIZE ), f"This file has a non valid data block size for channel {chan_id}, this case cannot be handled" - diff = np.diff(data_chan["timestamp"]) channel_has_corrupted_timestamps = np.any(diff <= 0) if channel_has_corrupted_timestamps: # protect against corrupted timestamp in channel - raise ValueError(f"{ch_name} has corrputed timestamps, this channels need to be moved away from the folder") + raise ValueError(f"{ch_name} has timestamps with zero values or negative differences between consecutive timestamps, this file ({continuous_filename}) with corrupted timestamps needs to be moved away from the folder.") if seg_index == 0: # add in channel list