Skip to content

Commit f943af8

Browse files
committed
add utility method to get timestamps
1 parent 3845cdc commit f943af8

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

neo/rawio/intanrawio.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,26 @@ def _demultiplex_digital_data(self, raw_digital_data, channel_ids, i_start, i_st
530530
output[:, channel_index] = demultiplex_data[i_start:i_stop].flatten()
531531

532532
return output
533+
534+
def get_intan_timestamps(self):
535+
"""
536+
537+
Retrieves the timestamps from the Intan raw data based on the file format.
538+
Returns
539+
-------
540+
timestamps: ndarray
541+
The flattened array of timestamps.
542+
"""
543+
if self.file_format == "header-attached":
544+
timestamps = self._raw_data["timestamp"]
545+
546+
# timestamps are always last stream for headerless binary files
547+
elif self.file_format == "one-file-per-signal":
548+
timestamps = self._raw_data["timestamp"]
549+
elif self.file_format == "one-file-per-channel":
550+
timestamps = self._raw_data["timestamp"][0]
551+
552+
return timestamps.flatten() if timestamps.ndim > 1 else timestamps
533553

534554
def _assert_timestamp_continuity(self):
535555
"""
@@ -555,16 +575,9 @@ def _assert_timestamp_continuity(self):
555575
* **one-file-per-channel:** Timestamps are retrieved from the first channel of the last stream.
556576
"""
557577
# check timestamp continuity
558-
if self.file_format == "header-attached":
559-
timestamp = self._raw_data["timestamp"].flatten()
560-
561-
# timestamps are always last stream for headerless binary files
562-
elif self.file_format == "one-file-per-signal":
563-
timestamp = self._raw_data["timestamp"]
564-
elif self.file_format == "one-file-per-channel":
565-
timestamp = self._raw_data["timestamp"][0]
578+
timestamps = self.get_intan_timestamps()
566579

567-
discontinuous_timestamps = np.diff(timestamp) != 1
580+
discontinuous_timestamps = np.diff(timestamps) != 1
568581
timestamps_are_not_contiguous = np.any(discontinuous_timestamps)
569582
if timestamps_are_not_contiguous:
570583
# Mark a flag that can be checked after parsing the header to see if the timestamps are continuous or not
@@ -582,8 +595,8 @@ def _assert_timestamp_continuity(self):
582595

583596
amplifier_sampling_rate = self._global_info["sampling_rate"]
584597
for discontinuity_index in np.where(discontinuous_timestamps)[0]:
585-
prev_ts = timestamp[discontinuity_index]
586-
next_ts = timestamp[discontinuity_index + 1]
598+
prev_ts = timestamps[discontinuity_index]
599+
next_ts = timestamps[discontinuity_index + 1]
587600
time_diff = (next_ts - prev_ts) / amplifier_sampling_rate
588601

589602
error_msg += (

0 commit comments

Comments
 (0)