Skip to content

Commit 5c54fd9

Browse files
authored
Merge pull request #1470 from h-mayorquin/add_possiblity_of_reading_file
Add the possilibity of opening intan files even if corrupted.
2 parents 13a90b9 + 7a53c7e commit 5c54fd9

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

neo/rawio/intanrawio.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
"""
2020

2121
from pathlib import Path
22-
import os
23-
from collections import OrderedDict
2422
from packaging.version import Version as V
2523
import warnings
2624

@@ -44,8 +42,12 @@ class IntanRawIO(BaseRawIO):
4442
Parameters
4543
----------
4644
filename: str, default: ''
47-
name of the 'rhd' or 'rhs' data file
48-
45+
name of the 'rhd' or 'rhs' data file
46+
ignore_integrity_checks: bool, default: False
47+
If True, data that violates integrity assumptions will be loaded. At the moment the only integrity
48+
check we perform is that timestamps are continuous. Setting this to True will ignore this check and set
49+
the attribute `discontinuous_timestamps` to True if the timestamps are not continous. This attribute can be checked
50+
after parsing the header to see if the timestamps are continuous or not.
4951
Notes
5052
-----
5153
* Intan reader can handle two file formats 'rhd' and 'rhs'. It will automatically
@@ -84,10 +86,13 @@ class IntanRawIO(BaseRawIO):
8486
extensions = ["rhd", "rhs", "dat"]
8587
rawmode = "one-file"
8688

87-
def __init__(self, filename=""):
89+
def __init__(self, filename="", ignore_integrity_checks=False):
8890

8991
BaseRawIO.__init__(self)
9092
self.filename = filename
93+
self.ignore_integrity_checks = ignore_integrity_checks
94+
self.discontinuous_timestamps = False
95+
9196

9297
def _source_name(self):
9398
return self.filename
@@ -186,11 +191,18 @@ def _parse_header(self):
186191
elif self.file_format == "one-file-per-channel":
187192
time_stream_index = max(self._raw_data.keys())
188193
timestamp = self._raw_data[time_stream_index][0]
189-
190-
if not np.all(np.diff(timestamp) == 1):
191-
raise NeoReadWriteError(
192-
f"Timestamp have gaps, this could be due to a corrupted file or an inappropriate file merge"
193-
)
194+
195+
discontinuous_timestamps = np.diff(timestamp) != 1
196+
timestamps_are_not_contiguous = np.any(discontinuous_timestamps)
197+
if timestamps_are_not_contiguous:
198+
self.discontinuous_timestamps = True
199+
if not self.ignore_integrity_checks:
200+
error_msg = (
201+
"Timestamps are not continuous, this could be due to a corrupted file or an inappropriate file merge. "
202+
"Initialize the reader with `ignore_integrity_checks=True` to ignore this error and open the file. \n"
203+
f"Timestamps around discontinuities: {timestamp[discontinuous_timestamps]}"
204+
)
205+
raise NeoReadWriteError(error_msg)
194206

195207
# signals
196208
signal_channels = []

0 commit comments

Comments
 (0)