Aligning timestamps across Gemini system

Aligning timestamps across Gemini system

In our previous Neural Signal Processor (NSP) systems, our data was saved in a single NEV/NS* file (depending on your settings) that combined the neural data along with the analog and digital inputs from the NSP hardware on one timescale. However, the Gemini system instead uses hubs that each save their own files alongside the NSP saving the analog and digital inputs in its own files. 

In general, the data will be stored similarly as before, where the gap between each sample will be consistent across the session and data recorded across multiple hubs and the NSP. Therefore, synchronization will utilize the same sample number across the different data files.

However, as each hub's file(s) and the NSP's file will be operating using different clocks, there are instances where the data may need slight alignment for analysis purposes when trying to synchronize. This may be done to align data to specific analog inputs in the NSP or compare neural data on channels across multiple hubs for example. This alignment is done using a similar process in Matlab using the NPMK scripts or python using the brpylib library.
For more information regarding the difference in time structure using Gemini hubs compared to the previous systems, please review this article regarding PTP data alignment

Info

Matlab/NPMK

To include timestamps for the continuous data in NPMK, use the following command and select your datafile:
openNSx('noalign')

This will create a struct for the data with the name "NS*" with the * referring to your data file type. In the struct under NS*.Time is all the timestamps listed sequentially from the beginning to the end of the recording. These values are based off of clock values in picosecond precision and will move forward in time.

If you save this struct with a variable name, you can repeat that command and open structs with your other hub(s)'s data and the NSP analog/digital data. You can use the Time variable in each struct as a way to find the closest timestamps in each file and find the difference between clock values to align the data together. That difference can also be used in the NEV struct to align the timestamps for spikes as well.


Idea

Python/BrPyLib

To include timestamps for the continuous data in BrPyLib, use the following commands:
import numpy as np
from brpylib import NsxFile

nsx = NsxFile()
out = nsx.getdata()

res    = nsx.basic_header["TimeStampResolution"]
period = nsx.basic_header["Period"]

timestamps = np.concatenate([
    (seg["Timestamp"] + np.arange(seg["NumDataPoints"]) * period) / res
    for seg in out["data_headers"]
])

nsx.close()

The timestamps variable will contain the timestamps for the data in that section. You can repeat this process for the different hub/NSP files and compare the timestamps to find the closest ones that match time-wise according to the clocks to align your data. The difference between the different clocks can also be used to align the NEV files as well.
If you are having any trouble with handling the files or have additional questions about aligning the data, reach out to our support team at support@blackrockneuro.com.