2020"""
2121
2222from pathlib import Path
23- import os
24- from collections import OrderedDict
2523from packaging .version import Version
2624import warnings
2725
@@ -44,8 +42,12 @@ class IntanRawIO(BaseRawIO):
4442 Parameters
4543 ----------
4644 filename: str, default: ''
47- name of the 'rhd' or 'rhs' data/header file
48-
45+ name of the 'rhd' or 'rhs' data/header 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 * The Intan reader can handle two file formats 'rhd' and 'rhs'. It will automatically
@@ -99,10 +101,13 @@ class IntanRawIO(BaseRawIO):
99101 extensions = ["rhd" , "rhs" , "dat" ]
100102 rawmode = "one-file"
101103
102- def __init__ (self , filename = "" ):
104+ def __init__ (self , filename = "" , ignore_integrity_checks = False ):
103105
104106 BaseRawIO .__init__ (self )
105107 self .filename = filename
108+ self .ignore_integrity_checks = ignore_integrity_checks
109+ self .discontinuous_timestamps = False
110+
106111
107112 def _source_name (self ):
108113 return self .filename
@@ -202,11 +207,18 @@ def _parse_header(self):
202207 elif self .file_format == "one-file-per-channel" :
203208 time_stream_index = max (self ._raw_data .keys ())
204209 timestamp = self ._raw_data [time_stream_index ][0 ]
205-
206- if not np .all (np .diff (timestamp ) == 1 ):
207- raise NeoReadWriteError (
208- f"Timestamp have gaps, this could be due to a corrupted file or an inappropriate file merge"
209- )
210+
211+ discontinuous_timestamps = np .diff (timestamp ) != 1
212+ timestamps_are_not_contiguous = np .any (discontinuous_timestamps )
213+ if timestamps_are_not_contiguous :
214+ self .discontinuous_timestamps = True
215+ if not self .ignore_integrity_checks :
216+ error_msg = (
217+ "Timestamps are not continuous, this could be due to a corrupted file or an inappropriate file merge. "
218+ "Initialize the reader with `ignore_integrity_checks=True` to ignore this error and open the file. \n "
219+ f"Timestamps around discontinuities: { timestamp [discontinuous_timestamps ]} "
220+ )
221+ raise NeoReadWriteError (error_msg )
210222
211223 # signals
212224 signal_channels = []
0 commit comments