Ejemplo n.º 1
0
    def testYToMinusY( self):

        print "testCalc.testYToMinusY"

        PySpectra.cls()
        PySpectra.delete()
        scan = PySpectra.Scan( name = "t1", xMin = 2., xMax = 10.0, nPts = 201)
        scan.y = np.sin( scan.y)

        with self.assertRaises( ValueError) as context:
            calc.yToMinusY( name = None)
        #print("testSetXY: %s" %  repr( context.exception))
        self.assertTrue( "calc.yToMinusY: name not specified"
                         in context.exception)

        with self.assertRaises( ValueError) as context:
            calc.yToMinusY( name = "notExist")
        #print("testSetXY: %s" %  repr( context.exception))
        self.assertTrue( "calc.yToMinusY: failed to find notExist"
                         in context.exception)

        scanMY = calc.yToMinusY( name = scan.name, nameNew = "t1_y2MinusY")
        self.assertEqual( len( scan.y), len( scanMY.y))
        self.assertEqual( len( scan.x), len( scanMY.x))
        
        for i in range( len( scan.y)):
            self.assertEqual( scan.y[i], - scanMY.y[i])
            self.assertEqual( scan.x[i], scanMY.x[i])
        
        PySpectra.display()
        #PySpectra.show()
        PySpectra.processEventsLoop( 1)

        print "testCalc.testYToMinusY, DONE"
Ejemplo n.º 2
0
    def test_setX_Y(self):
        import random

        print "testIFC.test_setX_Y"
        PySpectra.command("cls")
        PySpectra.command("delete")

        max = 50
        PySpectra.command("create s1 0 10 %d" % max)

        s1 = PySpectra.getGqe("s1")
        self.assertEqual(s1.currentIndex, 49)
        self.assertEqual(s1.lastIndex, -1)
        PySpectra.command("display")
        self.assertEqual(s1.lastIndex, (max - 1))

        for i in range(max):
            PySpectra.command("setY s1 %d %g" % (i, random.random() * 10))
            PySpectra.command("setX s1 %d %g" % (i, float(i) / 100.))
            self.assertEqual(s1.currentIndex, i)
            PySpectra.command("display")
            time.sleep(0.1)

        PySpectra.processEventsLoop(1)
        print "testIFC.test_setX_Y DONE"

        return
Ejemplo n.º 3
0
    def test_setArrow(self):

        print "testIFC.test_setArrow"
        PySpectra.command("cls")
        PySpectra.command("delete")
        max = 20
        PySpectra.command(
            "setComment \"Arrows: Current: 5, Misc: 2, SetPoint: 6\"")
        PySpectra.command("create s1 0 10 %d" % max)

        gqe = PySpectra.getGqe("s1")
        gqe.motorNameList = ["eh_mot66"]

        PySpectra.command("setArrowCurrent s1 position 5.")
        PySpectra.command("setArrowMisc s1 position 2.")
        PySpectra.command("setArrowSetPoint s1 position 6.")
        PySpectra.command("display")
        PySpectra.processEventsLoop(1)

        pos = 5
        for i in range(20):
            pos = 5 + float(i) * 0.05
            PySpectra.command("setArrowCurrent s1 position %g" % pos)
            time.sleep(0.1)

        print "testIFC.test_setArrow DONE"
        return
Ejemplo n.º 4
0
    def testFillData(self):
        print "testPySpectra.testFillData"
        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle("scan.setY()")
        scan = PySpectra.Scan(name='t1',
                              xLabel="up to 200 pts",
                              nPts=201,
                              yMin=-10.,
                              yMax=10.)
        self.assertEqual(scan.currentIndex, 200)
        #scan.y = np.tan( scan.x)

        startTime = time.time()
        for i in range(len(scan.y)):
            scan.setY(i, math.tan(float(i) / 10))
            PySpectra.display()

        diffTime = time.time() - startTime
        self.assertLess(diffTime, 12)

        PySpectra.display()
        PySpectra.processEventsLoop(1)

        print "testPySpectra.testFillData, DONE"
