Ejemplo n.º 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))')
Ejemplo n.º 2
0
                def run(self):
                    def time_rel(ns=1e9):
                        return MDSplus.DIVIDE(MDSplus.Int64(ns),
                                              self.frame_rate)

                    try:
                        cur_frame = 0
                        rng = MDSplus.Range(None, None, time_rel())
                        while True:
                            try:
                                queued = self.queue.get(True, 1)
                            except queue.Empty:
                                if self.strm.on:
                                    continue
                                break  # measurement done
                            if queued is None:
                                break
                            trigger, frames = queued
                            if self.fsttrig is None:
                                self.fsttrig = trigger
                            trigger = MDSplus.Int64(trigger - self.fsttrig)
                            trg = MDSplus.ADD(self.trigger, trigger)
                            first_frame = cur_frame
                            for ic in range(frames.shape[0]):
                                dim = MDSplus.ADD(trg,
                                                  time_rel([cur_frame * 1e9]))
                                limit = MDSplus.ADD(trg,
                                                    time_rel(cur_frame * 1e9))
                                data = frames[ic:ic + 1]
                                self.frames.makeSegment(
                                    limit, limit, dim, data)
                                cur_frame += 1
                            last_frame = cur_frame - 1
                            win = MDSplus.Window(first_frame, last_frame, trg)
                            start = MDSplus.ADD(trg,
                                                time_rel(first_frame * 1e9))
                            end = MDSplus.ADD(trg, time_rel(last_frame * 1e9))
                            dim = MDSplus.Dimension(win, rng)
                            frames = frames.reshape(
                                (frames.shape[0], -1)).max(1)
                            self.frames_max.makeSegment(
                                start, end, dim, frames)
                            self.queue.task_done()
                    except Exception as e:
                        self.exception = e
                        traceback.print_exc()
Ejemplo n.º 3
0
 def setChanScale(self, node, num):
     #Raw input channel, where the conditioning has been applied:
     input_chan = self.__getattr__('INPUT_%3.3d' % num)
     chan = self.__getattr__(node)
     #Un-conditioning the signal:
     chan.setSegmentScale(
         MDSplus.ADD(
             MDSplus.DIVIDE(
                 MDSplus.MULTIPLY(input_chan.COEFFICIENT, MDSplus.dVALUE()),
                 MDSplus.MULTIPLY(input_chan.SC_GAIN1,
                                  input_chan.SC_GAIN2)),
             MDSplus.SUBTRACT(input_chan.OFFSET, input_chan.SC_OFFSET)))
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
 def setChanScale(self,num):
     chan=self.__getattr__('INPUT_%3.3d' % num)
     chan.setSegmentScale(MDSplus.ADD(MDSplus.MULTIPLY(chan.COEFFICIENT,MDSplus.dVALUE()),chan.OFFSET))