diff --git a/moseq2_ephys_sync/ttl.py b/moseq2_ephys_sync/ttl.py index 642d952..8be166e 100644 --- a/moseq2_ephys_sync/ttl.py +++ b/moseq2_ephys_sync/ttl.py @@ -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): """ @@ -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 \ No newline at end of file