Exemple #1
0
    def __init__(self, *args):

        QtBlissGraph.__init__(self, *args)
        picker = qwt.QwtPlotPicker(qwt.QwtPlot.xBottom, qwt.QwtPlot.yLeft,
                                   qwt.QwtPicker.PointSelection,
                                   qwt.QwtPlotPicker.CrossRubberBand,
                                   qwt.QwtPicker.AlwaysOn, self.canvas())
        picker.connect(picker, SIGNAL('selected(const QwtDoublePoint&)'),
                       self.pickPoint)
    def __init__(self,*args):

        QtBlissGraph.__init__(self,*args)
        picker = qwt.QwtPlotPicker(qwt.QwtPlot.xBottom,
                               qwt.QwtPlot.yLeft,
                               qwt.QwtPicker.PointSelection,
                               qwt.QwtPlotPicker.CrossRubberBand,
                               qwt.QwtPicker.AlwaysOn,
                               self.canvas())
        picker.connect( picker, SIGNAL('selected(const QwtDoublePoint&)'), self.pickPoint)
Exemple #3
0
 def __init__(self, parent=None, **kw):
     Plot1DWindowBase.Plot1DWindowBase.__init__(self, parent, **kw)
     mainLayout = self.layout()
     if not ('usecrosscursor' in kw):
         kw['usecrosscursor'] = True
     self.graph = QtBlissGraph.QtBlissGraph(self, **kw)
     self.graph.canvas().setMouseTracking(1)
     self.graph.setCanvasBackground(qt.Qt.white)
     mainLayout.addWidget(self.graph)
     self.newCurve = self.addCurve
     self.setTitle = self.graph.setTitle
     self.activeCurve = None
     self._logY = False
     self.__toggleCounter = 0
Exemple #4
0
    def __init__(self,
                 parent=None,
                 selection=False,
                 colormap=False,
                 imageicons=False,
                 standalonesave=True,
                 standalonezoom=True,
                 profileselection=False):
        qt.QWidget.__init__(self, parent)
        self.mainLayout = qt.QVBoxLayout(self)
        self.mainLayout.setMargin(0)
        self.mainLayout.setSpacing(0)
        if QTVERSION < '4.0.0':
            profileselection = False
        self._buildToolBar(selection,
                           colormap,
                           imageicons,
                           standalonesave,
                           standalonezoom=standalonezoom,
                           profileselection=profileselection)
        self.graph = QtBlissGraph.QtBlissGraph(self)
        self.graph.xlabel("Column")
        self.graph.ylabel("Row")
        self.graph.yAutoScale = 1
        self.graph.xAutoScale = 1
        if profileselection:
            if len(self._pickerSelectionButtons):
                self.connect(self.graph, qt.SIGNAL('PolygonSignal'),
                             self._graphPolygonSignalReceived)
                self.connect(self._pickerSelectionWidthValue,
                             qt.SIGNAL('valueChanged(int)'),
                             self.setPickerSelectionWith)

        self.saveDirectory = os.getcwd()
        self.mainLayout.addWidget(self.graph)
        self.printPreview = PyMcaPrintPreview.PyMcaPrintPreview(modal=0)
        if DEBUG:
            print("printPreview id = %d" % id(self.printPreview))
