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

Neuropixels Dataset Time Alignment Notes #31

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

Neuropixels Dataset Time Alignment Notes #31

weiglszonja opened this issue Dec 2, 2024 · 0 comments

Comments

@weiglszonja
Copy link
Collaborator

weiglszonja commented Dec 2, 2024

Neuropixels Dataset

Data streams

  • Bpod output (.mat)
  • OpenEphys recordings (AP, LFP streams)
  • Kilosort/Phy spike sorting output
  • Processed spike sorting data ("S", "SU" structs)

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/J076/DataFiles/J076_RWTautowait2_20231212_145250.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]
>>> [19.988, 39.7154, 43.6313, 46.8732, 59.4011, 77.7451, 79.4653]

NIDAQ trial start time

The aligned trial start times can be accessed from the processed behavior data using the "Cled" field.

 from pymatreader import read_mat

S_struct_data = read_mat("J076_2023-12-12.mat")["S"] # should contain "S" named struct
# "Cled" field contains the aligned onset and offset times for each trial [2 x ntrials]
center_port_onset_times = [center_port_times[0] for center_port_times in S_struct_data["Cled"]]
center_port_offset_times = [center_port_times[1] for center_port_times in S_struct_data["Cled"]]
center_port_onset_times[:7]
>>> [48.57017236918037, 68.2978722016674, 72.2138230625031, 75.45578122765313, 87.98392024937102, 106.3281781420765, 108.04842315623304]

Alignment

We are aligning the starting time of the recording and sorting interfaces to the Bpod interface.

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

time_shift = bpod_trial_start_times[0] - center_port_onset_times[0]
>>> -28.58217236918037

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

recording_folder_path = "J076_2023-12-12_14-52-04/Record Node 117"
ap_stream_name = "Record Node 117#Neuropix-PXI-119.ProbeA-AP"
recording_interface = OpenEphysRecordingInterface(recording_folder_path, ap_stream_name)

unaligned_timestamps = recording_interface.get_timestamps()
unaligned_timestamps[:7]
>>> [29.74, 29.74003333, 29.74006667, 29.7401, 29.74013333, 29.74016667, 29.7402]

aligned_timestamps = unaligned_timestamps + time_shift
>>> [1.15782763, 1.15786096, 1.1578943 , 1.15792763, 1.15796096, 1.1579943 , 1.15802763]
  1. When the time shift is negative and the first aligned timestamp of the recording 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 recording nor the center_port_onset_times and center_port_offset_times
  1. When the time shift is negative and the first aligned timestamp of the recording trace is positive
  • we move the recording, center_port_onset_times and center_port_offset_times backward
  1. When time shift is positive
  • we move the recording, center_port_onset_times and center_port_offset_times 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