Esempio n. 1
0
    def __init__(self,graph=True,attach=False,mode='scat',**kwargs):
        QtGui.QMainWindow.__init__(self)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowTitle("Scanning")
        self.main_widget = QtGui.QWidget(self)
        l = QtGui.QVBoxLayout(self.main_widget)
        hl = QtGui.QHBoxLayout()
        if 'parent' in kwargs: 
            self.parent=kwargs['parent']
            exargs=self.parent.control
            self.control=self.parent.control
            self.polar=self.parent.polar
        else: exargs={}
        if graph:
            self.graph = MyStaticMplCanvas(self.main_widget, width=5, height=4, dpi=100, polar=self.polar)
            self.graph.change_sizes()
            self.graph.axes.set_xlabel('X [mm]')
            self.graph.axes.set_ylabel('Y [mm]')
            #if self.data:
            #    self.anal.draw()
            l.addWidget(self.graph)
        self.butts=[]
        for bid in ['Period','Fluct.','Mean','Variab.','Save','Stop']:
            self.butts.append(QtGui.QPushButton(self.tr("&"+bid)))
            #self.attButton.setIcon(ico)
        for b in self.butts: hl.addWidget(b)
        self.connect(self.butts[0], QtCore.SIGNAL("clicked()"), self.show_peri)
        self.connect(self.butts[1], QtCore.SIGNAL("clicked()"), self.show_disp)
        self.connect(self.butts[2], QtCore.SIGNAL("clicked()"), self.show_mean)
        self.connect(self.butts[3], QtCore.SIGNAL("clicked()"), self.show_vari)
        self.connect(self.butts[4], QtCore.SIGNAL("clicked()"), self.save_data)
        self.connect(self.butts[5], QtCore.SIGNAL("clicked()"), self.stop_scan)

        l.addLayout(hl)
        self.main_widget.setFocus()
        self.setCentralWidget(self.main_widget)
        self.statusBar().showMessage("scanning under way")
        if self.polar:
            self.xlim=None
            if 'ny' in exargs: self.ylim=[0,(exargs['ny']-0.5)*self.parent.control['xstep']]
        else:
            if 'xlim' in kwargs: exargs['nx']=kwargs['xlim']
            if 'nx' in exargs: self.xlim=[-0.5*self.parent.control['xstep'],(exargs['nx']-0.5)*self.parent.control['xstep']]
            if 'ylim' in kwargs: exargs['ny']=kwargs['ylim']
            if 'ny' in exargs: self.ylim=[-0.5*self.parent.control['ystep'],(exargs['ny']-0.5)*self.parent.control['ystep']]
        self.clear()
        self.graph.axes.hold(1)
        if self.xlim!=None: 
            self.graph.axes.set_xlim(self.xlim)
            print('setting xlim %.2f-%.2f'%tuple(self.xlim))
        if self.ylim!=None: 
            self.graph.axes.set_ylim(self.ylim)
            print('setting ylim %.2f-%.2f'%tuple(self.ylim))
        self.mode=mode