Ejemplo n.º 5
0
    def testFillScan(self):

        graPyspIfc.setSpectra(False)

        graPyspIfc.cls()
        graPyspIfc.delete()

        scan = graPyspIfc.Scan(name="s1", color="blue", nPts=101)

        scan.y = numpy.random.normal(size=(101))
        scan.x = numpy.linspace(0., 10., 101)

        scan.display()
        PySpectra.processEventsLoop(1)

        if utils.getHostname() != definitions.hostTK:
            return

        graPyspIfc.setSpectra(True)

        graPyspIfc.cls()
        graPyspIfc.delete()

        scan = graPyspIfc.Scan(name="s1", color="blue", nPts=101)

        scan.y = numpy.random.normal(size=(101))
        scan.x = numpy.linspace(0., 10., 101)

        scan.display()
        time.sleep(1)

        graPyspIfc.close()
Ejemplo n.º 6
0
    def testCreateScansByGqes(self):

        print "testPySpectra.testCreateScansByGqes"
        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle("create scan by putData-gqes")

        x = np.linspace(0., 10., 100)
        tan = np.tan(x)
        sin = np.sin(x)
        cos = np.cos(x)

        hsh = {
            'putData': {
                'gqes': [{
                    'x': x,
                    'y': tan,
                    'name': 'tan'
                }, {
                    'x': x,
                    'y': cos,
                    'name': 'cos'
                }, {
                    'x': x,
                    'y': sin,
                    'name': 'sin',
                    'showGridY': False,
                    'symbolColor': 'blue',
                    'showGridX': True,
                    'yLog': False,
                    'symbol': '+',
                    'xLog': False,
                    'symbolSize': 5
                }]
            }
        }

        PySpectra.toPyspLocal(hsh)

        lst = PySpectra.getGqeList()
        self.assertEqual(len(lst), 3)

        self.assertEqual(lst[0].name, 'tan')
        self.assertEqual(lst[1].name, 'cos')
        self.assertEqual(lst[2].name, 'sin')

        comparison = x == lst[0].x
        self.assertTrue(comparison.all())
        comparison = tan == lst[0].y
        self.assertTrue(comparison.all())
        comparison = cos == lst[1].y
        self.assertTrue(comparison.all())
        comparison = sin == lst[2].y
        self.assertTrue(comparison.all())
        PySpectra.display()

        PySpectra.processEventsLoop(1)

        #utils.launchGui()
        print "testPySpectra.testCreateScansByGqes, DONE"
Ejemplo n.º 7
0
    def test_doty(self):

        print "testPySpectra.test_doty"

        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle("2 plots, the seconds has doty as the x-axis")

        scan1 = PySpectra.Scan(name="notdotyscan",
                               xMin=10.,
                               xMax=30.0,
                               nPts=101,
                               dType=np.float64,
                               lineColor='red',
                               lineStyle='solidLine')
        self.assertEqual(scan1.doty, False)

        scan2 = PySpectra.Scan(name="dotyscan",
                               xMin=10.,
                               xMax=30.0,
                               nPts=101,
                               dType=np.float64,
                               doty=True,
                               lineColor='red',
                               lineStyle='solidLine')

        self.assertEqual(scan2.doty, True)

        PySpectra.display()
        PySpectra.processEventsLoop(1)

        print "testPySpectra.test_doty DONE"
Ejemplo n.º 8
0
    def test_createScanByLimit(self):

        print "testPySpectra.test_createScanByLimit"

        PySpectra.cls()
        PySpectra.delete()

        PySpectra.setTitle("create scan by limits")
        scan = PySpectra.Scan(name="test1",
                              xMin=0.,
                              xMax=1.0,
                              nPts=101,
                              dType=np.float64,
                              at=(2, 2, 3),
                              lineColor='red',
                              lineStyle='solidLine')
        self.assertEqual(scan.xMin, 0.)
        self.assertEqual(scan.xMax, 1.)
        self.assertEqual(scan.nPts, 101)
        self.assertEqual(scan.dType, np.float64)
        self.assertEqual(len(scan.x), 101)
        self.assertEqual(scan.x.dtype, np.float64)
        self.assertEqual(len(scan.y), 101)
        self.assertEqual(scan.y.dtype, np.float64)

        self.assertEqual(scan.lineColor, 'red')

        PySpectra.display()
        PySpectra.processEventsLoop(1)
        print "testPySpectra.test_createScanByLimit DONE"
