Exemplo n.º 1
0
def test():
    from PyMca import SpecFileLayer

    if len(sys.argv) < 3:
        print("USAGE: %s <filename> <key>" % sys.argv[0])
        sys.exit(0)

    #d= SpecFileData()
    d = SpecFileLayer.SpecFileLayer()

    d.SetSource(sys.argv[1])
    info,data = d.LoadSource(sys.argv[2])
    #info= d.GetPageInfo({"SourceName":sys.argv[1], "Key":sys.argv[2]})

    if qt.qVersion() < '4.0.0':
        app= qt.QApplication(sys.argv)
        wid= SpecFileDataInfo(info)
        wid.show()

        app.setMainWidget(wid)
        app.exec_loop()
    else:
        app= qt.QApplication([])
        wid= SpecFileDataInfo(info)
        wid.show()
        app.exec_()
Exemplo n.º 2
0
def testwidget():
    import sys

    def change(ddict):
        print("New selection:", )
        print(ddict)

    a = qt.QApplication(sys.argv)
    qt.QObject.connect(a, qt.SIGNAL("lastWindowClosed()"), a,
                       qt.SLOT("quit()"))

    w = qt.QTabWidget()

    if QTVERSION < '4.0.0':
        f = FitPeakSelect(w)
        w.addTab(f, "QPeriodicTable")
        qt.QObject.connect(f, qt.PYSIGNAL("FitPeakSelect"), change)
        w.show()
        a.exec_loop()
    else:
        f = FitPeakSelect()
        w.addTab(f, "QPeriodicTable")
        qt.QObject.connect(f, qt.SIGNAL("FitPeakSelect"), change)
        w.show()
        a.exec_()
Exemplo n.º 3
0
def test():
    from PyMca import SpecfitFunctions
    a=SpecfitFunctions.SpecfitFunctions()
    x = numpy.arange(1000).astype(numpy.float)
    p1 = numpy.array([1500,100.,50.0])
    p2 = numpy.array([1500,700.,50.0])
    y = a.gauss(p1, x)+1
    y = y + a.gauss(p2,x)

    fit = SimpleFit()
    fit.importFunctions(SpecfitFunctions)
    fit.setFitFunction('Gaussians')
    #fit.setBackgroundFunction('Gaussians')
    #fit.setBackgroundFunction('Constant')
    fit.setData(x, y)
    fit.fit()
    print("Expected parameters 1500,100.,50.0, 1500,700.,50.0")
    from PyMca import PyMcaQt as qt
    from PyMca import Parameters
    a = qt.QApplication(sys.argv)
    qt.QObject.connect(a,qt.SIGNAL("lastWindowClosed()"),a,qt.SLOT("quit()"))
    w =Parameters.Parameters()
    w.fillfromfit(fit.paramlist)
    w.show()
    a.exec_()
Exemplo n.º 4
0
def test():
    a = qt.QApplication(sys.argv)
    #new access
    from PyMca import QDataSource
    w= QSourceSelector()
    def mySlot(ddict):
        print(ddict)
        if ddict["event"] == "NewSourceSelected":
            d = QDataSource.QDataSource(ddict["sourcelist"][0])
            w.specfileWidget.setDataSource(d)
            if QTVERSION < '4.0.0':
                a.connect(w, qt.PYSIGNAL("SourceSelectorSignal"),
                      mySlot)
            else:
                a.connect(w, qt.SIGNAL("SourceSelectorSignal"),
                       mySlot)

        
    qt.QObject.connect(a, qt.SIGNAL("lastWindowClosed()"),
              a, qt.SLOT("quit()"))

    if QTVERSION < '4.0.0':
        w.show()
        a.exec_loop()
    else:
        w.show()
        a.exec_()
