Skip to content

Commit

Permalink
allow user to set predicted peak index
Browse files Browse the repository at this point in the history
  • Loading branch information
dmeliza committed Apr 10, 2017
1 parent 3e2feaa commit 5d20b5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions quickspikes/tools.py
Expand Up @@ -13,13 +13,15 @@ def filter_times(times, min, max):
return tuple(t for t in times if (t > min) and (t < max))


def realign_spikes(times, spikes, upsample, jitter=1, reflect_fft=False):
def realign_spikes(times, spikes, upsample, jitter=1, reflect_fft=False, expected_peak=None):
"""Realign spikes to their peaks using bandwidth-limited resampling
times : one-dimensional array of spike times, in units of samples
spikes : array of spike waveforms, with dimensions (nspikes, npoints)
upsample : integer, the factor by which to upsample the data for realignment
jitter : samples (in original data) to search for true peak
expected_peak : if supplied, searches around this index for the peak. If not supplied,
uses the argmax of the mean spike
Returns (times, spikes), with the sampling rate increased by a factor of upsample
Expand All @@ -30,7 +32,8 @@ def realign_spikes(times, spikes, upsample, jitter=1, reflect_fft=False):
nevents, nsamples = spikes.shape

# first infer the expected peak time
expected_peak = mean(spikes, 0).argmax() * upsample
if expected_peak is None:
expected_peak = mean(spikes, 0).argmax() * upsample
spikes = fftresample(spikes, int(nsamples * upsample), reflect=reflect_fft)
# find peaks within upsample samples of mean peak
shift = find_peaks(spikes, expected_peak, upsample * jitter)
Expand Down Expand Up @@ -71,7 +74,7 @@ def fftresample(S, npoints, axis=1, reflect=False):
if reflect:
Srev = S[:, ::-1]
S = column_stack([Srev, S, Srev])
npoints *= 3
npoints = npoints * 3
Sf = rfft(S, axis=axis)
Srs = (1. * npoints / S.shape[axis]) * irfft(Sf, npoints, axis=axis)
if reflect:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -24,7 +24,7 @@

setup(
name = 'quickspikes',
version = '1.3.1',
version = '1.3.2',
packages=find_packages(exclude=["*test*"]),
ext_modules = [_spikes],
cmdclass = {'build_ext': build_ext},
Expand Down

0 comments on commit 5d20b5f

Please sign in to comment.