Ejemplo n.º 9
0
    def testTextOnlyScan(self):

        print("testPySpectra.testTextOnlyScan")

        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle("test textOnly Scans")

        g = PySpectra.Scan(name="textContainer", textOnly=True)

        g.addText(name="testText", text="some text to be displayed")

        self.assertEqual(len(g.textList), 1)
        txt = g.textList[0]
        self.assertEqual(txt.name, "testText")
        self.assertEqual(txt.hAlign, "left")
        self.assertEqual(txt.vAlign, "top")
        self.assertEqual(txt.color, "black")
        self.assertEqual(txt.x, 0.5)
        self.assertEqual(txt.y, 0.5)
        self.assertEqual(txt.NDC, True)

        g.display()
        PySpectra.processEventsLoop(1)
        return
Ejemplo n.º 10
0
    def test_read(self):

        print "testPySpectra.test_read"

        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle("the graphics window should contain 24 plots")
        PySpectra.read("%s/test/data/ti_au_tio2_sio2_kat55a_0001.fio" %
                       pySpectraPath)
        lst = PySpectra.getGqeList()
        self.assertEqual(len(lst), 24)
        self.assertEqual(lst[0].name, "TI_AU_TIO2_SIO2_KAT55A_0001")
        self.assertEqual(lst[1].name, "TI_AU_TIO2_SIO2_KAT55A_0001_RING")

        PySpectra.display()
        PySpectra.processEventsLoop(1)

        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle("the graphics window should contain 4 plots")
        PySpectra.read("%s/test/data/SPLITTER_PXE_BL_22_2.dat" % pySpectraPath)
        lst = PySpectra.getGqeList()
        self.assertEqual(len(lst), 4)
        self.assertEqual(lst[0].name, "scan1")
        self.assertEqual(lst[1].name, "scan2")
        self.assertEqual(lst[2].name, "scan3")
        self.assertEqual(lst[3].name, "scan4")

        PySpectra.display()
        PySpectra.processEventsLoop(1)

        print "testPySpectra.test_read DONE"
Ejemplo n.º 11
0
    def testAddText(self):

        print("testPySpectra.testAddText")

        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle("test addText")

        g = utils.createGauss()
        g.addText(name="testText",
                  x=0.2,
                  y=0.1,
                  color='magenta',
                  fontSize=20,
                  text="dies ist ein addText test text")

        self.assertEqual(len(g.textList), 1)
        txt = g.textList[0]
        self.assertEqual(txt.name, "testText")
        self.assertEqual(txt.hAlign, "left")
        self.assertEqual(txt.vAlign, "top")
        self.assertEqual(txt.color, "magenta")
        self.assertEqual(txt.fontSize, 20)
        self.assertEqual(txt.x, 0.2)
        self.assertEqual(txt.y, 0.1)
        self.assertEqual(txt.NDC, True)

        g.display()
        PySpectra.processEventsLoop(1)
        return
Ejemplo n.º 12
0
    def testDisplayTwo( self): 

        print "testGraphics.testDisplayTwo"

        PySpectra.cls()
        PySpectra.delete()

        sinus = PySpectra.Scan( name = 'sinus', xMin = 0., 
                                xMax = 6.0, nPts = 101, dType = np.float64,
                                lineWidth = 5., 
                                lineColor = 'red', lineStyle = 'dashed')
        sinus.y = np.sin( sinus.y)

        cosinus = PySpectra.Scan( name = "cosinus", xMin = 0., 
                                  xMax = 6.0, nPts = 101, dType = np.float64,
                                  lineWidth = 3., 
                                  lineColor = 'blue', 
                                  lineStyle = 'dotted')
        cosinus.y = np.cos( cosinus.y)

        PySpectra.display()
        #PySpectra.show()
        PySpectra.processEventsLoop( 1)

        print "testGraphics.testDisplayTwo, DONE"
Ejemplo n.º 13
0
    def testClose( self): 
        '''
        '''
        print "testGraphics.testClose"

        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle( "testing close()")

        sinus = PySpectra.Scan( name = 'sinus', 
                                xMin = 0., xMax = 6.0, nPts = 101, lineColor = 'red', doty = True)
        sinus.y = np.sin( sinus.y)

        PySpectra.display()
        PySpectra.processEventsLoop( 1)

        PySpectra.close()

        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle( "testing close(), again")

        sinus = PySpectra.Scan( name = 'sinus', 
                                xMin = 0., xMax = 6.0, nPts = 101, lineColor = 'red', doty = True)
        sinus.y = np.sin( sinus.y)

        PySpectra.display()
        PySpectra.processEventsLoop( 1)

        print "testGraphics.testClose, DONE"