Exemple #5
0
    def plot(self):
        if not HAS_QWT:
            return
        d = self.tubeWidget.getParameters()
        transmission    = d["transmission"]
        anode           = d["anode"]
        anodedensity    = d["anodedensity"]
        anodethickness  = d["anodethickness"]
        
        voltage         = d["voltage"]
        wele            = d["window"]
        wdensity        = d["windowdensity"]
        wthickness      = d["windowthickness"]
        fele            = d["filter1"]
        fdensity        = d["filter1density"]
        fthickness      = d["filter1thickness"]
        filterlist      =[[fele, fdensity, fthickness]]
        alphae          = d["alphae"]
        alphax          = d["alphax"]

        delta           = d["deltaplotting"]
        e = numpy.arange(1, voltage, delta)

        if self.graph is None:
            self.graph = QtBlissGraph.QtBlissGraph(self)
            self.l.addWidget(self.graph)
            #self.graph.setTitle("Reference: X-Ray Spectrometry 28 (1999) 255-256")
            self.graph.xlabel("Energy (keV)")
            self.graph.ylabel("photons/sr/mA/keV/s")
            self.graph.show()

        if __name__ == "__main__":
            continuumR = XRayTubeEbel.continuumEbel([anode, anodedensity, anodethickness],
                                             voltage, e,
                                             [wele, wdensity, wthickness],
                                             alphae=alphae, alphax=alphax,
                                             transmission=0,
                                             targetthickness=anodethickness,
                                             filterlist=filterlist)

            continuumT = XRayTubeEbel.continuumEbel([anode, anodedensity, anodethickness],
                                             voltage, e,
                                             [wele, wdensity, wthickness],
                                             alphae=alphae, alphax=alphax,
                                             transmission=1,
                                             targetthickness=anodethickness,
                                             filterlist=filterlist)




            self.graph.newcurve("continuumR", e, continuumR)
            self.graph.newcurve("continuumT", e, continuumT)
        else:
            continuum = XRayTubeEbel.continuumEbel([anode, anodedensity, anodethickness],
                                             voltage, e,
                                             [wele, wdensity, wthickness],
                                             alphae=alphae, alphax=alphax,
                                             transmission=transmission,
                                             targetthickness=anodethickness,
                                             filterlist=filterlist)
            self.graph.newcurve("continuum", e, continuum)

        self.graph.zoomReset()
        self.graph.replot()
