Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiber Photometry Dataset Time Alignment Notes #30

Open
weiglszonja opened this issue Dec 2, 2024 · 0 comments
Open

Fiber Photometry Dataset Time Alignment Notes #30

weiglszonja opened this issue Dec 2, 2024 · 0 comments

Comments

@weiglszonja
Copy link
Collaborator

weiglszonja commented Dec 2, 2024

Fiber Photometry Dataset

Data streams

  • Bpod output (.mat)
  • Video from behavioral camera (.mp4)
  • DeepLabCut output (.h5)
  • Fiber photometry from Doric system(.doric or .csv)

Session start time

The session start time is the reference time for all timestamps in the NWB file. We are using session_start_time from the Bpod output. (The start time of the session in the Bpod data can be accessed from the "Info" struct, with "SessionDate" and "SessionStartTime_UTC" fields.)

Bpod trial start time

We are extracting the trial start times from the Bpod output using the "TrialStartTimestamp" field.

 from pymatreader import read_mat

 bpod_data = read_mat("raw_Bpod/J069/DataFiles/J069_RWTautowait2_20230809_131216.mat")["SessionData"] # should contain "SessionData" named struct

 # The trial start times from the Bpod data
 bpod_trial_start_times = bpod_data['TrialStartTimestamp']
bpod_trial_start_times[:7]
>>> [ 11.4261, 104.5276, 146.0112, 203.5646, 211.7232, 215.3226, 224.041 ]

Doric trial start time

The trial start times from the Doric acquisition can be obtained from one of the digital signals ("DigitalIO/DIO02" in .doric file, "DI/O-2" in .csv file).

import h5py
from neuroconv.tools.signal_processing import get_rising_frames_from_ttl

doric_file = h5py.File("J069_ACh_20230809_HJJ_0002.doric", mode="r")
ttl_signal = doric_file["/DataAcquisition/FPConsole/Signals/Series0001/DigitalIO/DIO02"][:]
timestamps = doric_file["/DataAcquisition/FPConsole/Signals/Series0001/DigitalIO/Time"][:]

rising_frames_from_center_port_ttl = get_rising_frames_from_ttl(ttl_signal)
num_trials = len(rising_frames_from_center_port_ttl)
doric_trial_start_times = [timestamps[rising_frames_from_center_port_ttl][i] for i in range(num_trials)]
doric_trial_start_times[:7]
>>> [17.11626, 110.21736, 151.702835, 209.255035, 217.41393499999998, 221.01406, 229.73321]

Alignment

We are aligning the starting time of the fiber photometry, video and DLC interfaces to the Bpod interface.

We are computing the time shift from the Bpod trial start time to the Doric trial start time.

For example, the computed time shift for this session:

time_shift = bpod_trial_start_times[0] - doric_trial_start_times[0]
>>> -5.6901600000000006

We are applying this time_shift to the timestamps for the raw fluorescence signals as:

doric_timestamps = doric_file["/DataAcquisition/FPConsole/Signals/Series0001/AnalogIn/Time"][:]
aligned_timestamps = doric_timestamps + time_shift
  1. When the time shift is negative and the first aligned timestamp of the doric trace is negative:
  • shift back bpod (from every column that has a timestamp they have to be shifted back)
  • shift back session start time
  • don't have to move doric or video
  1. When the time shift is negative and the first aligned timestamp of the doric trace is positive
  • we move the doric and video backward
  1. When time shift is positive
  • we move the doric and video forward
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant