예제 #1
0
 def data(self):
     self.assertEqual(m.Data(0x80000000).__class__, m.Int64)
     self.assertEqual(m.Data(0x7fffffff).__class__, m.Int32)
     if m.version.ispy2:
         self.assertEqual(m.Data(long(1)).__class__, m.Int64)
     a = m.ADD(m.Int32(1), m.Int32(2))
     self.assertEqual(m.MULTIPLY(a, a).decompile(), "(1 + 2) * (1 + 2)")
     self.assertEqual(m.Data(2).compare(2), True)
     self.assertEqual(m.Data(2).compare(1), False)
     self.assertEqual(
         m.Dictionary([1, 'a', 2, 'b']).data().tolist(), {
             1: 'a',
             2: 'b'
         })
     self.assertEqual(
         m.List([1, 'a', 2, 'b']).data().tolist(), [1, 'a', 2, 'b'])
     a = m.Apd()
     e = m.Data(1)
     e.tree = 'dummy_e'
     f = m.Data(2)
     f.tree = 'dummy_f'
     self.assertEqual(a.tree, None)
     a.append(e)  # a should use tree of e
     self.assertEqual(a.tree, e.tree)
     self.assertEqual(a[0].tree, e.tree)
     a.append(f)  # a should keep tree of e
     self.assertEqual(a.tree, e.tree)
     self.assertEqual(a[1].tree, f.tree)
     self._doUnaryArray(m.Int32(range(10)), m.Int32Array(range(10)),
                        'Int32(range(10))')
예제 #2
0
def DevAddPythonDevice(path, model, nidout=None):
    """Add a python device to the tree.

    1) finding the model in the list defined by
       the tdi function, MdsDevices.
    2) try importing the package for the model and calling its Add method.

    Both the path and model are passed in as Ident instances.
    The StringArray returned by MdsDevices() contains String instances
    containing blank filled values containing an \0 character embedded.
    These Strings have to be manipulated to produce simple str() values.
    """

    import sys
    import MDSplus

    model = str(model.data()).strip()
    path = str(path.data()).strip()
    try:
        node = MDSplus.Device.PyDevice(model).Add(MDSplus.Tree(), path)
        if isinstance(nidout, (MDSplus.Ident, )):
            MDSplus.Data.execute("$=$", nidout, MDSplus.Int32(node.nid))
        return MDSplus.TreeSUCCESS.status
    except MDSplus.MDSplusException:
        return sys.exc_info()[1].status
    except Exception:
        print("Error adding device instance of %s: %s" %
              (model, sys.exc_info()[1]))
        return MDSplus.MDSplusERROR.status
예제 #3
0
 def testmds(cfg="/etc/xcap_cygnet4k.fmt"):
     """Test MDSplus device."""
     import gc
     gc.collect()
     MDSplus.setenv('test_path', '/tmp')
     from devices.cygnet4k import CYGNET4K
     with MDSplus.Tree('test', 1, 'NEW') as t:
         dev = CYGNET4K.Add(t, "CYGNET4K")
         t.write()
         dev.conf_file.no_write_shot = False
         dev.conf_file = cfg
         dev.roi_rect.no_write_shot = False
         dev.roi_rect = MDSplus.Int32((128, 128, 512, 512))
     old = MDSplus.Device.debug
     MDSplus.Device.debug = 0  # max(1, old)
     t.open()
     try:
         dev.init()
         time.sleep(1)
         dev.start()
         time.sleep(1)
         dev.stop()
     finally:
         dev.deinit()
         print(dev.frames_percentile.getRecord(None))
         t.close()
         MDSplus.Device.debug = old
예제 #4
0
 def testmds(expt='test', shot=1):
     import gc
     gc.collect()
     MDSplus.setenv('test_path', '/tmp')
     from LocalDevices.cygnet4k import CYGNET4K
     with MDSplus.Tree(expt, shot, 'NEW') as t:
         dev = CYGNET4K.Add(t, "CYGNET4K")
         t.write()
         dev.conf_file.no_write_shot = False
         dev.conf_file = "/etc/xcap_cygnet4k.fmt"
         dev.roi_rect.no_write_shot = False
         dev.roi_rect = MDSplus.Int32([500, 500, 1000, 1000])
     old = MDSplus.Device.debug
     MDSplus.Device.debug = 0  #max(1,old)
     t.open()
     try:
         dev.init()
         sleep(1)
         dev.start()
         sleep(1)
         dev.stop()
     finally:
         dev.deinit()
         print(dev.frames_max.getRecord(None))
         t.close()
         MDSplus.Device.debug = old
