def gtCompare(gtSpikes,data,bitmasks): avg,avgB,u = [],[],0 for spk in gtSpikes: for i,mask in enumerate(bitmasks): if u == 0: avg.append(0.0) avgB.append(np.median(roip.find_avg_over_tc(data,mask))) avg[i] += (sum(roip.find_avg_over_tc(data[spk:spk+10],mask))/10.0)-avgB[i] u = 1 return avg
def saveSingleSpkTrain(event): click = plt.ginput(1,300) if typ == 2: j = match_point(click,self.bitmasks) if self.t == 0: train,spikes,self.fil = roip.spikeDet(self.tc_data,self.bitmasks[j]) self.t = 1 elif self.t == 1: train,spikes = roip.spikeDetL(self.tc_data,self.bitmasks[j],self.fil) arch = [train,spikes] print 'What would you like to name the data from this ROI?' name = raw_input('> ') np.save(name,arch)
def showSpikes(event): click = plt.ginput(1,300) if typ == 2: j = match_point(click,self.bitmasks) if self.t == 0: train,spikes,self.fil = roip.spikeDet(self.tc_data,self.bitmasks[j]) self.t = 1 elif self.t == 1: train,spikes = roip.spikeDetL(self.tc_data,self.bitmasks[j],self.fil) else: print 'Something is wrong.' #self.plo = plt.figure(2) self.ax_plot.plot(train) self.ax_plot.plot(spikes,np.ones(np.size(spikes))*35000,'r.') print 'Spiketimes for ROI '+str(j)+': ',spikes if typ == 3: print 'Not currently supported.'
def corCompare(fluor,data,bitmasks): r = [] for mask in bitmasks: tc = roip.find_avg_over_tc(data,mask) r.append(pearsonr(fluor,tc)) return r #def deleteMultiDetection_backup(bitmasks,data): """back up of a different way of dealing with multiple detections of the same physical ROI across z.""" """
def saveAllSpkTrains(event): arch = [] if typ == 2: for j in range(len(self.bitmasks)): print 'Mask '+str(j+1)+' of '+str(len(self.bitmasks)) if self.t == 0: train,spikes,self.fil = roip.spikeDet(self.tc_data,self.bitmasks[j]) self.t = 1 else: train,spikes = roip.spikeDetL(self.tc_data,self.bitmasks[j],self.fil) arch.append([train,spikes]) elif typ == 3: for roi in self.prinROI: if self.t == 0: train,spikes,self.fil = roip.spikeDet(self.tc_data,self.bitmasks[roi[0]][roi[1]]) else: train,spikes = roip.spikeDetL(self.tc_data,bitmasks[roi[0]][roi[1]],self.fil) self.t = 1 arch.append([roi,train,spikes]) print 'What would you like to name this dataset?' name = raw_input('> ') np.save(name,arch)
def deleteMultiDetection(bitmasks,data): """finds unique ROIs in three dimensions, returns a list of indices of the principal z-slice of all ROIs as well as changes the bitmasks such that points not in the region are zero and points in the region are the same non-zero as all points in the ROI across the z-axis. for example, if a and b are ROI on different but adjacent z-slices and their centres are close enough such that the algorithm believes them to be duplicates of the same cell body, both arrays will have the same integer value in all points considered in the region.""" prinROI,saveROI = [],[] count = 1 for i in xrange(len(bitmasks)): for j in xrange(len(bitmasks[i])): if len(np.where(bitmasks[i][j] == 1)[0]) != 0: a = np.where(bitmasks[i][j] == 1) xavg1,yavg1 = np.mean(a[0]),np.mean(a[1]) sameROILoc = [[i,j]] avg = [roip.find_avg_at_t(data[i],bitmasks[i][j])] for k in xrange(i+1,len(bitmasks)-1): q = 0 for l in xrange(len(bitmasks[k])): b = np.where(bitmasks[k][l] >= 1) xavg2,yavg2 = np.mean(b[0]),np.mean(b[1]) if abs(xavg1 - xavg2) < bitmasks[i][j].shape[0]*.1 and abs(yavg1-yavg2) < bitmasks[i][j].shape[1]*.1: sameROILoc.append([k,l]) avg.append(roip.find_avg_at_t(data[k],bitmasks[k][l])) q = 1 if q == 0: #saveROI.append(sameROILoc[np.argmax(avg)]) #sameROILoc = np.delete(sameROILoc,np.argmax(avg),0) count += 1 prinROI.append(sameROILoc[np.argmax(avg)]) for z in xrange(len(sameROILoc)): bitmasks[sameROILoc[z][0]][sameROILoc[z][1]] = np.where(bitmasks[sameROILoc[z][0]][sameROILoc[z][1]] >= 1,count,0) break prinROI = [list(ro) for ro in set(tuple(roi) for roi in prinROI)] prinROI.sort() return bitmasks,prinROI