Esempio n. 1
0
    def __setup_layout( self ):
        
        self.connect( self.button, QtCore.SIGNAL( 'clicked()' ), self.button_Click )
        self.connect( self.button2, QtCore.SIGNAL( 'clicked()' ), self.button_Click2 )
        self.connect( self.button3, QtCore.SIGNAL( 'clicked()' ), self.button_Click3 )
        self.connect( self.button4, QtCore.SIGNAL( 'clicked()' ), self.button_Click4 )
        self.connect( self.button5, QtCore.SIGNAL( 'clicked()' ), self.button_Click5 )
        self.connect( self.button6, QtCore.SIGNAL( 'clicked()' ), self.button_Click6 )
        
        # Vertical cursor
        self.cursorposition = 0.8
        self.cursorposition2 = 1.2
        self.vcursor1 = make.vcursor(self.cursorposition,  label='x = %.2f')
        self.plot.add_item( self.vcursor1 )
        self.vcursor2 = make.vcursor(self.cursorposition2,  label='x = %.2f')
        self.plot.add_item( self.vcursor2 )

        # Define the y label, x might change depending on user definition
        CurvePlot.set_axis_title(self.plot,CurvePlot.Y_LEFT,"Intensity (counts)")

        # Crate the PlotManager
        self.manager = PlotManager( self )
        self.manager.add_plot( self.plot )
        self.manager.add_plot( self.plot2 )

        # Create Toolbar
        toolbar = self.addToolBar( 'tools' )
        self.manager.add_toolbar( toolbar, id( toolbar ) )

        # Register the ToolBar's type
        self.manager.register_all_curve_tools( )
#        self.manager.register_other_tools()

        # Register a custom tool
        self.manager.add_tool( SelectPointTool, title = 'Position', on_active_item = True, mode = 'create' )
Esempio n. 2
0
    def button_Click6( self ):
        # Clear the plot first
        self.plot2.del_all_items()
        
        # Seed for random generator of colors, so that they are always in the same order
        random.seed(654321)
        colorlistred = [220, 255, 155, 24, 0, 0, 48, 205, 255, 255, 0, 142]
        colorlistgreen = [20, 105, 48, 116, 229, 238, 128, 205, 193, 97, 0, 142]
        colorlistblue = [60, 180, 255, 205, 238, 118, 20, 0, 37, 3, 0, 142]
        markerlist = ['Rect','Diamond', 'UTriangle', 'DTriangle', 'RTriangle','Cross', 'Ellipse', 'Star1', 'XCross', 'LTriangle', 'Star2']

        # Get cursor positions to define ROI
        x1 = guiqwt.shapes.Marker.xValue(self.vcursor1)
        x2 = guiqwt.shapes.Marker.xValue(self.vcursor2)
        if x2 < x1:
            x3 = copy.deepcopy(x1)
            x1 = copy.deepcopy(x2)
            x2 = x3
        indices = []
        
        self.sumy = {}
        self.sumx = {}
        # Use first predefined colours, then random
        colorcounter = 0

        maxsumx = 0
        minsumx = 10000
        maxsumy = 0
        minsumy = 10000000
        self.sumxall = {}
        self.sumyall = {}
        seriesnames = []

        for row in range(self.series_list_model.rowCount()):
            model_index = self.series_list_model.index(row, 0)
            checked = self.series_list_model.data(model_index,
                Qt.CheckStateRole) == QVariant(Qt.Checked)
            name = str(self.series_list_model.data(model_index).toString())

            if checked:
                # Find x values over which to sum
                indices = []
                for index,value in enumerate(self.x[name]):
                    if value > x1 and value < x2:
                        indices.append(index)
                xx = np.array(self.x[name])
                yy = np.array(self.y[name])
                sumy1 = np.trapz(yy[indices],xx[indices])
                self.sumy[name] = [float(sumy1)]
                number1 = re.findall("(?<=_|-)[\d]*(?=.chi)",name)
                sumx1 = int(number1[0])
                self.sumx[name] = [float(sumx1)]
                if max(self.sumx[name])>maxsumx:
                    maxsumx = max(self.sumx[name])
                if max(self.sumy[name])>maxsumy:
                    maxsumy = max(self.sumy[name])
                if min(self.sumx[name])<minsumx:
                    minsumx = min(self.sumx[name])
                if min(self.sumy[name])<minsumy and min(self.sumy[name]) > 0:
                    minsumy = min(self.sumy[name])
                # Check which series names we have
                name1 = re.findall("[\W\S\d]*(?=-[\d]{5}.chi)",name)
                # Try different versions of writing the names if first one does not succeed
                if name1 == []:
                    name1 = re.findall("[\W\S\d]*(?=_[\d]{4}.chi)",name)
                if name1 == []:
                    name1 = re.findall("[\W\S\d]*(?=_[\d]{5}.chi)",name)
                seriesname1 = str(name1[0])
                if seriesname1 not in seriesnames:
                    seriesnames.append(seriesname1)
                    self.sumxall[seriesname1] = []
                    self.sumyall[seriesname1] = []
                self.sumxall[seriesname1].append(sumx1)
                self.sumyall[seriesname1].append(sumy1)

        # Make lines and legends to separate different sample series
        colorcounter = 0
        random.seed(654321)
        markercounter = 0
        for seriesname1 in seriesnames:
                if len(colorlistred) > colorcounter:
                    self.curveB = make.curve( [ ], [ ], seriesname1, QtGui.QColor( colorlistred[colorcounter], colorlistgreen[colorcounter], colorlistblue[colorcounter] ), linewidth=3.0, marker=markerlist[markercounter], markerfacecolor = QtGui.QColor( colorlistred[colorcounter], colorlistgreen[colorcounter], colorlistblue[colorcounter] ), markeredgecolor= QtGui.QColor( colorlistred[colorcounter], colorlistgreen[colorcounter], colorlistblue[colorcounter] ))
                    colorcounter = colorcounter + 1
                    markercounter = markercounter + 1
                else:
                    newcolor = QtGui.QColor( random.randint(0,255), random.randint(0,255), random.randint(0,255))
                    self.curveB = make.curve( [ ], [ ], seriesname1, newcolor, linewidth=3.0, marker=markerlist[markercounter], markerfacecolor = newcolor, markeredgecolor = newcolor )
                    markercounter = markercounter + 1
                if markercounter > len(markerlist):
                    markercounter = 0
                self.plot2.add_item( self.curveB )
                self.curveB.set_data( self.sumxall[seriesname1],self.sumyall[seriesname1] )                
        

        CurvePlot.set_axis_title(self.plot2,CurvePlot.X_BOTTOM,"File number")
        CurvePlot.set_axis_title(self.plot2,CurvePlot.Y_LEFT,"ROI sum")
        
        self.legend2 = make.legend( 'TR' ) # Top Right
        self.plot2.add_item( self.legend2 )

        # Reset axis if ticked
        if self.tick_axis_reset.isChecked()==True:
            CurvePlot.set_axis_limits(self.plot2,CurvePlot.X_BOTTOM,minsumx*0.9,maxsumx*1.1)
            CurvePlot.set_axis_limits(self.plot2,CurvePlot.Y_LEFT,minsumy*0.9,maxsumy*1.1)

        # Plot everything
        self.plot2.replot( )