예제 #5
0
 def decompile(self):
     self.assertEqual(str(m.Uint8(123)), '123BU')
     self.assertEqual(str(m.Uint16(123)), '123WU')
     self.assertEqual(str(m.Uint32(123)), '123LU')
     self.assertEqual(str(m.Uint64(123)), '123QU')
     self.assertEqual(str(m.Int8(123)), '123B')
     self.assertEqual(str(m.Int16(123)), '123W')
     self.assertEqual(str(m.Int32(123)), '123')
     self.assertEqual(str(m.Int64(123)), '123Q')
     self.assertEqual(
         str(m.Signal(m.ZERO(100000, 0).evaluate(), None, 0)),
         "Build_Signal(Set_Range(100000,0 /*** etc. ***/), *, 0)")
예제 #6
0
 def run(self):
     try:
         self.dev.tree.open()
         while not self.lib.is_stored(1):
             if not self.on:
                 return
             time.sleep(.1)
         cinfo = self.lib.get_cinfo()
         self.dev.store_cinfo(cinfo)
         rate = float(cinfo['rate'])
         self.update(self.dev.frame_rate,
                     (MDSplus.Float64(rate).setUnits('Hz')))
         self.update(self.dev.exposure,
                     (MDSplus.Int32(cinfo['exp']).setUnits('ns')))
         num_cine = len(self.lib.cstats())
         Q = queue.Queue(30)
         writer = self.Writer(self, Q)
         writer.start()
         try:
             for c in range(1, num_cine + 1):
                 while not self.lib.is_triggered(c):
                     if not self.on:
                         return  # end of measurement
                     time.sleep(.1)
                 self.lib.wait_stored(c)
                 for trig, imgs in self.lib.read_images(
                         0,
                         cine=c,
                         debug=self.dev.debug,
                         port=self.dev._host_port):
                     while writer.is_alive():
                         try:
                             Q.put((trig, imgs), True, 1)
                         except queue.Full:
                             continue
                         else:
                             break
                     else:
                         break
         finally:
             Q.put(None)  # indicate last frame to end thread
             writer.join()
             if hasattr(writer, "exception"):
                 self.exception = writer.exception
     except Exception as e:
         self.exception = e
         traceback.print_exc()
