Esempio n. 1
0
    def testToPyspMonitorColumns(self):
        import random
        print "testZmqIfc.testToPyspMonitor1"

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

        hsh = HasyUtils.toPyspMonitor({'command': ['cls', 'delete']})
        self.assertEqual(hsh['result'], 'done')

        MAX = 25
        pos = np.linspace(0, 10, MAX)
        d1 = np.random.random_sample((len(pos), )) * 1000.
        d2 = np.random.random_sample((len(pos), )) * 1000.

        hsh = HasyUtils.toPyspMonitor({
            'putData': {
                'title':
                "testing putData & columns",
                'comment':
                "a comment",
                'columns': [{
                    'name': "eh_mot01",
                    'data': pos
                }, {
                    'name': "eh_c01",
                    'data': d1
                }, {
                    'name': "eh_c02",
                    'data': d2,
                    'symbolColor': 'blue',
                    'symbol': '+',
                    'symbolSize': 5,
                    'xLog': False,
                    'yLog': False,
                    'showGridX': False,
                    'showGridY': False
                }]
            }
        })
        self.assertEqual(hsh['result'], 'done')
        HasyUtils.toPyspMonitor({'command': ['display']})
        self.assertEqual(hsh['result'], 'done')
        time.sleep(1)

        #
        # retrieve the data
        #
        hsh = HasyUtils.toPyspMonitor({'getData': True})
        self.assertEqual(hsh['result'], 'done')
        #
        # ... and compare.
        #
        for i in range(MAX):
            self.assertEqual(pos[i], hsh['getData']['EH_C01']['x'][i])
            self.assertEqual(d1[i], hsh['getData']['EH_C01']['y'][i])
            self.assertEqual(d2[i], hsh['getData']['EH_C02']['y'][i])

        print "testZmqIfc.testToPyspMonitorColumns DONE"
        return
Esempio n. 2
0
    def testToPyspMonitorCompleteImagePutData(self):
        '''
        use putData to transfer a complete image at once
        '''
        print "testZmqIfc.testToPyspMonitor6"

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

        hsh = HasyUtils.toPyspMonitor({'command': ['cls', 'delete']})
        self.assertEqual(hsh['result'], 'done')
        hsh = HasyUtils.toPyspMonitor({'command': ['setWsViewport dina5s']})
        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)

        #
        # title: putData transfers the complete image at once
        #
        hsh = HasyUtils.toPyspMonitor({
            'command':
            ['setTitle "putData transfers the complete image at once"']
        })
        self.assertEqual(hsh['result'], 'done')

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

        hsh = HasyUtils.toPyspMonitor({'command': ['display']})
        self.assertEqual(hsh['result'], 'done')
        time.sleep(2)

        print "testZmqIfc.testToPyspMonitorCompleteImagePutData DONE"

        return
Esempio n. 3
0
def assertPyspMonitorRunning():
    """
    returns (status, wasLaunched)

    it tests whether the pyspMonitor responds to isAlive. 
    If so, the function return rather quickly.

    Otherwise we call assertProcessRunning() which may take some time
    """
    res = HasyUtils.toPyspMonitor({'isAlive': True}, testAlive=False)
    if res['result'] == 'done':
        return (True, False)
    else:
        #
        # even if the pyspMonitor does not reply to 'isAlive',
        # the process may exist
        #
        if utils.findProcessByName("/usr/bin/pyspMonitor.py"):
            utils.killProcess("/usr/bin/pyspMonitor.py")
        if utils.findProcessByName("/usr/bin/pyspMonitor3.py"):
            utils.killProcess("/usr/bin/pyspMonitor3.py")

        if HasyUtils.getPythonVersionSardana() == '/usr/bin/python':
            return utils.assertProcessRunning("/usr/bin/pyspMonitor.py")
        else:
            return utils.assertProcessRunning("/usr/bin/pyspMonitor3.py")