Exemplo n.º 5
0
def test(a):
    from PyMca import PyMcaQt as qt
    from PyMca import Specfit
    from PyMca import ScanWindow
    #print dir(a)
    x = numpy.arange(1000).astype(numpy.float)
    p1 = numpy.array([1500,100.,50.0])
    p2 = numpy.array([1500,700.,50.0])
    y = a.gauss(p1,x)+1
    y = y + a.gauss(p2,x)
    app=qt.QApplication([])
    #fit=Specfit.Specfit(root,x,y,
    #                    user_theory='New Theory',
    #                    user_function=a.gauss,
    #                    user_parameters=['Height','Position','FWHM'])
    #                    #user_estimate=estimate)
    fit=Specfit.Specfit(x,y)
    fit.addtheory('Gaussians',a.gauss,['Height','Position','FWHM'],
                    a.estimate_gauss)                       
    fit.settheory('Gaussians')
    fit.setbackground('Linear')
    
    fit.estimate()
    fit.startfit()
    yfit=fit.gendata(x=x,parameters=fit.paramlist)
    print("I set an offset of 1 to see the difference in log scale :-)")
    w = ScanWindow.ScanWindow()
    w.addCurve(x, y + 1, "Data + 1")
    w.addCurve(x, yfit, "Fit")
    w.show()
    app.exec_()
def test():
    app = qt.QApplication([])
    qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"), app,
                       qt.SLOT('quit()'))

    container = StackPluginResultsWindow()
    data = numpy.arange(20000)
    data.shape = 2, 100, 100
    data[1, 0:100, 0:50] = 100
    container.setStackPluginResults(
        data,
        spectra=[numpy.arange(100.),
                 numpy.arange(100.) + 10],
        image_names=["I1", "I2"],
        spectra_names=["V1", "V2"])
    container.show()

    def theSlot(ddict):
        print(ddict['event'])

    if QTVERSION < '4.0.0':
        qt.QObject.connect(container, qt.PYSIGNAL("MaskImageWidgetSignal"),
                           updateMask)
        app.setMainWidget(container)
        app.exec_loop()
    else:
        qt.QObject.connect(container, qt.SIGNAL("MaskImageWidgetSignal"),
                           theSlot)
        app.exec_()
Exemplo n.º 7
0
def main():
    import sys
    import getopt
    app=qt.QApplication(sys.argv) 
    winpalette = qt.QPalette(qt.QColor(230,240,249),qt.QColor(238,234,238))
    app.setPalette(winpalette)
    options=''
    longoptions=[]
    opts, args = getopt.getopt(
                    sys.argv[1:],
                    options,
                    longoptions)      
    for opt,arg in opts:
        pass
    filelist=args
    qt.QObject.connect(app,qt.SIGNAL("lastWindowClosed()"),app, qt.SLOT("quit()"))
    w=EdfFileSimpleViewer()
    if QTVERSION < '4.0.0' :
        app.setMainWidget(w)
        w.show()
        if len(filelist):w.setFileList(filelist)
        app.exec_loop()
    else:
        if len(filelist):w.setFileList(filelist)
        w.show()
        app.exec_()
Exemplo n.º 8
0
def main():
    app = qt.QApplication(sys.argv)
    winpalette = qt.QPalette(qt.QColor(230, 240, 249),
                             qt.QColor(238, 234, 238))
    app.setPalette(winpalette)
    if len(sys.argv) > 1:
        ene = float(sys.argv[1])
    else:
        ene = 5.9
    mw = qt.QWidget()
    l = qt.QVBoxLayout(mw)
    l.setSpacing(0)
    if 0:
        w = PeakIdentifier(mw, energy=ene)
        browsertext = qt.QTextView(mw)

        def myslot(dict):
            browsertext.setText(dict['text'])

        mw.connect(w, qt.PYSIGNAL('PeakIdentifierSignal'), myslot)
    else:
        w = PeakIdentifier(mw, energy=ene, useviewer=1)
        #######w.myslot()
    l.addWidget(w)
    if QTVERSION < '4.0.0':
        app.setMainWidget(mw)
        mw.show()
        app.exec_loop()
    else:
        mw.setWindowTitle("Peak Identifier")
        mw.show()
        app.exec_()
