Skip to content

Commit 281e37b

Browse files
author
Thinh Nguyen
committed
bugfix in waveform extraction for OpenEphys
1 parent 3452ab7 commit 281e37b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

elements_ephys/readers/openephys.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,20 @@ def extract_spike_waveforms(self, spikes, channel, n_wf=500, wf_win=(-32, 32)):
144144
:param bit_volts: scalar required to convert int16 values into microvolts (default of 1)
145145
:return: waveforms (sample x channel x spike)
146146
"""
147-
147+
data = self.ap_data.T # (sample x channel)
148148
channel_ind = [np.where(self.ap_meta['channels_ids'] == chn)[0][0] for chn in channel]
149149

150150
# ignore spikes at the beginning or end of raw data
151151
spikes = spikes[np.logical_and(spikes > (-wf_win[0] / self.ap_meta['sample_rate']),
152-
spikes < (wf_win[-1] / self.ap_meta['sample_rate']))]
152+
spikes < (self.ap_timestamps.max() - wf_win[-1] / self.ap_meta['sample_rate']))]
153153
# select a randomized set of "n_wf" spikes
154154
np.random.shuffle(spikes)
155155
spikes = spikes[:n_wf]
156156
# extract waveforms
157157
if len(spikes) > 0:
158158
spike_indices = np.searchsorted(self.ap_timestamps, spikes, side="left")
159159
# waveform at each spike: (sample x channel x spike)
160-
spike_wfs = np.dstack([self.ap_data[int(spk + wf_win[0]):int(spk + wf_win[-1]), channel_ind]
160+
spike_wfs = np.dstack([data[int(spk + wf_win[0]):int(spk + wf_win[-1]), channel_ind]
161161
for spk in spike_indices])
162162
return spike_wfs
163163
else: # if no spike found, return NaN of size (sample x channel x 1)

0 commit comments

Comments
 (0)