Esempio n. 3
0
    def button_Click2( self ):
#        has_series = False
        
        # Seed for random generator of colors, so that they are always in the same order
        random.seed(654321)
        colorlistred = [220, 255, 155, 24, 0, 0, 48, 205, 255, 255, 0, 142]
        colorlistgreen = [20, 105, 48, 116, 229, 238, 128, 205, 193, 97, 0, 142]
        colorlistblue = [60, 180, 255, 205, 238, 118, 20, 0, 37, 3, 0, 142]
        
        # Clear the plot first
        self.plot.del_all_items()
        # Add back the vertical cursor to the plot in the same position as before
        self.plot.add_item( self.vcursor1 )
        self.plot.add_item( self.vcursor2 )
        
        # For axes take max of 2theta and max of intensity
        maxtth = 0
        maxintensity = 0
        mintth = 100
        minintensity = 100
        # Use first predefined colours, then random
        colorcounter = 0
        # Two simple markers to test if mixed x ranges exist
        foundq = 0
        foundtth = 0
        for row in range(self.series_list_model.rowCount()):
            model_index = self.series_list_model.index(row, 0)
            checked = self.series_list_model.data(model_index,
                Qt.CheckStateRole) == QVariant(Qt.Checked)
            name = str(self.series_list_model.data(model_index).toString())
            
            if checked:
#                has_series = True
                self.curveAlabel = name
                if len(colorlistred) > colorcounter:
                    self.curveA = make.curve( [ ], [ ], self.curveAlabel, QtGui.QColor( colorlistred[colorcounter], colorlistgreen[colorcounter], colorlistblue[colorcounter] ), linewidth=3.0)
                    colorcounter = colorcounter + 1
                else:                    
                    self.curveA = make.curve( [ ], [ ], self.curveAlabel, QtGui.QColor( random.randint(0,255), random.randint(0,255), random.randint(0,255) ), linewidth=3.0)
                self.plot.add_item( self.curveA )

                self.curveA.set_data( self.x[name], self.y[name])
                if max(self.x[name])>maxtth:
                    maxtth = max(self.x[name])
                if max(self.y[name])>maxintensity:
                    maxintensity = max(self.y[name])
                if min(self.x[name])<mintth:
                    mintth = min(self.x[name])
                if min(self.y[name])<minintensity and min(self.y[name]) > 0:
                    minintensity = min(self.y[name])
                # Check if TTH or Q range, redefine x label if Q
                f = open(str(self.fullfilename[name]))
                text1 = f.read()
                f.close()
                if 'Azimuth (Degrees)' in text1:
                    foundtth = 1
                    CurvePlot.set_axis_title(self.plot,CurvePlot.X_BOTTOM,"Azimuth angle (degrees)")
                elif 'Q' in text1:
                    foundq = 1
                    CurvePlot.set_axis_title(self.plot,CurvePlot.X_BOTTOM,"q (1/nm)")
                elif '2-Theta Angle (Degrees)' in text1:
                    foundtth = 1
                    CurvePlot.set_axis_title(self.plot,CurvePlot.X_BOTTOM,"2-theta (degrees)")
                if foundq == 1 and foundtth == 1:
                    CurvePlot.set_axis_title(self.plot,CurvePlot.X_BOTTOM,"Mixed! q (1/nm) and 2-theta (degrees)")                    

        self.legend = make.legend( 'TR' ) # Top Right
        self.plot.add_item( self.legend )
        
        # Reset axis if checkbox is checked, otherwise ignore
        if self.tick_axis_reset.isChecked()==True:
            CurvePlot.set_axis_limits(self.plot,CurvePlot.X_BOTTOM,mintth*0.9,maxtth*1.1)
            CurvePlot.set_axis_limits(self.plot,CurvePlot.Y_LEFT,minintensity*0.9,maxintensity*1.1)

        # Plot everything
        self.plot.replot( )
        
        # Refresh also the integral plot
        self.button_Click6( )