Ejemplo n.º 1
0
 def grange(self):
     '''plot range'''
     if self.randial==None: 
         from spectrax import RangeDial
         self.randial=RangeDial(self.graph.axes)
     else:
         self.randial.read_axes(self.graph.axes)
     self.randial.exec_()
     self.graph.hscale=[self.randial.xmin.value(),self.randial.xmax.value()]
     self.graph.vscale=[self.randial.ymin.value(),self.randial.ymax.value()]
     self.graph.axes.set_xlim(*self.graph.hscale)
     self.calib.axes.set_xlim(*self.graph.hscale)
     self.graph.axes.set_ylim(*self.graph.vscale)
     self.graph.draw()
     self.calib.draw()
Ejemplo n.º 2
0
class GraphWindow(QtGui.QMainWindow):
    '''window containing 2 canvases
    '''
    instr=None
    stack={}
    erange=[1,3647] #depends later on spectroscope connected
    emin,emax=1.13,2.8
    xunit=0
    rebins=None
    anrange=None

    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowTitle("application main window")
        if hasattr(rc,'meas_range'): self.emin,self.emax=rc.meas_range #only in eV?
        self.main_widget = QtGui.QWidget(self)
        self.graph = MyDynamicMplCanvas(self.main_widget, width=8, height=6, dpi=100)
        self.calib = MyStaticMplCanvas(self.main_widget, width=8, height=4, dpi=100)
        self.graph.parent=self # link back for communication
        self.graph.change_sizes()
        self.calib.change_sizes()
        return
        
    def grange(self):
        '''plot range'''
        if self.randial==None: 
            from spectrax import RangeDial
            self.randial=RangeDial(self.graph.axes)
        else:
            self.randial.read_axes(self.graph.axes)
        self.randial.exec_()
        self.graph.hscale=[self.randial.xmin.value(),self.randial.xmax.value()]
        self.graph.vscale=[self.randial.ymin.value(),self.randial.ymax.value()]
        self.graph.axes.set_xlim(*self.graph.hscale)
        self.calib.axes.set_xlim(*self.graph.hscale)
        self.graph.axes.set_ylim(*self.graph.vscale)
        self.graph.draw()
        self.calib.draw()
        
    def onselect(self, xmin, xmax):
        if self.toolbar.hZoom:
            #self.graph.axes.set_ylim(ymax = self.localYMax)
            self.graph.axes.set_xlim(xmin,xmax)
            if self.instr!=None and self.instr.flat!=None: 
                self.calib.axes.set_xlim(xmin,xmax)
                self.calib.axes.grid(1)
                self.calib.draw()
            self.graph.draw()
        self.graph.hscale=(xmin,xmax) 
        #self.graph.vscale=(xmin,xmax) 
        
    def set_binning(self):
        d, ok = QtGui.QInputDialog.getInteger(self, self.tr("binning"),self.tr("nb. of bins"), 20, 0, 1000, 10)
        if ok: 
            nbins=int(d)
            if d<0:
                self.rebins=None
                return
            step=(self.instr.pixtable[-1]-self.instr.pixtable[0])/nbins
            self.rebins=((self.instr.pixtable-self.instr.pixtable[0])/step).astype('int')
            self.rebins[-1]=self.rebins[-2]
    #ndimage.mean(y,spectrac.aw.rebins,range(19))

    def get_vscale(self,imin=None,imax=None):
        '''min/max value of all displayed graphs
        '''
        data=[f.get_ydata()[imin:imax] for f in list(self.stack.values()) if f.get_visible()]
        if len(data)==0 and self.instr.last!=None: data.append(self.instr.last[imin:imax])
        if len(data)==0:
            alert(self,"No data plotted")
            return 0,0
        #if self.graph.last: data.append(self.graph.last.get_ydata()[imin:imax])
        return [min([d.min() for d in data]),max([d.max() for d in data])]

    def reset(self,exten=0.2):
        if self.stack!=None and len(self.stack)>0: 
            self.graph.hscale=list(self.stack.values())[0].axes.dataLim.get_points()[:,0]
        else: 
            if self.xunit==1: self.graph.hscale=[self.instr.pixtable[0],self.instr.pixtable[-1]]
            else: self.graph.hscale=[self.instr.pixtable[-1],self.instr.pixtable[0]]
        self.graph.vscale=self.get_vscale()
        vspan=(self.graph.vscale[1]-self.graph.vscale[0])*exten
        self.graph.vscale=[self.graph.vscale[0]-vspan,self.graph.vscale[1]+vspan]
        self.graph.axes.set_xlim(*self.graph.hscale)
        self.calib.axes.set_xlim(*self.graph.hscale)
        self.graph.axes.set_ylim(*self.graph.vscale)
        self.graph.axes.grid(1)
        self.calib.axes.grid(1)
        self.graph.draw()
        self.calib.draw()
        
    def adjust_vert(self,exten=0,use_stack=True):
        ''' should adjust according to all graphs plotted
        '''
        if exten==0: exten=rc.vert_exten
        from spectra import get_ids
        if self.instr: 
            imin,imax=get_ids(self.instr.pixtable,self.graph.axes.get_xlim())
            #print "using range %i / %i"%(imin,imax)
        elif len(self.stack)>0:
            ite=list(self.stack.keys())[0]
            imin,imax=get_ids(self.stack[ite].get_xdata(),self.graph.axes.get_xlim())
        else: imin,imax=None,None
        self.graph.vscale=self.get_vscale(imin,imax)
        xlim=self.graph.axes.get_xlim()
        
        data=[f.get_ydata()[imin:imax] for f in list(self.stack.values())]
        if self.instr and self.instr.last!=None: data.append(self.instr.last[imin:imax])
        elif self.graph.last: data.append(self.graph.last.get_ydata()[imin:imax])
        if len(data)==0: return 
        self.graph.vscale=[min([d.min() for d in data]),max([d.max() for d in data])]
        vspan=(self.graph.vscale[1]-self.graph.vscale[0])*exten
        self.graph.vscale=[self.graph.vscale[0]-vspan,self.graph.vscale[1]+vspan]
        self.graph.axes.set_ylim(self.graph.vscale[0],self.graph.vscale[1])
        self.graph.axes.set_xlim(min(xlim),max(xlim))
        self.graph.draw()
        #self.graph.axes.grid(1)

    def analplot(self):
        '''show analytic range
        '''
        if self.anrange==None: return
        if self.graph.analbar:
        #if self.showanal.checkState()>0:
            self.showanal.setChecked(0)
            for a in self.graph.axes.patches:
                    self.graph.axes.patches.remove(a)
            #self.graph.analbar.remove()
            self.graph.analbar=None
        else:
            self.showanal.setChecked(1)
            pos=[self.instr.pixtable[self.anrange[0]],self.instr.pixtable[self.anrange[1]]]
            self.graph.analbar=self.graph.axes.axvspan(pos[0],pos[1],facecolor='g',alpha=0.2)
        self.graph.draw()
        if self.graph.hscale: self.graph.axes.set_xlim(*self.graph.hscale)
            
    def clear(self):
        self.graph.clear()
        self.stack.clear()