Ejemplo n.º 14
0
    def testCreateScan(self):

        graPyspIfc.setSpectra(False)

        graPyspIfc.cls()
        graPyspIfc.delete()

        scan = graPyspIfc.Scan(name="s1", lineColor="red", nPts=201)
        self.assertEqual(scan.xMin, 0.)
        self.assertEqual(scan.xMax, 10.)
        self.assertEqual(scan.lineColor, "red")
        self.assertEqual(scan.nPts, 201)
        scan.display()

        PySpectra.processEventsLoop(1)

        if utils.getHostname() != definitions.hostTK:
            return

        graPyspIfc.setSpectra(True)

        graPyspIfc.cls()
        graPyspIfc.delete()

        scan = graPyspIfc.Scan(name="s1", lineColor="blue", nPts=201)

        self.assertEqual(scan.xMin, 0.)
        self.assertEqual(scan.xMax, 10.)
        self.assertEqual(scan.lineColor, "blue")
        self.assertEqual(scan.nPts, 201)
        scan.display()
        time.sleep(1)
        graPyspIfc.close()
Ejemplo n.º 15
0
    def testAntiDerivative( self):

        print "testCalc.testAntiDerivative"


        PySpectra.cls()
        PySpectra.delete()
        scan = PySpectra.Scan( name = "t1", xMin = 0., xMax = 10.0, nPts = 201)
        scan.y = np.sin( scan.y)

        with self.assertRaises( ValueError) as context:
            calc.antiderivative( name = None)
        #print("testSetXY: %s" %  repr( context.exception))
        self.assertTrue( "calc.antiderivative: name not specified"
                         in context.exception)

        with self.assertRaises( ValueError) as context:
            calc.derivative( name = "notExist")
        self.assertTrue( "calc.derivative: failed to find notExist"
                         in context.exception)
        calc.antiderivative( name = scan.name, nameNew = "t1_ad")
        PySpectra.display()
        #PySpectra.show()
        PySpectra.processEventsLoop( 1)

        print "testCalc.testAntiDerivative, DONE"
Ejemplo n.º 16
0
    def testToPyspLocalSetPixelWorld(self):
        '''
        set the mandelbrot pixel in world coordinates
        '''
        print "testZmqIfc.testToPyspLocalSetPixelWorld"
        hsh = PySpectra.toPyspLocal({'command': ['cls', 'delete']})
        self.assertEqual(hsh['result'], 'done')
        hsh = PySpectra.toPyspLocal({'command': ['setWsViewport dina5s']})
        self.assertEqual(hsh['result'], 'done')
        #
        # title: set pixels using world coordinates
        #
        hsh = PySpectra.toPyspLocal(
            {'command': ['setTitle "set pixels using world coordinates"']})
        self.assertEqual(hsh['result'], 'done')

        (xmin, xmax) = (-2., -0.5)
        (ymin, ymax) = (0, 1.5)
        (width, height) = (100, 100)
        maxiter = 25
        #
        # create the image
        #
        hsh = {
            'Image': {
                'name': "MandelBrot",
                'xMin': xmin,
                'xMax': xmax,
                'width': width,
                'yMin': ymin,
                'yMax': ymax,
                'height': height
            }
        }

        hsh = PySpectra.toPyspLocal(hsh)
        self.assertEqual(hsh['result'], 'done')
        #
        # fill the image, pixel by pixel
        #
        r1 = np.linspace(xmin, xmax, width)
        r2 = np.linspace(ymin, ymax, height)
        for i in range(width):
            for j in range(height):
                res = mandelbrot(r1[i] + 1j * r2[j], maxiter)
                hsh = {
                    'command': [
                        'setPixelWorld MandelBrot %g %g %g' %
                        (r1[i], r2[j], res)
                    ]
                }
                hsh = PySpectra.toPyspLocal(hsh)
                self.assertEqual(hsh['result'], 'done')
            hsh = PySpectra.toPyspLocal({'command': ['display']})
            self.assertEqual(hsh['result'], 'done')
        PySpectra.processEventsLoop(1)

        print "testZmqIfc.testToPyspLocalSetPixelWorld DONE"
        return