예제 #7
0
 def tdiFunctions(self):
     m.dTRUE = m.__dict__['$TRUE']
     m.dFALSE = m.__dict__['$FALSE']
     from MDSplus import mdsExceptions as Exc
     """Test Exceptions"""
     self._doExceptionTest('abort()', Exc.TdiABORT)
     self._doExceptionTest('{,}', Exc.TdiSYNTAX)
     self._doExceptionTest('\033[[A', Exc.TdiBOMB)
     self._doExceptionTest('abs()', Exc.TdiMISS_ARG)
     self._doExceptionTest('abs("")', Exc.TdiINVDTYDSC)
     self._doExceptionTest('abs(1,2)', Exc.TdiEXTRA_ARG)
     self._doExceptionTest('"', Exc.TdiUNBALANCE)
     """Test $Missing/NoData/None"""
     self._doTdiTest('', None)
     """Test abs"""
     self._doThreeTest('abs(cmplx(3.0,4.0))', m.ABS(m.Complex64(3. + 4.j)),
                       m.Float32(5.))
     """Test abs1"""
     self._doThreeTest('abs1(cmplx(3.0,4.0))',
                       m.ABS1(m.Complex64(3. + 4.j)), m.Float32(7.))
     """Test abssq"""
     self._doThreeTest('abssq(cmplx(3.0,4.0))',
                       m.ABSSQ(m.Complex64(3. + 4.j)), m.Float32(25.))
     """Test accumulate"""
     self._doThreeTestArray('accumulate([1,2,3])',
                            m.ACCUMULATE(m.makeArray([1, 2, 3])),
                            m.Int32Array([1, 3, 6]))
     self._doThreeTestArray(
         'accumulate([[1,3,5],[2,4,6]])',
         m.ACCUMULATE(m.makeArray([[1, 3, 5], [2, 4, 6]])),
         m.Int32Array([[1, 4, 9], [11, 15, 21]]))
     self._doThreeTestArray(
         'accumulate([[1,3,5],[2,4,6]],0)',
         m.ACCUMULATE(m.makeArray([[1, 3, 5], [2, 4, 6]]), 0),
         m.Int32Array([[1, 4, 9], [2, 6, 12]]))
     #self._doThreeTestArray('accumulate([[1,3,5],[2,4,6]],1)',m.ACCUMULATE([[1,3,5],[2,4,6]],1),m.Int32Array([[1,3,5],[3,7,11]]))  # tdi issue
     self._doUnaryArray(
         m.Data.execute('accumulate([[1,3,5],[2,4,6]],1)'),
         m.ACCUMULATE(m.makeArray([[1, 3, 5], [2, 4, 6]]), 1).getData())
     """Test achar"""
     self._doThreeTest('achar(88)', m.ACHAR(88), m.String('X'))
     """Test ADJUSTL"""
     self._doThreeTest('adjustl(" WORD")', m.ADJUSTL(" WORD"),
                       m.String("WORD "))
     """Test ADJUSTR"""
     self._doThreeTest('adjustr("WORD ")', m.ADJUSTR("WORD "),
                       m.String(" WORD"))
     """Test AIMAG"""
     self._doThreeTest('AIMAG(CMPLX(2.0,3.0))', m.AIMAG(m.CMPLX(2., 3.)),
                       m.Float32(3.0))
     """Test AINT"""
     self._doThreeTest('aint(2.783)', m.AINT(2.783), m.Float32(2.0))
     self._doThreeTest('aint(-2.783)', m.AINT(-2.783), m.Float32(-2.0))
     """Test NE (operates on flattened array, i.e. first 3 values are compared)"""
     A, B = m.makeArray([1, 3, 5]), m.makeArray([[0, 3, 5], [0, 0, 0],
                                                 [0, 4, 8]])
     self._doThreeTestArray(
         '_A=[1,3,5],_B=[[0,3,5],[0,0,0],[0,4,8]],_A ne _B', m.NE(A, B),
         m.Uint8Array([1, 0, 0]))
     """Test NE (operates on flattened array, i.e. first 3 values are compared)"""
     self._doThreeTestArray('_A eq _B', m.EQ(A, B), m.Uint8Array([0, 1, 1]))
     """Test ALL and ANY"""
     self._doThreeTest('all([$TRUE,$FALSE,$TRUE])',
                       m.ALL(m.makeArray([1, 0, 1])), m.Uint8(0))
     self._doThreeTest('any([$TRUE,$FALSE,$TRUE])',
                       m.ANY(m.makeArray([1, 0, 1])), m.Uint8(1))
     A = 0
     self._doThreeTest('_A=0,all(_A eq _B)', m.ALL(m.EQ(A, B)), False)
     self._doThreeTest('any(_A ne _B)', m.ANY(m.NE(A, B)), True)
     self._doThreeTestArray('all(_A ne _B,0)', m.ALL(m.NE(A, B), 0),
                            m.Uint8Array([0, 0, 0]))
     self._doThreeTestArray('any(_A ne _B,0)', m.ANY(m.NE(A, B), 0),
                            m.Uint8Array([1, 0, 1]))
     self._doThreeTestArray('all(_A eq _B,1)', m.ALL(m.EQ(A, B), 1),
                            m.Uint8Array([1, 0, 0]))
     self._doThreeTestArray('any(_A ne _B,1)', m.ANY(m.NE(A, B), 1),
                            m.Uint8Array([0, 1, 1]))
     """Test allocated"""
     self.assertEqual(m.DEALLOCATE('*') >= 2,
                      True)  # deallocates _A and _B and more?
     self.assertEqual(m.ALLOCATED('_xyz'), m.Uint8(0))
     self._doTdiTest('_xyz=0,allocated("_xyz")', m.Uint8(1))
     self.assertEqual(m.ALLOCATED('_xyz'), m.Uint8(1))
     self.assertEqual(m.DEALLOCATE('*'), m.Uint8(1))
     self.assertEqual(m.ALLOCATED('_xyz'), m.Uint8(0))
     """Test AND"""
     A, B = m.makeArray([0, 0, 1, 1]), m.makeArray([0, 1, 0, 1])
     self._doThreeTestArray('_A=[0,0,1,1],_B=[0,1,0,1],_A && _B',
                            m.AND(A, B), m.Uint8Array([0, 0, 0, 1]))
     """Test AND_NOT"""
     self._doThreeTestArray('_A AND_NOT _B', m.AND_NOT(A, B),
                            m.Uint8Array([0, 0, 1, 0]))
     """Test ANINT"""
     self._doThreeTest('ANINT(2.783)', m.ANINT(2.783), m.Float32(3.0))
     """Test ARG"""
     self._doTdiTest(
         'execute("abs(arg(cmplx(3.0,4.0)) - .9272952) < .000001")',
         m.Uint8(1))
     """Test ARGD"""
     self._doTdiTest(
         'execute("abs(argd(cmplx(3.0,4.0)) - 53.1301) < .000001")',
         m.Uint8(1))
     """Test arg_of"""
     self._doThreeTest('arg_of(pub->foo(42,43))',
                       m.ARG_OF(m.Call('pub', 'foo', 42, 43)), m.Int32(42))
     self._doThreeTest('arg_of(pub->foo(42,43),1)',
                       m.ARG_OF(m.Call('pub', 'foo', 42, 43), 1),
                       m.Int32(43))
     self._doThreeTest('arg_of(1+3,1)', m.ARG_OF(m.ADD(1, 3), 1),
                       m.Int32(3))
     """Test Array"""
     self._doThreeTestArray('array(10)', m.ARRAY(10),
                            m.Float32Array([0] * 10))
     self._doThreeTestArray('array(10,0)', m.ARRAY(10, 0),
                            m.Int32Array([0] * 10))
     self._doThreeTestArray('array(10,0BU)', m.ARRAY(10, m.Uint8(0)),
                            m.Uint8Array([0] * 10))
     self._doThreeTestArray('zero(100)', m.ZERO(100),
                            m.Float32Array([0] * 100))