def test():
    app = qt.QApplication([])
    a=numpy.arange(256.)
    a.shape = 16, 16
    w = SaveImageSetup(None, a)
    w.setParameters(w.getParameters())
    w.show()
    app.exec_()
Exemplo n.º 10
0
def main():
    from PyMca import PyMcaQt as qt
    from PyMca import Plot1D
    app = qt.QApplication([])
    plot = Plot1D.Plot1D()
    plugin = getPlugin1DInstance(plot)
    plugin.applyMethod(plugin.getMethods()[0])
    print app.exec_()
Exemplo n.º 11
0
 def display(self, model):
     app = qt.QApplication.instance()
     if not app:  # create QApplication if it doesnt exist
         app = qt.QApplication(sys.argv)
     tree = qt.QTreeView()
     tree.setModel(model)
     tree.show()
     app.exec_()
     return tree
Exemplo n.º 12
0
def test():
    a = qt.QApplication(sys.argv)
    qt.QObject.connect(a, qt.SIGNAL("lastWindowClosed()"), a,
                       qt.SLOT("quit()"))
    w = ParametersTab()
    if QTVERSION < '4.0.0': a.setMainWidget(w)
    w.show()
    if 1:
        import specfile
        import Specfit
        import numpy
        sf = specfile.Specfile('02021201.dat')
        scan = sf.select('14')
        #sf=specfile.Specfile('02022101.dat')
        #scan=sf.select('11')
        mcadata = scan.mca(1)
        y = numpy.array(mcadata)
        #x=numpy.arange(len(y))
        x = numpy.arange(len(y)) * 0.0200511 - 0.003186
        fit = Specfit.Specfit()
        fit.setdata(x=x, y=y)
        fit.importfun("SpecfitFunctions.py")
        fit.settheory('Hypermet')
        fit.configure(Yscaling=1.,
                      WeightFlag=1,
                      PosFwhmFlag=1,
                      HeightAreaFlag=1,
                      FwhmPoints=50,
                      PositionFlag=1,
                      HypermetTails=1)
        fit.setbackground('Linear')
        if 0:
            # build a spectrum array
            f = open("spec.arsp", 'r')
            #read the spectrum data
            x = numpy.array([], numpy.float)
            y = numpy.array([], numpy.float)
            tmp = f.readline()[:-1]
            while (tmp != ""):
                tmpSeq = tmp.split()
                x = numpy.concatenate((x, [float(tmpSeq[0])]))
                y = numpy.concatenate((y, [float(tmpSeq[1])]))
                tmp = f.readline()[:-1]
            fit.setdata(x=x, y=y)
        if 1:
            mcaresult = fit.mcafit(x=x, xmin=x[70], xmax=x[500])
            w.fillfrommca(mcaresult)
        else:
            fit.estimate()
            fit.startfit()
            w.fillfromfit(fit.paramlist, current='Fit')
            w.removeview(view='Region 1')
    if QTVERSION < '4.0.0':
        a.exec_loop()
    else:
        a.exec_()
Exemplo n.º 13
0
def test():
    app = qt.QApplication([])
    w = QSelectorWidget()
    w.show()
    qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"),
                       app, qt.SLOT("quit()"))
    if QTVERSION < '4.0.0':
        app.exec_loop()
    else:
        app.exec_()
Exemplo n.º 14
0
def test():
    app = qt.QApplication([])
    w = qt.QTextEdit()
    if len(sys.argv) > 1:
        log = ChangeLog(textfile=sys.argv[-1])
    else:
        log = ChangeLog(textfile='changelog.txt')
    w.setDocument(log)
    w.show()
    app.exec_()
Exemplo n.º 15
0
def main():
    app = qt.QApplication([])
    tab = HDF5Selection()
    tab.setSelection({
        'x': [1, 2],
        'y': [4],
        'cntlist': ["dummy", "Cnt0", "Cnt1", "Cnt2", "Cnt3"]
    })
    tab.show()
    app.exec_()
