Skip to content

Commit

Permalink
Convert ephys times to sec within workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahpearl committed Sep 9, 2021
1 parent aed6b05 commit 882f019
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions moseq2_ephys_sync/ttl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from glob import glob
import sync
import pdb

def ttl_workflow(base_path, save_path, num_leds, led_blink_interval, ephys_fs):
"""
Expand All @@ -18,12 +19,14 @@ def ttl_workflow(base_path, save_path, num_leds, led_blink_interval, ephys_fs):
# (This is a bit of a glitch in open ephys, might be able to remove this in future versions)
continuous_timestamps_path = glob('%s/**/continuous/**/timestamps.npy' % base_path,recursive = True)[0] ## load the continuous stream's timestamps
continuous_timestamps = np.load(continuous_timestamps_path)
ephys_timestamps -= continuous_timestamps[0] # subract the first timestamp from all TTLs; this way continuous ephys can safely start at 0 samples or seconds
ephys_timestamps -= continuous_timestamps[0] # subract the first timestamp from all TTLs; this way continuous ephys can safely start at 0 samples or seconds
ephys_timestamps = ephys_timestamps / ephys_fs

ttl_channels = [-4,-3,-2,-1,1,2,3,4]
print('Assuming sync leds in ttl channels 1-4...')
ttl_bool = np.isin(channels, ttl_channels)
ephys_events = np.vstack([ephys_timestamps[ttl_bool], abs(channels[ttl_bool])-1, np.sign(channels[ttl_bool])]).T
codes, ephys_latencies = sync.events_to_codes(ephys_events, nchannels=num_leds, minCodeTime=(led_blink_interval-1)*ephys_fs)
codes, ephys_latencies = sync.events_to_codes(ephys_events, nchannels=num_leds, minCodeTime=(led_blink_interval-1))
codes = np.asarray(codes)

return codes

0 comments on commit 882f019

Please sign in to comment.