Skip to content

Commit

Permalink
Use systime timestamps for digital mark data
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelbray32 committed Aug 20, 2023
1 parent d120a4a commit 388b82b
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/spikegadgets_to_nwb/spike_gadgets_raw_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
) # TODO the import location was updated for this notebook

import numpy as np

from scipy.stats import linregress
from xml.etree import ElementTree


Expand Down Expand Up @@ -535,7 +535,10 @@ def get_digitalsignal(self, stream_id, channel_id):
# 0 when there is change from 1 to 0

# track the timestamps when there is a change from 0 to 1 or 1 to 0
timestamps = self.get_analogsignal_timestamps(i_start, i_stop)
if self.sysClock_byte:
timestamps = self._get_regressesed_systime(i_start, i_stop)
else:
timestamps = self.get_analogsignal_timestamps(i_start, i_stop)
dio_change_times = timestamps[np.where(change_dir)[0] + 1]

# insert the first timestamp with the first value
Expand All @@ -548,3 +551,26 @@ def get_digitalsignal(self, stream_id, channel_id):
# raw_unit16 = raw_unit16[:, re_order]

return dio_change_times, change_dir_trim

def _get_regressesed_systime(self, i_start, i_stop):
NANOSECONDS_PER_SECOND = 1e9
# get values
systime = self.get_sys_clock(i_start, i_stop)
trodestime = self.get_analogsignal_timestamps(i_start, i_stop)
# Convert
systime_seconds = np.asarray(systime).astype(np.float64)
trodestime_index = np.asarray(trodestime).astype(np.float64)

slope, intercept, r_value, p_value, std_err = linregress(
trodestime_index, systime_seconds
)
adjusted_timestamps = intercept + slope * trodestime_index
return (adjusted_timestamps) / NANOSECONDS_PER_SECOND

def _get_systime_from_trodes_timestamps(self, i_start, i_stop):
MILLISECONDS_PER_SECOND = 1e3
# get values
trodestime = self.get_analogsignal_timestamps(i_start, i_stop)
return (trodestime - int(self.timestamp_at_creation)) * (
1.0 / self._sampling_rate
) + int(self.system_time_at_creation) / MILLISECONDS_PER_SECOND

0 comments on commit 388b82b

Please sign in to comment.