def __load_chn_data(self,selectChan,file_name):
spk_startswith = "spike_{0}".format(selectChan)
with hp.File(file_name,"r") as f:
times = list()
waveforms = list()
units = list()
for chn_unit in f["spikes"].keys():
if chn_unit.startswith(spk_startswith):
tep_time = f["spikes"][chn_unit]["times"].value
waveform = f["spikes"][chn_unit]["waveforms"].value
unit = int(chn_unit.split("_")[-1])
unit = np.ones(tep_time.shape,dtype=np.int32)*unit
times.append(tep_time)
waveforms.append(waveform)
units.append(unit)
if times:
times = np.hstack(times)
units = np.hstack(units)
waveforms = np.vstack(waveforms)
sort_index = np.argsort(times)
units = units[sort_index]
waveforms = waveforms[sort_index]
times = times[sort_index]
# calculate waveform_range
waveforms_max = np.apply_along_axis(max,1,waveforms)
waveforms_min = np.apply_along_axis(min,1,waveforms)
waveforms_range = np.vstack([waveforms_min,waveforms_max]).T
# calculate PCA of waveforms
scaler = StandardScaler()
scaler.fit(waveforms)
waveforms_scaled = scaler.transform(waveforms)
pca = PCA(n_components=self.pca_used_num)
pca.fit(waveforms_scaled)
wavePCAs = pca.transform(waveforms_scaled)
return times,units,waveforms_range,wavePCAs
else:
return None,None,None,None
评论列表
文章目录