Exemplo n.º 16
0
def test1(args):
    app = qt.QApplication(args)
    w = HorizontalSliderWithBrowser()

    def slot(ddict):
        print(ddict)

    qt.QObject.connect(w, qt.SIGNAL("valueChanged(int)"), slot)
    w.setRange(8, 20)
    w.show()
    app.exec_()
Exemplo n.º 17
0
def main():
    app = qt.QApplication([])
    w = ScanFit()
    qt.QObject.connect(app, qt.SIGNAL("lasWindowClosed()"), app,
                       qt.SLOT("quit()"))
    w.show()
    if QTVERSION < '4.0.0':
        app.setMainWidget(w)
        app.exec_loop()
    else:
        app.exec_()
Exemplo n.º 18
0
def test():
    app = qt.QApplication([])
    qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"), app,
                       qt.SLOT('quit()'))

    w = DoubleSlider()
    w.show()
    if QTVERSION < '4.0.0':
        app.exec_loop()
    else:
        app.exec_()
Exemplo n.º 19
0
def main(args):
    import specfile
    import Specfit
    import numpy
    app = qt.QApplication(args)
    tab = Parameters(labels=[
        'Parameter', 'Estimation', 'Fit Value', 'Sigma', 'Restrains',
        'Min/Parame', 'Max/Factor/Delta/'
    ],
                     paramlist=['Height', 'Position', 'FWHM'])
    tab.showGrid()
    tab.configure(name='Height', estimation='1234', group=0)
    tab.configure(name='Position', code='FIXED', group=1)
    tab.configure(name='FWHM', group=1)

    if len(args) > 1:
        fit = Specfit.Specfit()
        fit.importfun("SpecfitFunctions.py")
        fit.settheory('Hypermet')
        fit.configure(Yscaling=1.,
                      WeightFlag=1,
                      PosFwhmFlag=1,
                      HeightAreaFlag=1,
                      FwhmPoints=50,
                      PositionFlag=1,
                      HypermetTails=1)
        fit.setbackground('Linear')

        fname = args[1]
        sf = specfile.Specfile(fname)
        scan = sf[0]
        nbmca = scan.nbmca()
        if nbmca > 0:
            mcadata = scan.mca(1)
            y = numpy.array(mcadata)
            x = numpy.arange(len(y)) * 0.0200511 - 0.003186
            fit.setdata(x=x, y=y)
            mcaresult = fit.mcafit(x=x, xmin=x[70], xmax=x[500])
        else:
            data = scan.data()
            x = data[0, :]
            y = data[-1, :]
            fit.setdata(x=x, y=y)
            fit.estimate()
            fit.startfit()
        tab.fillfromfit(fit.paramlist)
    tab.show()
    qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"), app,
                       qt.SLOT("quit()"))
    if QTVERSION < '4.0.0':
        app.setMainWidget(tab)
        app.exec_loop()
    else:
        app.exec_()
Exemplo n.º 20
0
def main():
    app = qt.QApplication([])
    tab = HDF5CounterTable()
    tab.build(["Cnt1", "Cnt2", "Cnt3"])
    tab.setCounterSelection({
        'x': [1, 2],
        'y': [4],
        'cntlist': ["dummy", "Cnt0", "Cnt1", "Cnt2", "Cnt3"]
    })
    tab.show()
    app.exec_()
Exemplo n.º 21
0
def test():
    app = qt.QApplication([])
    qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"), app,
                       qt.SLOT('quit()'))

    container = RGBCorrelatorGraph()
    container.show()
    if QTVERSION < '4.0.0':
        app.setMainWidget(container)
        app.exec_loop()
    else:
        app.exec_()