Ejemplo n.º 17
0
    def test_toPyspLocalSetPixelWorld(self):
        '''
        this examples simulates the toPyspMonitor() interface
        replace toPyspLocal() by toPyspMonitor() to connect to pyspMonitor.py 
        '''
        print "testIFC.test_toPyspLocalSetPixelWorld"
        hsh = PySpectra.toPyspLocal(
            {'command': ['cls', 'delete', 'setWsViewport DINA5S']})
        if hsh['result'] != "done":
            print "error from ['delete', 'setWsViewport DINA5S', 'cls']"
            return

        (xmin, xmax) = (-2., -0.5)
        (ymin, ymax) = (0, 1.5)
        (width, height) = (100, 100)
        maxiter = 25

        #
        # create the image
        #
        hsh = PySpectra.toPyspLocal({
            'Image': {
                'name': "MandelBrot",
                'xMin': xmin,
                'xMax': xmax,
                'width': width,
                'yMin': ymin,
                'yMax': ymax,
                'height': height
            }
        })
        if hsh['result'] != "done":
            print "error from Image", repr(hsh)
            return
        #
        # fill the image, pixel by pixel
        #
        r1 = np.linspace(xmin, xmax, width)
        r2 = np.linspace(ymin, ymax, height)
        for i in range(width):
            for j in range(height):
                res = mandelbrot(r1[i] + 1j * r2[j], maxiter)
                hsh = PySpectra.toPyspLocal({
                    'command': [
                        "setPixelWorld MandelBrot %g %g %s" %
                        (r1[i], r2[j], repr(res))
                    ]
                })
                if hsh['result'] != "done":
                    print "error from setPixelWorld"
                    return
            PySpectra.toPyspLocal({'command': ['cls', 'display']})
        PySpectra.toPyspLocal({'command': ['cls']})
        PySpectra.toPyspLocal({'command': ['display']})
        PySpectra.processEventsLoop(1)

        print "testIFC.test_toPyspLocalSetPixelWorld, DONE"
        return
Ejemplo n.º 18
0
    def testToPyspLocalCompleteImageByImage(self):
        '''
        use Image to transfer a complete image at once
        '''
        print "testZmqIfc.testToPyspLocalCompleteImageByImage"
        hsh = PySpectra.toPyspLocal({'command': ['cls', 'delete']})
        self.assertEqual(hsh['result'], 'done')
        hsh = PySpectra.toPyspLocal({'command': ['setWsViewport dina5s']})
        self.assertEqual(hsh['result'], 'done')
        #
        # setTitle
        #
        hsh = PySpectra.toPyspLocal({
            'command':
            ['setTitle "use Imageto transfer the complete image at once"']
        })
        self.assertEqual(hsh['result'], 'done')

        (xmin, xmax) = (-2., -0.5)
        (ymin, ymax) = (0, 1.5)
        (width, height) = (100, 100)
        maxiter = 25
        #
        # fill the image, pixel by pixel
        #
        r1 = np.linspace(xmin, xmax, width)
        r2 = np.linspace(ymin, ymax, height)
        data = np.ndarray((width, height), np.float64)
        for i in range(width):
            for j in range(height):
                res = mandelbrot(r1[i] + 1j * r2[j], maxiter)
                data[i][j] = int(res)

        hsh = PySpectra.toPyspLocal({
            'Image': {
                'name': "MandelBrot",
                'data': data,
                'xMin': xmin,
                'xMax': xmax,
                'yMin': ymin,
                'yMax': ymax,
            }
        })
        self.assertEqual(hsh['result'], 'done')

        hsh = PySpectra.toPyspLocal({'command': ['cls', 'display']})
        self.assertEqual(hsh['result'], 'done')
        o = PySpectra.getGqe("Mandelbrot")
        self.assertEqual(o.height, 100)
        self.assertEqual(o.width, 100)
        self.assertEqual(o.xMin, xmin)
        self.assertEqual(o.xMax, xmax)
        self.assertEqual(o.yMin, ymin)
        self.assertEqual(o.yMax, ymax)
        PySpectra.processEventsLoop(2)

        print "testZmqIfc.testToPyspLocalCompleteImageByImage DONE"
        return