Esempio n. 2
0
 def __init__(self,graph=True,attach=False,mode='peri'):
     QtGui.QMainWindow.__init__(self)
     self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
     self.setWindowTitle("Data analysis")
     self.main_widget = QtGui.QWidget(self)
     self.mode=mode
     self.file_menu = QtGui.QMenu('&Fourier', self)
     self.menuBar().addMenu(self.file_menu)
     l = QtGui.QVBoxLayout(self.main_widget)
     hl = QtGui.QHBoxLayout()
     hl2 = QtGui.QHBoxLayout()
     
     if mode=='peri':
         self.perButton = QtGui.QPushButton(self.tr("&Period"))
         self.connect(self.perButton, QtCore.SIGNAL("clicked()"), get_period)
         hl.addWidget(self.perButton)
         self.fitButton = QtGui.QPushButton(self.tr("&Fit interval"))
         self.connect(self.fitButton, QtCore.SIGNAL("clicked()"), get_fit)
         hl.addWidget(self.fitButton)
     if attach:
         ico=QtGui.QIcon('E:\\Documents and Settings\\Kremik\\Dokumenty\\attach.png')
         self.attButton = QtGui.QPushButton(self.tr("&Attach"))
         self.attButton.setIcon(ico)
         self.connect(self.attButton, QtCore.SIGNAL("clicked()"), get_period)
         hl.addWidget(self.attButton)
     if mode=='peri':
         self.shapeButton = QtGui.QPushButton(self.tr("&Refract.ind."))
         shapeMenu = QtGui.QMenu(self.tr("refr. index"), self)
         shapeMenu.addAction(self.tr("const"),self.set_const)
         shapeMenu.addAction(self.tr("polynom"),self.set_poly)
         shapeMenu.addAction(self.tr("lorentz"))
         self.shapeButton.setMenu(shapeMenu)
         hl.addWidget(self.shapeButton)
     if mode=='scan' and len(anal_data)>0:
         self.shapeButton = QtGui.QPushButton(self.tr("&Available"))
         shapeMenu = QtGui.QMenu(self.tr("2-D maps"), self)
         for k in list(anal_data.keys()):
             if len(getattr(anal_data[k],'shape',(0,)))==2:
                 shapeMenu.addAction(self.tr("k"),self.show_map)
         self.shapeButton.setMenu(shapeMenu)
         hl.addWidget(self.shapeButton)
         self.vmin = QtGui.QLineEdit()
         self.vmax = QtGui.QLineEdit()
         hl.addWidget(QtGui.QLabel(self.tr(" min.val. ")))
         hl.addWidget(self.vmin)
         hl.addWidget(QtGui.QLabel(self.tr(" max.val. ")))
         hl.addWidget(self.vmax)
     if graph:
         self.anal = MyStaticMplCanvas(self.main_widget, width=5, height=4, dpi=100)
         self.anal.change_sizes()
         #if self.data:
         #    self.anal.draw()
         l.addWidget(self.anal)
     l.addLayout(hl)
     if mode=='peri':
         self.perEdit1 = QtGui.QLineEdit(str(self.period))
         self.perEdit2 = QtGui.QLineEdit(str(self.period))
         self.modeLabel = QtGui.QLabel(self.tr(""))
         perLabel = QtGui.QLabel(self.tr("Period estimate: min "))
         hl2.addWidget(perLabel)
         hl2.addWidget(self.perEdit1)
         perLabel = QtGui.QLabel(self.tr(" max "))
         hl2.addWidget(perLabel)
         hl2.addWidget(self.perEdit2)
         hl2.addWidget(self.modeLabel)
         l.addLayout(hl2)
         self.parLabel = QtGui.QLabel(self.tr("Fitted parameters: <b>None</b>"))
         l.addWidget(self.parLabel)
     
     self.main_widget.setFocus()
     self.setCentralWidget(self.main_widget)
     self.statusBar().showMessage("please choose method")
     global task
     task=self