Exemplo n.º 22
0
def test2():
    app = qt.QApplication([])
    qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"), app,
                       qt.SLOT('quit()'))

    dialog = NNMAParametersDialog()
    #dialog.setParameters({'options':[1,3,5,7,9],'method':1, 'npc':8,'binning':3})
    dialog.setModal(True)
    ret = dialog.exec_()
    if ret:
        dialog.close()
        print(dialog.getParameters())
Exemplo n.º 23
0
def test2(args):
    app = qt.QApplication(args)
    w = FrameBrowser()

    def slot(ddict):
        print(ddict)

    qt.QObject.connect(w, qt.SIGNAL("indexChanged"), slot)
    if len(args) > 1:
        w.setLimits(8, 20)
    w.show()
    app.exec_()
Exemplo n.º 24
0
def test():
    from PyMca import StackBase
    testFileName = "TiffTest.tif"
    nrows = 2000
    ncols = 2000
    #create a dummy stack with 100 images
    nImages = 100
    imagestack = True
    a = numpy.ones((nrows, ncols), numpy.float32)
    if not os.path.exists(testFileName):
        print("Creating test filename %s"  % testFileName)
        tif = TiffIO.TiffIO(testFileName, mode = 'wb+')

        for i in range(nImages):
            data = (a * i).astype(numpy.float32)
            if i == 1:
                tif = TiffIO.TiffIO(testFileName, mode = 'rb+')
            tif.writeImage(data,
                           info={'Title':'Image %d of %d' % (i+1, nImages)})
        tif = None

    stackData = TiffStack(imagestack=imagestack)
    stackData.loadFileList([testFileName], dynamic=True)

    if 0:
        stack = StackBase.StackBase()
        stack.setStack(stackData)
        print("This should be 0 = %f" %  stack.calculateROIImages(0, 0)['ROI'].sum())
        print("This should be %f = %f" %\
              (a.sum(),stack.calculateROIImages(1, 2)['ROI'].sum()))
        if imagestack:
            print("%f should be = %f" %\
                  (stackData.data[0:10,:,:].sum(),
                   stack.calculateROIImages(0, 10)['ROI'].sum()))
            print("Test small ROI 10 should be = %f" %\
                  stackData.data[10:11,[10],11].sum())
            print("Test small ROI 40 should be = %f" %\
                  stackData.data[10:11,[10,12,14,16],11].sum())
        else:
            print("%f should be = %f" %\
                  (stackData.data[:,:, 0:10].sum(),
                   stack.calculateROIImages(0, 10)['ROI'].sum()))
            print("Test small ROI %f" %\
                  stackData.data[10:11,[29],:].sum())
    else:
        from PyMca import PyMcaQt as qt
        from PyMca import QStackWidget
        app = qt.QApplication([])
        w = QStackWidget.QStackWidget()
        print("Setting stack")
        w.setStack(stackData)
        w.show()
        app.exec_()
Exemplo n.º 25
0
def test():
    app = qt.QApplication(sys.argv)
    app.connect(app, qt.SIGNAL("lastWindowClosed()"), app.quit)
    wid = SimpleFitConfigurationGUI()
    ddict = {}
    ddict['fit'] = {}
    ddict['fit']['use_limits'] = 1
    ddict['fit']['xmin'] = 1
    ddict['fit']['xmax'] = 1024
    wid.setConfiguration(ddict)
    wid.exec_()
    print(wid.getConfiguration())
    sys.exit()
Exemplo n.º 26
0
def main():
    app = qt.QApplication([])
    winpalette = qt.QPalette(qt.QColor(230, 240, 249),
                             qt.QColor(238, 234, 238))
    app.setPalette(winpalette)
    w = ElementsInfo()
    if qt.qVersion() < '4.0.0':
        app.setMainWidget(w)
        w.show()
        app.exec_loop()
    else:
        w.show()
        app.exec_()