Ejemplo n.º 19
0
 def test_execTests(self):
     '''
     get the functions of ./PySpectra/examples/exampleCode.py and execute them
     '''
     for funcName in dir(PySpectra.examples.exampleCode):
         if funcName.find('example') != 0:
             continue
         cmd = "PySpectra.examples.exampleCode.%s()" % funcName
         print("testExamples: executing %s" % cmd)
         exec cmd
         print("%s DONE" % cmd)
         PySpectra.processEventsLoop(1)
     return
Ejemplo n.º 20
0
    def testOverlay( self): 

        print "testGraphics.testOverlay"

        PySpectra.cls()
        PySpectra.delete()

        sinus = PySpectra.Scan( name = 'sinus', xMin = 0., 
                                xMax = 6.0, nPts = 101, dType = np.float64,
                                lineWidth = 5., 
                                lineColor = 'red', lineStyle = 'dashed')
        sinus.y = np.sin( sinus.y)

        tan = PySpectra.Scan( name = 'tangens', xMin = 0., 
                              xMax = 6.0, nPts = 101, dType = np.float64,
                              lineWidth = 2., 
                              lineColor = 'green', lineStyle = 'dashed')
        tan.y = np.tan( tan.y)
        #
        # cosinus has to be plotted in the same viewport as sinus
        #
        cosinus = PySpectra.Scan( name = "cosinus", xMin = 0., 
                                  xMax = 6.0, nPts = 101, dType = np.float64,
                                  lineWidth = 3., 
                                  lineColor = 'blue', 
                                  overlay = "sinus", 
                                  lineStyle = 'dotted')
        self.assertEqual( cosinus.overlay, 'sinus')

        cosinus.y = np.cos( cosinus.y)
        #
        # cossquare has to be plotted in the same viewport as tangens
        #
        cossquare = PySpectra.Scan( name = "cossquare", xMin = 0., 
                                    xMax = 6.0, nPts = 101, dType = np.float64,
                                    yMin = -5, yMax = 5., 
                                    lineWidth = 1., 
                                    overlay = 'tangens', 
                                    lineColor = 'blue', 
                                    lineStyle = 'dotted')
        self.assertEqual( cossquare.overlay, 'tangens')

        cossquare.y = np.cos( tan.x) * np.cos( tan.x)

        PySpectra.display()
        #PySpectra.show()
        PySpectra.processEventsLoop( 1)

        print "testGraphics.testOverlay, DONE"
Ejemplo n.º 21
0
def main():
    t1 = pysp.Scan( name = "t1", color = 'blue', yLabel = 'sin')
    t1.y = np.sin( t1.x)
    t1.currentIndex = 10
    
    t2 = pysp.Scan( name = "t2", color = 'blue', yLabel = 'rand')
    t2.y = np.random.random_sample( (len( t2.x), ))
    
    for i in range( 10, len( t1.x)):
        t1.currentIndex = i
        pysp.display()
        t2.y = np.random.random_sample( (len( t2.x), ))
        t2.lastIndex = 0

    pysp.processEventsLoop()
Ejemplo n.º 22
0
    def testSinusScan(self):

        graPyspIfc.setSpectra(False)

        graPyspIfc.cls()
        graPyspIfc.delete()
        sinus = graPyspIfc.Scan(name="sinus",
                                lineColor='blue',
                                xMin=-5,
                                xMax=5.,
                                yMin=-1.5,
                                yMax=1.5,
                                nPts=21,
                                yLabel='sin')

        sinus.y = numpy.sin(sinus.x)

        sinus.display()
        self.assertEqual(sinus.getCurrent(), 20)
        PySpectra.processEventsLoop(1)

        if utils.getHostname() != definitions.hostTK:
            return

        graPyspIfc.setSpectra(True)

        graPyspIfc.cls()
        graPyspIfc.delete()

        sinus = graPyspIfc.Scan(name="sinus",
                                lineColor='blue',
                                xMin=-5,
                                xMax=5.,
                                yMin=-1.5,
                                yMax=1.5,
                                nPts=21,
                                yLabel='sin')

        sinus.y = numpy.sin(sinus.x)

        sinus.display()

        time.sleep(2)

        self.assertEqual(sinus.getCurrent(), 20)

        graPyspIfc.close()