Exemple #6
0
    def getImage(self):
        dict = self.fitresult
        if MATPLOTLIB:
            try:
                fig = Figure(figsize=(6, 3))  # in inches
                canvas = FigureCanvas(fig)
                ax = fig.add_axes([.15, .15, .8, .8])
                ax.set_axisbelow(True)
                logplot = self.plotDict.get('logy', True)
                if logplot:
                    axplot = ax.semilogy
                else:
                    axplot = ax.plot
                axplot(dict['result']['energy'],
                       dict['result']['ydata'],
                       'k',
                       lw=1.5)
                axplot(dict['result']['energy'],
                       dict['result']['continuum'],
                       'g',
                       lw=1.5)
                legendlist = ['spectrum', 'continuum', 'fit']
                axplot(dict['result']['energy'],
                       dict['result']['yfit'],
                       'r',
                       lw=1.5)
                fontproperties = FontProperties(size=8)
                if dict['result']['config']['fit']['sumflag']:
                    axplot(dict['result']['energy'],
                           dict['result']['pileup'] +
                           dict['result']['continuum'],
                           'y',
                           lw=1.5)
                    legendlist.append('pileup')
                if matplotlib_version < '0.99.0':
                    legend = ax.legend(legendlist,
                                       0,
                                       prop=fontproperties,
                                       labelsep=0.02)
                else:
                    legend = ax.legend(legendlist,
                                       0,
                                       prop=fontproperties,
                                       labelspacing=0.02)
            except ValueError:
                fig = Figure(figsize=(6, 3))  # in inches
                canvas = FigureCanvas(fig)
                ax = fig.add_axes([.15, .15, .8, .8])
                ax.set_axisbelow(True)
                ax.plot(dict['result']['energy'],
                        dict['result']['ydata'],
                        'k',
                        lw=1.5)
                ax.plot(dict['result']['energy'],
                        dict['result']['continuum'],
                        'g',
                        lw=1.5)
                legendlist = ['spectrum', 'continuum', 'fit']
                ax.plot(dict['result']['energy'],
                        dict['result']['yfit'],
                        'r',
                        lw=1.5)
                fontproperties = FontProperties(size=8)
                if dict['result']['config']['fit']['sumflag']:
                    ax.plot(dict['result']['energy'],
                            dict['result']['pileup'] +
                            dict['result']['continuum'],
                            'y',
                            lw=1.5)
                    legendlist.append('pileup')
                if matplotlib_version < '0.99.0':
                    legend = ax.legend(legendlist,
                                       0,
                                       prop=fontproperties,
                                       labelsep=0.02)
                else:
                    legend = ax.legend(legendlist,
                                       0,
                                       prop=fontproperties,
                                       labelspacing=0.02)

            ax.set_xlabel('Energy')
            ax.set_ylabel('Counts')
            legend.draw_frame(False)

            outfile = self.outdir + "/" + self.outfile + ".png"
            try:
                os.remove(outfile)
            except:
                pass

            canvas.print_figure(outfile)
            return self.__getFitImage(self.outfile + ".png")

        if self.graph is None:
            self.widget = qt.QWidget()
            self.widget.l = qt.QVBoxLayout(self.widget)
            self.graph = QtBlissGraph.QtBlissGraph(self.widget)
            self.widget.l.addWidget(self.graph)
        widget = self.widget
        graph = self.graph

        graph.xlabel('Energy')
        graph.ylabel('Counts')
        graph.setCanvasBackground(qt.Qt.white)
        x = dict['result']['energy']
        graph.newcurve('spectrum', x=x, y=dict['result']['ydata'], logfilter=1)
        graph.newcurve('continuum',
                       x=x,
                       y=dict['result']['continuum'],
                       logfilter=1)
        graph.newcurve('fit', x=x, y=dict['result']['yfit'], logfilter=1)
        if dict['result']['config']['fit']['escapeflag']:
            #I DO NOT HAVE THE CONTRIBUTION
            pass
            #self.graph.newcurve('escape',x=x,y=dict['result']['escape'],logfilter=1)
        if dict['result']['config']['fit']['sumflag']:
            graph.newcurve('pileup',
                           x=x,
                           y=dict['result']['pileup'] +
                           dict['result']['continuum'],
                           logfilter=1)
        graph.ToggleLogY()
        ymin = min(min(dict['result']['ydata']), min(dict['result']['yfit']))
        ymax = max(max(dict['result']['ydata']), max(dict['result']['yfit']))
        graph.setY1AxisLimits(ymin, ymax)
        graph.setY2AxisLimits(ymin, ymax)
        graph.show()
        widget.resize(450, 300)
        #widget.show()

        qt.qApp.processEvents()
        outfile = self.outdir + "/" + self.outfile + ".png"
        pixmap = qt.QPixmap.grabWidget(widget)
        try:
            os.remove(outfile)
        except:
            pass
        if pixmap.save(outfile, 'PNG'):
            qt.qApp.processEvents()
            graph.close()
            del graph
            widget.close()
            del widget
            return self.__getFitImage(self.outfile + ".png")
        else:
            print("cannot generate image")
            return ""
    print("selections ")
    print("getZSelectionArray  shape = ", stack.getZSelectionArray().shape)
    print("getXYSelectionArray shape = ", stack.getXYSelectionArray().shape)

    from PyMca import PyMcaQt as qt
    app = qt.QApplication([])
    qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"), app,
                       qt.SLOT("quit()"))
    if 1:
        from PyMca import RGBCorrelatorGraph
        w = RGBCorrelatorGraph.RGBCorrelatorGraph()
        graph = w.graph
    else:
        from PyMca import QtBlissGraph
        w = QtBlissGraph.QtBlissGraph()
        graph = w
    print("shape sum 0 = ", numpy.sum(stack.data, 0).shape)
    print("shape sum 1 = ", numpy.sum(stack.data, 1).shape)
    print("shape sum 2 = ", numpy.sum(stack.data, 2).shape)
    a = numpy.sum(stack.data, imax)
    print(a.shape)
    graph.setX1AxisLimits(0, a.shape[0])
    if 0:
        w.setY1AxisLimits(0, a.shape[1])
        w.setY1AxisInverted(True)
    else:
        graph.setY1AxisInverted(True)
        graph.setY1AxisLimits(0, a.shape[1])
    graph.imagePlot(a, ymirror=0)
    if imax == 0:
        if height is None:
            height = self._qImage.height()
        self._worldX = x
        self._worldY = y
        self._worldWidth = width
        self._worldHeight = height

    def setAlpha(self, alpha):
        self._alpha = alpha

if __name__ == "__main__":
    DEBUG = 1
    import os
    from PyMca import QtBlissGraph
    app = qt.QApplication([])
    plot = QtBlissGraph.QtBlissGraph()
    rescaler = Qwt5.QwtPlotRescaler(plot.canvas())
    rescaler.setEnabled(True)

    item = PolygonItem("Dummy")
    item.setData(x=[10, 400, 600.], y=[200, 600, 800.])
    item.attach(plot)
    image = QImageItem("Dummy2")
    qImage = qt.QImage(
        os.path.join(os.path.dirname(__file__), "PyMcaSplashImage.png"))
    image.setQImageList([qImage], qImage.width(), qImage.height())
    image.setData(200, 600)
    image.setAlpha(0.5)
    image.attach(plot)
    if 0:
        plot.setY1AxisLimits(1000, 0)