Esempio n. 4
0
    def test_toPyspMonitorScan(self):
        import random

        print "testIFC.test_toPyspMonitorScan"
        #
        # see, if the pyspMonitor is running. If not, return silently
        #
        hsh = HasyUtils.toPyspMonitor({'isAlive': True})
        if hsh['result'] != "done":
            print "test_toPyspMonitorScan: no pyspMonitor running"
            return

        ret = HasyUtils.toPyspMonitor({'command': ["cls", "delete"]})
        self.assertEqual(ret['result'], 'done')

        ret = HasyUtils.toPyspMonitor({
            'command': [
                "setTitle \"An important title\"",
                "setComment \"An interesting comment\""
            ]
        })
        self.assertEqual(ret['result'], 'done')

        max = 101
        name = "TestScan"
        ret = HasyUtils.toPyspMonitor({
            'Scan': {
                'name': name,
                'xMin': 0.,
                'xMax': 100.,
                'yMin': 0.,
                'yMax': 1.,
                'symbol': '+',
                'symbolColor': 'red',
                'symbolSize': 7,
                'lineColor': 'blue',
                'nPts': max,
                'autoscaleX': False,
                'autoscaleY': True
            }
        })
        self.assertEqual(ret['result'], 'done')

        for i in range(max):
            pos = float(i)
            posY = random.random() * 10
            HasyUtils.toPyspMonitor({
                'command':
                ['setXY %s %d %s %s' % (name, i, repr(pos), repr(posY))]
            })
            HasyUtils.toPyspMonitor({'command': ["display"]})
            time.sleep(0.1)

        print "testIFC.test_toPyspMonitorScan DONE"

        return
Esempio n. 5
0
def isPyspMonitorAliveNowInHasyUtils(node=None):
    '''
    returns True, if there is a pyspMonitor responding to the isAlive prompt
    '''
    hsh = HasyUtils.toPyspMonitor({'isAlive': True},
                                  node=node,
                                  testAlive=False)
    if hsh['result'] == 'notAlive':
        return False
    else:
        return True
Esempio n. 6
0
    def testToPyspMonitorSetPixelWorld(self):
        '''
        set the mandelbrot pixel in world coordinates
        '''
        print "testZmqIfc.testToPyspMonitor4"

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

        hsh = HasyUtils.toPyspMonitor({'command': ['cls', 'delete']})
        self.assertEqual(hsh['result'], 'done')
        hsh = HasyUtils.toPyspMonitor({'command': ['setWsViewport dina5s']})
        self.assertEqual(hsh['result'], 'done')
        #
        # title: set pixels using world coordinates
        #
        hsh = HasyUtils.toPyspMonitor(
            {'command': ['setTitle "set pixels using world coordinates"']})
        self.assertEqual(hsh['result'], 'done')

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

        hsh = HasyUtils.toPyspMonitor(hsh)
        self.assertEqual(hsh['result'], 'done')
        #
        # fill the image, pixel by pixel
        #
        r1 = np.linspace(xmin, xmax, width)
        r2 = np.linspace(ymin, ymax, height)
        startTime = time.time()
        for i in range(width):
            for j in range(height):
                res = mandelbrot(r1[i] + 1j * r2[j], maxiter)
                #
                # Speed:
                #   (50, 50) need 3.9s
                #   (50, 50) need 7s, with testAlive = True
                #
                hsh = {
                    'command': [
                        'setPixelWorld MandelBrot %g %g %g' %
                        (r1[i], r2[j], res)
                    ]
                }
                hsh = HasyUtils.toPyspMonitor(hsh)
                self.assertEqual(hsh['result'], 'done')
            hsh = HasyUtils.toPyspMonitor({'command': ['display']})
            self.assertEqual(hsh['result'], 'done')
        self.assertLess((time.time() - startTime), 5)
        time.sleep(1)
        print "testZmqIfc.testToPyspMonitorSetPixelWorld DONE"
        return
Esempio n. 7
0
    def testToPyspMonitorScan(self):
        import random
        print "testZmqIfc.testToPyspMonitor2"

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

        hsh = HasyUtils.toPyspMonitor({'command': ['cls', 'delete']})
        self.assertEqual(hsh['result'], 'done')

        MAX = 25
        pos = np.linspace(0, 10, MAX)
        d1 = np.random.random_sample((len(pos), )) * 1000.
        d2 = np.random.random_sample((len(pos), )) * 1000.

        HasyUtils.toPyspMonitor(
            {'command': ['setTitle "testing Scan command"']})
        self.assertEqual(hsh['result'], 'done')

        hsh = HasyUtils.toPyspMonitor(
            {'Scan': {
                'name': "d1",
                'x': pos,
                'y': d1
            }})
        self.assertEqual(hsh['result'], 'done')
        hsh = HasyUtils.toPyspMonitor(
            {'Scan': {
                'name': "d2",
                'x': pos,
                'y': d2
            }})
        self.assertEqual(hsh['result'], 'done')

        HasyUtils.toPyspMonitor({'command': ['setComment \"a comment\"']})
        self.assertEqual(hsh['result'], 'done')
        HasyUtils.toPyspMonitor({'command': ['display']})
        self.assertEqual(hsh['result'], 'done')
        time.sleep(1)
        #
        # retrieve the data and compare
        #
        hsh = HasyUtils.toPyspMonitor({'getData': True})
        for i in range(MAX):
            self.assertEqual(pos[i], hsh['getData']['D1']['x'][i])
            self.assertEqual(d1[i], hsh['getData']['D1']['y'][i])
            self.assertEqual(d2[i], hsh['getData']['D2']['y'][i])
        #
        # set y-values
        #
        HasyUtils.toPyspMonitor(
            {'command': ['setTitle "set y-values to linear"']})
        self.assertEqual(hsh['result'], 'done')
        for i in range(MAX):
            HasyUtils.toPyspMonitor(
                {'command': ['setY d1 %d %g' % (i, float(i) / 10.)]})

        HasyUtils.toPyspMonitor({'command': ['cls', 'display']})
        self.assertEqual(hsh['result'], 'done')
        time.sleep(1)

        print "testZmqIfc.testToPyspMonitorScan DONE"
        return
