spikesorting.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号