Ejemplo n.º 23
0
    def testDisplaySymbol( self): 

        print "testGraphics.testDisplaySymbol"

        PySpectra.cls()
        PySpectra.delete()

        sinus = PySpectra.Scan( name = 'sinus', xMin = 0., 
                                xMax = 6.0, nPts = 101, dType = np.float64,
                                at = (2,2,3), symbolColor = 'red', symbol = 'o', symbolSize = 10)

        sinus.y = np.sin( sinus.y)
        PySpectra.display( ['sinus'])
        #PySpectra.show()
        PySpectra.processEventsLoop( 1)

        print "testGraphics.testDisplaySymbol. DONE"
Ejemplo n.º 24
0
    def testToPyspLocalCompleteImageWithGetData(self):
        '''
        use Image to transfer a complete image at once
        '''
        print "testZmqIfc.testToPyspLocalCompleteImageWithGetData"

        hsh = PySpectra.toPyspLocal({'command': ['cls', 'delete']})
        self.assertEqual(hsh['result'], 'done')
        hsh = PySpectra.toPyspLocal({'command': ['setWsViewport dina5s']})
        self.assertEqual(hsh['result'], 'done')
        (xmin, xmax) = (-2., -0.5)
        (ymin, ymax) = (0, 1.5)
        (width, height) = (20, 20)
        maxiter = 25
        #
        # fill the image, pixel by pixel
        #
        r1 = np.linspace(xmin, xmax, width)
        r2 = np.linspace(ymin, ymax, height)
        data = np.ndarray((width, height), np.float64)
        for i in range(width):
            for j in range(height):
                res = mandelbrot(r1[i] + 1j * r2[j], maxiter)
                data[i][j] = int(res)

        hsh = PySpectra.toPyspLocal({
            'Image': {
                'name': "MandelBrot",
                'data': data,
                'xMin': xmin,
                'xMax': xmax,
                'yMin': ymin,
                'yMax': ymax,
            }
        })
        self.assertEqual(hsh['result'], 'done')

        hsh = PySpectra.toPyspLocal({'command': ['display']})
        self.assertEqual(hsh['result'], 'done')

        hsh = PySpectra.toPyspLocal({'getData': True})
        print("testZmqIfc: %s" % repr(hsh))
        PySpectra.processEventsLoop(2)

        print "testZmqIfc.testToPyspLocalCompleteImageWithGetData DONE"
        return
Ejemplo n.º 25
0
    def testSSA(self):
        print "testPySpectra.testSSA"
        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle("test SSA")

        g = utils.createGauss(name="gauss",
                              xMin=-5.,
                              xMax=5.,
                              nPts=101,
                              lineColor='red',
                              x0=0.,
                              sigma=1.,
                              amplitude=1.)

        g.ssa()
        self.assertEqual(len(g.textList), 5)

        # SSA results
        # midpoint: -6.84879e-06
        # peak-x:   0
        # cms:      -9.65309e-05
        # fwhm:     2.3552
        #
        self.assertTrue(g.textList[0].text == 'SSA results')

        lst = g.textList[1].text.split(':')
        self.assertTrue(lst[0] == 'midpoint')
        self.assertTrue(abs(float(lst[1])) < 0.0001)

        lst = g.textList[2].text.split(':')
        self.assertTrue(lst[0] == 'peak-x')
        self.assertTrue(abs(float(lst[1])) < 0.0001)

        lst = g.textList[3].text.split(':')
        self.assertTrue(lst[0] == 'cms')
        self.assertTrue(abs(float(lst[1])) < 0.0001)

        lst = g.textList[4].text.split(':')
        self.assertTrue(lst[0] == 'fwhm')
        self.assertTrue(abs(float(lst[1])) < 2.356)
        self.assertTrue(abs(float(lst[1])) > 2.350)

        PySpectra.display()
        PySpectra.processEventsLoop(1)
        return
Ejemplo n.º 26
0
    def testReUse(self):
        print "testPySpectra.testReUse"
        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle("test re-use")

        nPts = 100
        scan = PySpectra.Scan(name='t1',
                              xLabel="%s pts, going to be re-used" % nPts,
                              nPts=nPts)
        for i in range(10):
            PySpectra.cls()
            PySpectra.display()
            PySpectra.processEventsLoop(1)
            scan.x = np.linspace(0., 10., 100)
            scan.y = np.random.normal(size=(101))

        return
