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

Trial-based drift in spike time alignment #271

Open
kushalbakshi opened this issue Feb 6, 2023 · 0 comments
Open

Trial-based drift in spike time alignment #271

kushalbakshi opened this issue Feb 6, 2023 · 0 comments

Comments

@kushalbakshi
Copy link

When aligning unit spike times to timestamps for the "go" cue in BehavioralEvents, there is a consistent ~ 7.5 ms drift per trial clear visible in the event-aligned raster attached below. This issue was submitted by a user performing secondary analysis on the NWB files exported from the MAP pipeline on DANDI archive. The following script was used for generating the raster plots:

import os
from pynwb import NWBHDF5IO
import numpy as np
import matplotlib.pyplot as plt

dataDir = r""
sub = r'sub-484677'
date = r'sub-484677_ses-20210420T170516_behavior+ecephys+ogen.nwb'
fpath = os.path.join(dataDir,sub,date)
nwbfile = NWBHDF5IO(fpath).read()

unit = 0

alignEvent = 'go_start_times'
before = 3  # in seconds
after = 3
alignTimes = nwbfile.acquisition['BehavioralEvents'][alignEvent].timestamps[:]

spkwv = nwbfile.units['waveform_mean'][unit]

spktm = nwbfile.units['spike_times'][unit]
N = len(spktm)
trial_spikes = []
nspks = 0
for trix,time in enumerate(alignTimes):
    # align spike times
    spktm_aligned = spktm - time - 0.0075*trix # estimated drift correction
    # spktm_aligned = spktm - time

    # Keep only spike times in a given time window around the stimulus onset
    spktm_aligned = spktm_aligned[
        (-before < spktm_aligned) & (spktm_aligned < after)
    ]
    trial_spikes.append(spktm_aligned)

fig, axs = plt.subplots(2, 1, sharex="all", figsize=(6,3))
plt.xlabel("time from go cue (s)")
axs[0].eventplot(trial_spikes)

axs[0].set_ylabel("trial")
quality = nwbfile.units['unit_quality'].data[:][unit]
axs[0].set_title(f"unit {unit} | quality: {quality} | nSpikes: {N}")
axs[0].axvline(0, color=[0.5, 0.5, 0.5])

axs[1].hist(np.hstack(trial_spikes), 100)
axs[1].axvline(0, color=[0.5, 0.5, 0.5])
axs[1].set_ylabel('Spikes / bin')
plt.show()

fig, ax = plt.subplots(1, 1, figsize=(2,1))
ax.plot(spkwv)
plt.xlabel("samples")
ax.set_ylabel("mV")
plt.show()

Raster with drift:
image

Raster with correction applied:
image

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