def display_apply(self,widget): color = self.builder.get_object('colorbutton1') r = color.get_color().red_float g = color.get_color().green_float b = color.get_color().blue_float self.line_color = self.color = (r,g,b) self.prefs['LineColor'] = self.line_color color = self.builder.get_object('colorbutton2') r = color.get_color().red_float g = color.get_color().green_float b = color.get_color().blue_float self.back_color = (r,g,b) self.prefs['BackColor'] = self.back_color readwrite.writedata(self.prefs, os.getenv('HOME')+'/.pymeg') self.numofch = int(self.builder.get_object("spinbutton1").get_value()) self.chanind2plot = \ self.chanind[self.curchannel:self.curchannel+self.numofch] self.chanlabels2plot = \ self.chanlabels[self.curchannel:self.curchannel+self.numofch] st = float(self.builder.get_object("spinbutton2").get_value()) ed = float(self.builder.get_object("spinbutton3").get_value()) self.space = float(self.builder.get_object("entry1").get_text()) self.scalefact = float(self.builder.get_object("entry2").get_text()) #print 'se',st,ed, self.t startind = nearest.nearest(self.t,st)[0] stopind = nearest.nearest(self.t,ed)[0] print 'se',startind,stopind self.check_scale(startind,stopind) self.space_data() self.redraw(None)
def fft_method(self, data, srate, epochs): from meg import fftmeg,nearest '''fftmeg.calc(p.data.data_block, p.data.srate,epochs=p.data.numofepochs)''' fftout = fftmeg.calc(data, srate,epochs=epochs) cut_low = nearest.nearest(fftout.freq,self.hz_range[0])[0] cut_high = nearest.nearest(fftout.freq,self.hz_range[1])[0] self.result = fftout.pow[cut_low:cut_high]
def tftplot(self, type='P', aspect='auto', eventoffset=None, freq=None): ''' tftplot types type = 'P' for power type = 'Plog' for logpower type = 'itc' for phaselockingfactor type = 'itcreal' for realphaselockingfactor type = 'Ptrials' for nonaveraged power. power X trial type = 'Evoked Power' for evoked power eventoffset = 1000*p.data.eventtime[0] ''' print 'type of plot', type from pylab import imshow, show, colorbar, xlabel, ylabel if type == 'P' or type == 'Power': data = abs(self.P) #if iscomplexobj(data): if type == 'Plog' or type == 'Log Power': data = abs(self.Plog) if type == 'Evoked Power': try: onsetind = nearest.nearest(self.timevals,0)[0] print onsetind data = abs(self.P) / array([mean(abs(self.P[:,:onsetind]),axis=1)]).T except: 'cant do that dave' if type == 'Induced Power': try: onsetind = nearest.nearest(self.timevals,0)[0] print onsetind evoked = abs(self.P) / array([mean(abs(self.P[:,:onsetind]),axis=1)]).T data = abs(self.P) - evoked except: 'cant do that dave' if type == 'itc' or type == 'Inter Trial Coherence': data = abs(self.itcvals) if type == 'itcreal' or type == 'Phase': data = real(self.itcvals) if type == 'Ptrials' or type == 'Trial Power': #power per trial data = abs(self.Ptrials) if type == 'trialphase' or type == 'Trial Phase': ind = nearest.nearest(self.freqs, freq) data = squeeze(real(self.Ptrials[ind])).reshape((self.trials,self.npoints),order='C') xlab = 'time' ylab = 'trials' if eventoffset != None: self.timevals = self.timevals+eventoffset imshow(data,aspect=aspect, extent=(int(self.timevals[0]), int(self.timevals[-1]), \ int(self.freqrange[1]), int(self.freqrange[0]))); try: xlabel(xlab) ylabel(ylab) except: pass show() #colorbar() return data
def selection_to_ind(sels,sele,inc): print 'getting sel' if sele == sels: #only one point selected sele = sels+inc nearest.nearest(self.t,arange(sels,sele,inc)) sel_ind = nearest.nearest(self.t,arange(sels,sele,inc)) return sel_ind
def runoffsetcorrect(self,widget):#, callback=None): start = self.builder.get_object('entry1').get_text() end = self.builder.get_object('entry2').get_text() self.startind = nearest.nearest(self.eventtime,start)[0] self.endind = nearest.nearest(self.eventtime,end)[0] print 'offset correcting data', self.startind, self.endind for i in range(self.numofepochs): print 'epoch',i+1# i*self.frames, (i*self.frames)+self.frames, self.startind, self.endind epoch_data = self.data[i*self.frames:(i*self.frames)+self.frames,:] tmp = offset.correct(epoch_data, start=self.startind, end=self.endind) try: outdata = vstack((outdata,tmp)) except UnboundLocalError: outdata = copy(tmp) try: self.callback(outdata) except (TypeError,NameError): pass
def epoch_data(self,widget): print widget.get_label() prestim_sec = float(self.builder.get_object("entry1").get_text()) poststim_sec = float(self.builder.get_object("entry2").get_text()) prestim_ind = nearest.nearest(self.wintime,prestim_sec)[0] poststim_ind = nearest.nearest(self.wintime,poststim_sec)[0] #print prestim_ms,poststim_ms ind = self.result_ind.values()[0] print 'epoch', ind,prestim_ind startcut = ind-prestim_ind endcut = ind+poststim_ind try:self.callback(widget,startcut,endcut) except: pass return epoched = self.data[ind-prestim_ind:ind+poststim_ind] print epoched.shape,'shape'
def showpopupmenu(self,widget,event): print('button ',event.button) if event.button == 3: m = self.builder.get_object("menufunctions") print(widget, event) m.show_all() m.popup(None,None,None,3,0) if event.button == 1: ap = self.axes.get_position() x,y = self.canvas.get_width_height() posx = (event.x/x-.5)*(1/(ap.x1-ap.x0))*-1 posy = ((event.y/y-.5)*(1/(ap.y0-ap.y1))) #posx = ((event.x/x)-ap.x0)*(1/(ap.x1-ap.x0)) #posy = ((event.y/y)-(1-ap.y0))*(1/(ap.y0-ap.y1)) print posx,posy from meg import nearest nx=nearest.nearest(self.data[0],posy)[0] ny=nearest.nearest(self.data[1],posx)[0] print nx,ny
def ind_logic(ind_dict, timediff, timeseries): result_ind = [];finalind = [] ts = timeseries for i in range(0,len(ind_dict.keys())): if i == 0: result_ind = ind_dict[0] else: print('cur key num',i) prime_timeind = ts[ind_dict[0]] #first ind array second_timeind = ts[ind_dict[i]] #every ind array including first nind = unique(nearest(prime_timeind,second_timeind)) rind = unique(nearest(second_timeind,prime_timeind)) print 'debug', prime_timeind,second_timeind,nind,rind for j,k in zip(nind,rind): n1 = prime_timeind[j] #n2 = nearest(ts[second_timeind[j]] print 'jk', j,k try: n2 = second_timeind[k] except IndexError: print('Error, so bailing');return unique(result_ind) c = 0 print 'ns...',n1,n2 while n2 < n1: #look for second trigger to be equal or later than first c = c + 1 try: n2 = second_timeind[k+c] #make sure n2 index is after n1 and not just the closest. print 'n2',n2 except IndexError: break print 'looking at next ind' if (n2 - n1) <= timediff and n2-n1 > 0: print 'diff',n2 - n1,timediff print 'adding', j finalind.append(result_ind[j]) else: pass;#result_ind = delete(result_ind,j) return unique(finalind)
def button_press_event(self,widget,event): self.get_cursor_position(event) #print 'button pushed',event.button,event.type if event.type == gtk.gdk.BUTTON_PRESS: print "single click" if event.button == 1: self.xstart = self.sx #elif event.type == gtk.gdk._2BUTTON_PRESS: #print "double click" #elif event.type == gtk.gdk._3BUTTON_PRESS: #print "triple click. ouch, you hurt your user." if event.type == gtk.gdk.BUTTON_PRESS and event.button == 2: closest_data = nearest.nearest(self.data2plot[0,:],self.sy) print 'nearest',closest_data print 'highlighting channel' self.axes.axhspan(self.data2plot[:,closest_data].min(), \ self.data2plot[:,closest_data].max(), xmin=0, xmax=1, color='g',\ alpha=0.2) self.canvas.draw() self.specaxes.cla() NFFT = 1024 Fs = self.srate #(1/self.srate) print NFFT,int(Fs),'d' self.specaxes.specgram( self.data2plot[:,closest_data[0]], NFFT=NFFT, Fs=Fs,noverlap=900) #self.specaxes.axis('off') self.speccanvas.draw() self.csdaxes.csd(self.time, self.data2plot[:,closest_data[0]], NFFT=NFFT, Fs=Fs) #, noverlap=Noverlap, #cmap=cm.jet)#, xextent=xextent) #self.csdaxes.axis('off') self.csdcanvas.draw()