def create_multisession_fet_files(self): if not os.path.exists(self.clustersDir): print 'Creating clusters directory: %s'%(self.clustersDir) os.makedirs(self.clustersDir) if self.samples is None: self.load_all_waveforms() self.featureValues = spikesorting.calculate_features(self.samples,self.featureNames) spikesorting.write_fet_file(self.fetFilename, self.featureValues)
def create_multisession_fet_files(self): if not os.path.exists(self.clustersDir): print 'Creating clusters directory: %s'%(self.clustersDir) os.makedirs(self.clustersDir) if self.samples is None: self.load_waveforms() self.featureValues = spikesorting.calculate_features(self.samples,self.featureNames) spikesorting.write_fet_file(self.fetFilename, self.featureValues)
def __init__(self, samples): self.samples = samples self.points = spikesorting.calculate_features( self.samples, ["peak", "valley", "energy"]) self.fig = plt.figure() self.cloudax = plt.subplot2grid((3, 4), (0, 0), rowspan=2, colspan=2) self.wave0ax = plt.subplot2grid((3, 4), (0, 2), rowspan=1, colspan=1) self.wave1ax = plt.subplot2grid((3, 4), (0, 3), rowspan=1, colspan=1) self.wave2ax = plt.subplot2grid((3, 4), (1, 2), rowspan=1, colspan=1) self.wave3ax = plt.subplot2grid((3, 4), (1, 3), rowspan=1, colspan=1) self.wavaxes = [self.wave0ax, self.wave1ax, self.wave2ax, self.wave3ax] self.loghistax = plt.subplot2grid((3, 4), (2, 0), rowspan=1, colspan=2) self.timehistax = plt.subplot2grid((3, 4), (2, 2), rowspan=1, colspan=2) self.numDims = self.points.shape[1] self.combinations = [ c for c in itertools.combinations(range(self.numDims), 2) ] self.maxDim = len(self.combinations) - 1 #Start with the first combination self.dimNumber = 0 #All points start inside the cluster self.inCluster = np.ones(len(self.points), dtype=bool) self.outsideCluster = np.logical_not(self.inCluster) #Preserve the last cluster state for undo self.oldInsideCluster = self.inCluster self.oldOutsideCluster = self.outsideCluster #Make the fig and ax, and draw the initial plot self.draw_dimension(self.dimNumber) #Start the mouse handle.r and make an attribute to hold click pos self.mpid = self.fig.canvas.mpl_connect('button_press_event', self.on_click) self.cloudMouseClickData = [] #Start the key press handler self.kpid = self.fig.canvas.mpl_connect('key_press_event', self.on_key_press) #Start the handler to monitor the axis that the mouse is over self.axiswatcher = self.fig.canvas.mpl_connect('axes_enter_event', self.on_axis_enter) #show the plot plt.hold(True) self.fig.show()
def __init__(self, samples): self.samples = samples self.points = spikesorting.calculate_features(self.samples, ["peak", "valley", "energy"]) self.fig = plt.figure() self.cloudax = plt.subplot2grid((3, 4), (0, 0), rowspan=2, colspan=2) self.wave0ax = plt.subplot2grid((3, 4), (0, 2), rowspan=1, colspan=1) self.wave1ax = plt.subplot2grid((3, 4), (0, 3), rowspan=1, colspan=1) self.wave2ax = plt.subplot2grid((3, 4), (1, 2), rowspan=1, colspan=1) self.wave3ax = plt.subplot2grid((3, 4), (1, 3), rowspan=1, colspan=1) self.wavaxes = [self.wave0ax, self.wave1ax, self.wave2ax, self.wave3ax] self.loghistax = plt.subplot2grid((3, 4), (2, 0), rowspan=1, colspan=2) self.timehistax = plt.subplot2grid((3, 4), (2, 2), rowspan=1, colspan=2) self.numDims=self.points.shape[1] self.combinations=[c for c in itertools.combinations(range(self.numDims), 2)] self.maxDim=len(self.combinations)-1 #Start with the first combination self.dimNumber=0 #All points start inside the cluster self.inCluster=np.ones(len(self.points), dtype=bool) self.outsideCluster=np.logical_not(self.inCluster) #Preserve the last cluster state for undo self.oldInsideCluster=self.inCluster self.oldOutsideCluster=self.outsideCluster #Make the fig and ax, and draw the initial plot self.draw_dimension(self.dimNumber) #Start the mouse handle.r and make an attribute to hold click pos self.mpid=self.fig.canvas.mpl_connect('button_press_event', self.on_click) self.cloudMouseClickData=[] #Start the key press handler self.kpid = self.fig.canvas.mpl_connect('key_press_event', self.on_key_press) #Start the handler to monitor the axis that the mouse is over self.axiswatcher = self.fig.canvas.mpl_connect('axes_enter_event', self.on_axis_enter) #show the plot plt.hold(True) self.fig.show()
figure() dataplotter.two_axis_heatmap(spikeTimes, eventOnsetTimes, behavData['currentIntensity'], behavData['currentFreq']) title('All Spikes') show() # figure() # spikesorting.plot_waveforms(spikeData.samples) # title('all spikes') # figure() # dataplotter.plot_raster(spikeTimes, eventOnsetTimes) # show() fet = spikesorting.calculate_features(spikeData.samples, ['peak', 'valley', 'energy']) # fet = spikesorting.calculate_features(spikeData.samples, ['peak']) cw = clustercutting.AdvancedClusterCutter(spikeData.samples) cont = raw_input("Press enter to continue") while cont != '': cont = raw_input("Press enter to continue") figure() dataplotter.two_axis_heatmap(spikeTimes[cw.inCluster], eventOnsetTimes, behavData['currentIntensity'], behavData['currentFreq']) title('Selected Spikes') show()
SAVE=True # dbPath = os.path.join(settings.FIGURES_DATA_PATH, figparams.STUDY_NAME, 'celldatabase_ALLCELLS.h5') dbPath = '/tmp/celldatabase_new_20180830.h5' # dbPath = os.path.join(settings.FIGURES_DATA_PATH, figparams.STUDY_NAME, 'celldatabase_ALLCELLS_MODIFIED_CLU.h5') db = pd.read_hdf(dbPath, key='dataframe') cellsToRescue = db.query('autoTagged==1 and isiViolations>0.02 and isiViolations<0.04') for indRow, dbRow in cellsToRescue.iterrows(): cell = ephyscore.Cell(dbRow, useModifiedClusters=False) timestamps, samples, recordingNumber = cell.load_all_spikedata() isiViolations = spikesorting.calculate_ISI_violations(timestamps) print "isi violations: %{}".format(isiViolations*100) print "nSpikes: {}".format(len(timestamps)) featuresMat = spikesorting.calculate_features(samples, ['peakFirstHalf', 'valleyFirstHalf', 'energy']) #Sort by mahalanobis distance to the cluster centroid try: dM = spikesorting.distance_to_centroid(featuresMat) # except LinAlgError, errMsg: #Singular matrix error except: #FIXME: LinAlgError not defined?? continue sortArray = np.argsort(dM) spikesToRemove = 0 thisISIviolation = isiViolations #The isi violations including all the spikes jumpBy = int(len(timestamps)*0.01) #Jump by 1% of spikes each time if jumpBy==0: jumpBy = 1 #Jump by at least 1 spike FIXME: This is probably a terrible cluster if this happens