Ejemplo n.º 27
0
    def testImageMB2( self): 
        print "testGraphics.testImageMB2"

        PySpectra.setWsViewport( 'DINA5S')

        PySpectra.cls()
        PySpectra.delete()

        (xmin, xmax) = (-2., 1)
        (ymin, ymax) = (-1.5, 1.5)
        (width, height) = (300, 300)
        maxiter = 20
        #
        # create the image by supplying the limits
        #
        m = PySpectra.Image( name = "MandelbrotSet2", 
                             xMin = xmin, xMax = xmax, width = width,  
                             yMin = ymin, yMax = ymax, height = height, 
                             xLabel = "eh_mot01", yLabel = "eh_mot02")

        r1 = np.linspace(xmin, xmax, width)
        r2 = np.linspace(ymin, ymax, height)
        for i in range(width):
            for j in range(height):
                res = self.mandelbrot(r1[i] + 1j*r2[j],maxiter)
                m.setPixelWorld( x = r1[i], y = r2[j], value = res)

            PySpectra.cls()
            PySpectra.display()
        PySpectra.processEventsLoop(1)

        self.assertEqual( m.xMin, xmin)
        self.assertEqual( m.xMax, xmax)
        self.assertEqual( m.yMin, ymin)
        self.assertEqual( m.yMax, ymax)
        self.assertEqual( m.height, height)
        self.assertEqual( m.width, width)
        #
        # to understand '+ 1'consider : x [-2, 1], width 100
        #  if x == 1 -> ix == 100, so we need '+ 1'
        #
        self.assertEqual( m.data.shape[0], width)
        self.assertEqual( m.data.shape[1], height)
        return 
Ejemplo n.º 28
0
    def testDoty( self): 
        '''
        using showGridX, showGridY
        '''
        print "testGraphics.testDoty"

        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle( "check x-axis doty")

        sinus = PySpectra.Scan( name = 'sinus', 
                                xMin = 0., xMax = 6.0, nPts = 101, lineColor = 'red', doty = True)
        sinus.y = np.sin( sinus.y)

        PySpectra.display()
        #PySpectra.show()
        PySpectra.processEventsLoop( 1)

        print "testGraphics.testDoty, DONE"
Ejemplo n.º 29
0
    def testImageMB1( self): 
        print "testGraphics.testImageMB1"

        PySpectra.setWsViewport( 'DINA5S')

        PySpectra.cls()
        PySpectra.delete()

        (xmin, xmax) = (-2., 1)
        (ymin, ymax) = (-1.5, 1.5)
        (width, height) = (500, 500)
        maxiter = 20

        r1 = np.linspace(xmin, xmax, width)
        r2 = np.linspace(ymin, ymax, height)
        n3 = np.empty((width, height))
        for i in range(width):
            for j in range(height):
                n3[i,j] = self.mandelbrot(r1[i] + 1j*r2[j],maxiter)
        #
        # create the image by supplying data
        #
        m = PySpectra.Image( name = "MandelbrotSet1", data = n3,
                             xMin = xmin, xMax = xmax, width = width,  
                             yMin = ymin, yMax = ymax, height = height, 
                             xLabel = "eh_mot01", yLabel = "eh_mot02")

        PySpectra.display()

        self.assertEqual( m.xMin, xmin)
        self.assertEqual( m.xMax, xmax)
        self.assertEqual( m.yMin, ymin)
        self.assertEqual( m.yMax, ymax)
        self.assertEqual( m.height, height)
        self.assertEqual( m.width, width)
        #
        # to understand '+ 1'consider : x [-2, 1], width 100
        #  if x == 1 -> ix == 100, so we need '+ 1'
        #
        self.assertEqual( m.data.shape[0], width)
        self.assertEqual( m.data.shape[1], height)

        PySpectra.processEventsLoop( 2)
Ejemplo n.º 30
0
    def test_readMca_v1(self):

        print "testPySpectra.test_readMca_v1"

        PySpectra.cls()
        PySpectra.delete()
        PySpectra.setTitle("the graphics window should contain 1 MCA plot")
        PySpectra.read("%s/test/data/tst_09153_mca_s1.fio" % pySpectraPath,
                       flagMCA=True)
        lst = PySpectra.getGqeList()
        self.assertEqual(len(lst), 1)
        self.assertEqual(lst[0].name, "d1_mca01")
        self.assertEqual(lst[0].nPts, 2048)

        PySpectra.display()
        #PySpectra.show()
        PySpectra.processEventsLoop(1)

        print "testPySpectra.test_readMca_v1 DONE"