Esempio n. 3
0
class AnalyseWindow(QtGui.QMainWindow):
    anal=None
    period=''
    data=None
    mode='peri'
    def __init__(self,graph=True,attach=False,mode='peri'):
        QtGui.QMainWindow.__init__(self)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowTitle("Data analysis")
        self.main_widget = QtGui.QWidget(self)
        self.mode=mode
        self.file_menu = QtGui.QMenu('&Fourier', self)
        self.menuBar().addMenu(self.file_menu)
        l = QtGui.QVBoxLayout(self.main_widget)
        hl = QtGui.QHBoxLayout()
        hl2 = QtGui.QHBoxLayout()
        
        if mode=='peri':
            self.perButton = QtGui.QPushButton(self.tr("&Period"))
            self.connect(self.perButton, QtCore.SIGNAL("clicked()"), get_period)
            hl.addWidget(self.perButton)
            self.fitButton = QtGui.QPushButton(self.tr("&Fit interval"))
            self.connect(self.fitButton, QtCore.SIGNAL("clicked()"), get_fit)
            hl.addWidget(self.fitButton)
        if attach:
            ico=QtGui.QIcon('E:\\Documents and Settings\\Kremik\\Dokumenty\\attach.png')
            self.attButton = QtGui.QPushButton(self.tr("&Attach"))
            self.attButton.setIcon(ico)
            self.connect(self.attButton, QtCore.SIGNAL("clicked()"), get_period)
            hl.addWidget(self.attButton)
        if mode=='peri':
            self.shapeButton = QtGui.QPushButton(self.tr("&Refract.ind."))
            shapeMenu = QtGui.QMenu(self.tr("refr. index"), self)
            shapeMenu.addAction(self.tr("const"),self.set_const)
            shapeMenu.addAction(self.tr("polynom"),self.set_poly)
            shapeMenu.addAction(self.tr("lorentz"))
            self.shapeButton.setMenu(shapeMenu)
            hl.addWidget(self.shapeButton)
        if mode=='scan' and len(anal_data)>0:
            self.shapeButton = QtGui.QPushButton(self.tr("&Available"))
            shapeMenu = QtGui.QMenu(self.tr("2-D maps"), self)
            for k in list(anal_data.keys()):
                if len(getattr(anal_data[k],'shape',(0,)))==2:
                    shapeMenu.addAction(self.tr("k"),self.show_map)
            self.shapeButton.setMenu(shapeMenu)
            hl.addWidget(self.shapeButton)
            self.vmin = QtGui.QLineEdit()
            self.vmax = QtGui.QLineEdit()
            hl.addWidget(QtGui.QLabel(self.tr(" min.val. ")))
            hl.addWidget(self.vmin)
            hl.addWidget(QtGui.QLabel(self.tr(" max.val. ")))
            hl.addWidget(self.vmax)
        if graph:
            self.anal = MyStaticMplCanvas(self.main_widget, width=5, height=4, dpi=100)
            self.anal.change_sizes()
            #if self.data:
            #    self.anal.draw()
            l.addWidget(self.anal)
        l.addLayout(hl)
        if mode=='peri':
            self.perEdit1 = QtGui.QLineEdit(str(self.period))
            self.perEdit2 = QtGui.QLineEdit(str(self.period))
            self.modeLabel = QtGui.QLabel(self.tr(""))
            perLabel = QtGui.QLabel(self.tr("Period estimate: min "))
            hl2.addWidget(perLabel)
            hl2.addWidget(self.perEdit1)
            perLabel = QtGui.QLabel(self.tr(" max "))
            hl2.addWidget(perLabel)
            hl2.addWidget(self.perEdit2)
            hl2.addWidget(self.modeLabel)
            l.addLayout(hl2)
            self.parLabel = QtGui.QLabel(self.tr("Fitted parameters: <b>None</b>"))
            l.addWidget(self.parLabel)
        
        self.main_widget.setFocus()
        self.setCentralWidget(self.main_widget)
        self.statusBar().showMessage("please choose method")
        global task
        task=self
        
    def set_poly(self):
        self.modeLabel.setText('Cauchy prof.')
    def set_const(self):
        self.modeLabel.setText('const.')
    #def fileQuit(self):
    def closeEvent(self,ce):
        QtGui.QMessageBox.information(self, self.tr("Closing"), QtCore.QT_TR_NOOP("Analysis saved"))
    def get_perange(self):
        rep=[str(self.perEdit1.text()),str(self.perEdit2.text())]
        for i in [0,1]:
            if rep[i]=='': rep[i]==None
            else: rep[i]=float(rep[i])
        return rep
    def show_map():
        name='gui'
        if name in anal_data:
            vmin=fld[fld>0].min()
            vmax=fld[fld>0].max()
            extent=[(2*(i%2)-1)*fld.shape[i//2]//2 for i in range(4)] #+- range
            rep=self.anal.axes.imshow(fld,extent=extent,origin="lower",vmin=vmin,vmax=vmax)
            self.graph.figure.colorbar(rep)
Esempio n. 4
0
class ScanMap(QtGui.QMainWindow):
    parent=None
    points=[]
    xlim=None#[-10,10]
    ylim=None#[-10,10]
    polar=False
    graph=None
    butts=[]
    mode='scat'
    text_format=None
    control=None
    last=None
    def __init__(self,graph=True,attach=False,mode='scat',**kwargs):
        QtGui.QMainWindow.__init__(self)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowTitle("Scanning")
        self.main_widget = QtGui.QWidget(self)
        l = QtGui.QVBoxLayout(self.main_widget)
        hl = QtGui.QHBoxLayout()
        if 'parent' in kwargs: 
            self.parent=kwargs['parent']
            exargs=self.parent.control
            self.control=self.parent.control
            self.polar=self.parent.polar
        else: exargs={}
        if graph:
            self.graph = MyStaticMplCanvas(self.main_widget, width=5, height=4, dpi=100, polar=self.polar)
            self.graph.change_sizes()
            self.graph.axes.set_xlabel('X [mm]')
            self.graph.axes.set_ylabel('Y [mm]')
            #if self.data:
            #    self.anal.draw()
            l.addWidget(self.graph)
        self.butts=[]
        for bid in ['Period','Fluct.','Mean','Variab.','Save','Stop']:
            self.butts.append(QtGui.QPushButton(self.tr("&"+bid)))
            #self.attButton.setIcon(ico)
        for b in self.butts: hl.addWidget(b)
        self.connect(self.butts[0], QtCore.SIGNAL("clicked()"), self.show_peri)
        self.connect(self.butts[1], QtCore.SIGNAL("clicked()"), self.show_disp)
        self.connect(self.butts[2], QtCore.SIGNAL("clicked()"), self.show_mean)
        self.connect(self.butts[3], QtCore.SIGNAL("clicked()"), self.show_vari)
        self.connect(self.butts[4], QtCore.SIGNAL("clicked()"), self.save_data)
        self.connect(self.butts[5], QtCore.SIGNAL("clicked()"), self.stop_scan)

        l.addLayout(hl)
        self.main_widget.setFocus()
        self.setCentralWidget(self.main_widget)
        self.statusBar().showMessage("scanning under way")
        if self.polar:
            self.xlim=None
            if 'ny' in exargs: self.ylim=[0,(exargs['ny']-0.5)*self.parent.control['xstep']]
        else:
            if 'xlim' in kwargs: exargs['nx']=kwargs['xlim']
            if 'nx' in exargs: self.xlim=[-0.5*self.parent.control['xstep'],(exargs['nx']-0.5)*self.parent.control['xstep']]
            if 'ylim' in kwargs: exargs['ny']=kwargs['ylim']
            if 'ny' in exargs: self.ylim=[-0.5*self.parent.control['ystep'],(exargs['ny']-0.5)*self.parent.control['ystep']]
        self.clear()
        self.graph.axes.hold(1)
        if self.xlim!=None: 
            self.graph.axes.set_xlim(self.xlim)
            print('setting xlim %.2f-%.2f'%tuple(self.xlim))
        if self.ylim!=None: 
            self.graph.axes.set_ylim(self.ylim)
            print('setting ylim %.2f-%.2f'%tuple(self.ylim))
        self.mode=mode
    def clear(self):
        self.graph.axes.clear()
        self.graph.draw()        
    def add_point(self,what='peri'):
        '''draw single point'''
        self.graph.axes.hold(1)
        ix,iy=self.control['x'],self.control['y']
        val=0
        if anal_data and what in anal_data: val=anal_data[what][ix,iy]
        if what=='peri': val/=1000. #in micrometers
        px,py=self.control['gx'],self.control['gy']

        if self.polar:
            py*=pi/180.
            px*=rc.xstepsize
            #px,py=py,px
            #pr,ptheta=px,py/180.*pi
            #if 'init_r' in self.control: py+=self.control['init_r']
        else:
            px*=rc.xstepsize
            py*=rc.ystepsize
            
        if 'swap' in self.control: px,py=py,px
            #px,py=pr*cos(ptheta),pr*sin(ptheta)
            #from matplotlib.pyplot import polar
            #polar(self.parent.control['y']/180.*pi,self.parent.control['x'],'sg')
        self.last=self.graph.axes.plot(px,py,'o',color=(0.5+0.1*val,0.2,0.2),markersize=rc.disp_mark_size)[0]
        #print "plotting %.3f %.3f"%(px,py)
        if self.ylim!=None: shi=(self.ylim[1]-self.ylim[0])*rc.disp_anal_shift
        else: shi=0
        if self.text_format: 
            self.graph.axes.text(px,py+shi,self.text_format%val)
            #print 'point %i %i: %s [%s]'%(ix,iy,self.text_format%val,what)
        self.points.append([px,py])
        if self.xlim!=None: self.graph.axes.set_xlim(self.xlim)
        if self.ylim!=None: self.graph.axes.set_ylim(self.ylim)
        self.graph.mpl_connect('button_release_event',self.mouse_sel)
#        self.graph.mpl_connect('button_press_event',self.mouse_sel)
        self.graph.draw()
    def save_data(self):
        #from spectra import save
        oname = self.parent.fileDialog.getSaveFileName(self,self.tr("Output file"),
                                         self.parent.saveFileNameLabel.text(),
                                         self.tr("Text Files (*.txt);;All Files (*)"))
        if str(oname)!="": save_period(str(oname),anal_data['peri'],anal_data['peri_disp'])
    def stop_scan(self):
        if not 'stop' in self.control:
            self.control['stop']=1
            self.butts[4].setText('Run')
        else:
            del self.control['stop']
            self.butts[4].setText('Stop')
    def mouse_sel(self,event):
        self.statusBar().showMessage("pos %f %f"%(event.x,event.y))
    def image_plot(self,what='peri',fact=1,desc=None):
        from numpy import array,indices
        if len(self.points)==0: ix,iy=array(anal_data['gpos']).transpose().astype('f')
        else: ix,iy=array(self.points).transpose().astype('f')
        if not what in anal_data:
            self.graph.axes.hold(0)
            self.graph.axes.plot(ix,iy,'c',color='green')
            self.graph.axes.hold(1)
            return
        fld=anal_data[what].transpose()*fact
        if (fld>0).sum()==0: return
        vals=fld[fld>0]
        vmin=vals.min()
        vmax=vals.max()
        extent=[(2*(i%2)-1)*fld.shape[i//2]//2 for i in range(4)] #+- range
        if self.ylim!=None: shi=(self.ylim[1]-self.ylim[0])*rc.disp_anal_shift
        else: shi=0
            #self.graph.axes.set_ylim(self.ylim)
        if self.mode=='scat': 
            self.graph.axes.clear()
            print('plot %i points'%len(vals))
            #if self.xlim==None: self.xlim=[ix.min(),ix.max()]
            #if self.ylim==None: self.ylim=[iy.min(),iy.max()]
            col=(vals-vmin)/2./(vmax-vmin)
            rep=self.graph.axes.scatter(ix,iy,rc.disp_mark_size*10,color=[(a+0.5,0.6-a,0.3) for a in col])
            if self.text_format:
                for i in range(len(self.points)):
                    self.graph.axes.text(ix[i],iy[i]+shi,self.text_format%vals[i])
        else: 
            rep=self.graph.axes.imshow(fld,origin="lower",vmin=vmin,vmax=vmax)
            self.graph.figure.colorbar(rep)
        if desc: self.statusBar().showMessage(desc)
        #if self.xlim!=None: self.graph.axes.set_xlim(self.xlim)
        self.graph.draw()
        return rep
    def show_peri(self):
        self.image_plot('peri',desc='Thickness estimate [um]',fact=0.001)
    def show_mean(self):
        self.image_plot('mean',desc='Mean reflectivity')
    def show_vari(self):
        self.image_plot('vari',desc='Interference amplitude')
    def show_disp(self):
        self.image_plot('peri_disp',desc='Thickness fluctuation [nm]',fact=100.)
    def show_map(self):
        self.image_plot(None)