Esempio n. 8
0
    def testMoveScanInfo(self):

        print "testTangoIfc.testMoveScanInfo"

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

        PySpectra.cls()
        PySpectra.delete()
        #
        # senv ActiveMntGrp mg_pysp
        #
        if not utils.runMacro("senv ActiveMntGrp mg_pysp"):
            print("testTangoIfc.testMoveScanInfo: ruNMacro failed")
            return

        #
        # see, if the pyspMonitor process exists. Otherwise launch it
        #
        (status, wasLaunched) = PySpectra.assertPyspMonitorRunning()
        if not status:
            print(
                "testTangoIfc.testMoveScanInfo: failed to launch the pyspMonitor"
            )
            return
        #
        # move the motors to good starting points
        #
        if not utils.runMacro("umv eh_mot66 50 eh_mot67 12"):
            print("testTangoIfc.testMoveScanInfo: ruNMacro failed")
            return
        #
        # to the a2scan
        #
        if not utils.runMacro("a2scan eh_mot66 50 51 eh_mot67 12 13 40 0.1"):
            print("testTangoIfc.testMoveScanInfo: ruNMacro failed")
            return
        #
        # the pyspMonitor may still by 'scanning' although
        # we see that the scan is over. So test 'isAlive'
        #
        count = 0
        while 1:
            ret = HasyUtils.toPyspMonitor({'isAlive': True})
            if ret['result'] == 'done':
                break
            count += 1
            time.sleep(0.5)
            if count > 5:
                print("testTangoIfc.testMoveScanInfo: isAlive failes")
                return

        ret = HasyUtils.toPyspMonitor({'command': 'display sig_gen'})
        if ret['result'] != 'done':
            print(
                "testTangoIfc.testMoveScanInfo: 'display sig_gen' failed, %s" %
                repr(ret))
            return

        PySpectra.setTitle("moveStart sig_gen 50.5 False")
        res = HasyUtils.toPyspMonitor(
            {'command': 'moveStart sig_gen 50.5 False'})
        if res['result'] != 'done':
            print("testTangoIfc.testMoveScanInfo: moveStart failed failed")
            return

        while 1:
            if HasyUtils.toPyspMonitor({'getDoorState':
                                        True})['result'] == 'ON':
                break
            time.sleep(0.5)

        if wasLaunched:
            print("testTangoIfc.testMoveScanInfo: kill pyspMonitor.py")
            os.system("kill_proc -f pyspMonitor.py")

        print "testTangoIfc.testMoveScanInfo DONE"

        return
Esempio n. 9
0
    def test_toPyspLocalMonitorSetPixelWorld(self):
        '''
        this examples simulates the toPyspMonitor() interface
        replace toPyspLocal() by toPyspMonitor() to connect to pyspMonitor.py 
        '''
        print "testIFC.test_toPyspLocalSMonitorsetPixelWorld"
        #
        # see, if the pyspMonitor is running. If not, return silently
        #
        hsh = HasyUtils.toPyspMonitor({'isAlive': True})
        if hsh['result'] != "done":
            print "test_toPyspMonitorSetPixelWorld: no pyspMonitor running"
            return

        hsh = HasyUtils.toPyspMonitor(
            {'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 = HasyUtils.toPyspMonitor({
            '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 = HasyUtils.toPyspMonitor({
                    'command': [
                        "setPixelWorld MandelBrot %g %g %s" %
                        (r1[i], r2[j], repr(res))
                    ]
                })
                if hsh['result'] != "done":
                    print "error from setPixelWorld"
                    return
            HasyUtils.toPyspMonitor({'command': ['cls', 'display']})
        HasyUtils.toPyspMonitor({'command': ['cls']})
        HasyUtils.toPyspMonitor({'command': ['display']})

        print "testIFC.test_toPyspLocalSMonitorsetPixelWorld, DONE"

        return