Exemplo n.º 27
0
def testSimple():
    import sys
    import os
    filename = sys.argv[1]

    a = qt.QApplication(sys.argv)
    w = qt.QWidget()
    l = qt.QVBoxLayout(w)

    button = qt.QPushButton(w)
    button.setText("Print")

    scene = qt.QGraphicsScene()
    pixmapItem = qt.QGraphicsPixmapItem(
        qt.QPixmap.fromImage(qt.QImage(filename)))
    pixmapItem.setFlag(pixmapItem.ItemIsMovable, True)

    printer = qt.QPrinter(qt.QPrinter.HighResolution)
    printer.setFullPage(True)
    printer.setOutputFileName(os.path.splitext(filename)[0] + ".ps")

    page = qt.QGraphicsRectItem(0, 0, printer.width(), printer.height())
    scene.setSceneRect(qt.QRectF(0, 0, printer.width(), printer.height()))
    scene.addItem(page)
    scene.addItem(pixmapItem)
    view = qt.QGraphicsView(scene)
    view.fitInView(page.rect(), qt.Qt.KeepAspectRatio)
    #view.setSceneRect(
    view.scale(2, 2)

    #page.scale(0.05, 0.05)

    def printFile():
        painter = qt.QPainter(printer)
        scene.render(
            painter, qt.QRectF(0, 0, printer.width(), printer.height()),
            qt.QRectF(page.rect().x(),
                      page.rect().y(),
                      page.rect().width(),
                      page.rect().height()), qt.Qt.KeepAspectRatio)
        painter.end()

    l.addWidget(button)
    l.addWidget(view)
    w.resize(300, 600)
    w.show()
    w.connect(button, qt.SIGNAL('clicked()'), printFile)

    a.exec_()
Exemplo n.º 28
0
def test():
    import sys
    from PyMca import SpecFileLayer
    app = qt.QApplication([])
    tab = SpecFileMcaTable()
    d = SpecFileLayer.SpecFileLayer()
    if len(sys.argv) > 1:
        d.SetSource(sys.argv[1])
    else:
        d.SetSource('03novs060sum.mca')
    info, data = d.LoadSource('1.1')
    tab.build(info)
    tab.setSelectedMca(["1.1"])
    tab.show()
    app.exec_()
Exemplo n.º 29
0
def main(args):
    app = qt.QApplication(args)
    #tab = AttenuatorsTableWidget(None)
    if len(args) < 2:
        tab = AttenuatorsTab(None)
    elif len(args) > 3:
        tab = CompoundFittingTab(None)
    else:
        tab = MultilayerTab(None)
    if QTVERSION < '4.0.0':
        tab.show()
        app.setMainWidget(tab)
        app.exec_loop()
    else:
        tab.show()
        app.exec_()
Exemplo n.º 30
0
def testPreview():
    """
    """
    import sys
    import os.path

    if len(sys.argv) < 2:
        print("give an image file as parameter please.")
        sys.exit(1)

    if len(sys.argv) > 2:
        print("only one parameter please.")
        sys.exit(1)

    filename = sys.argv[1]

    a = qt.QApplication(sys.argv)

    p = qt.QPrinter()
    p.setOutputFileName(os.path.splitext(filename)[0] + ".ps")
    p.setColorMode(qt.QPrinter.Color)

    w = PyMcaPrintPreview(parent=None,
                          printer=p,
                          name='Print Prev',
                          modal=0,
                          fl=0)
    w.resize(400, 500)
    if QTVERSION < '4.0.0':
        w.addPixmap(qt.QPixmap(qt.QImage(filename)))
    else:
        w.addPixmap(qt.QPixmap.fromImage(qt.QImage(filename)))
    w.addImage(qt.QImage(filename))
    if 0:
        w2 = PyMcaPrintPreview(parent=None,
                               printer=p,
                               name='2Print Prev',
                               modal=0,
                               fl=0)
        w.exec_()
        w2.resize(100, 100)
        w2.show()
        sys.exit(w2.exec_())
    if QTVERSION < '4.0.0':
        sys.exit(w.exec_loop())
    else:
        sys.exit(w.exec_())