Example #1
0
        def run(self):

            print("Storeman::run(): STARTED")
            boardId = self.ni6682Obj.board_id.data()

            # Arm the channels
            for i in range(0, 3):

                tm = self.ni6682Obj.triggerModeDict[getattr(
                    self.ni6682Obj, 'channel_pfi%d_trig_mode' % (i)).data()]
                decimation = getattr(self.ni6682Obj,
                                     'channel_pfi%d_decimation' % (i)).data()

                print("Storeman::run(): boardId: ", boardId,
                      "channel PFI%d," % (i), " tm: ", tm, " decimation: ",
                      decimation)

                self.ni6682Obj.libts.NI6682_ArmChannel(c_int(boardId),
                                                       c_int(i), c_int(tm),
                                                       c_int(decimation))

            # Main loop of the thread
            while self.keepWorking:

                for i in range(0, 3):

                    sec = c_int()
                    nsec = c_int()

                    # Get the data
                    tmp = self.ni6682Obj.libts.NI6682_GetTimestamp(
                        c_int(boardId), c_int(i), byref(sec), byref(nsec))
                    while tmp != -1:

                        t = Int64(sec.value * 1000000000) + Int64(nsec.value)
                        #t = Int64(sec.value<<32) + Int64(nsec.value);
                        #print "Storeman::run(): time = ", t.value

                        # Int64Array([sec.value]) is necessary, Int64Array(sec.value) does not work.
                        getattr(self.ni6682Obj,
                                'channel_pfi%d_time_sec' % (i)).putRow(
                                    Int64(1), Int64Array([sec.value]), t)
                        getattr(self.ni6682Obj,
                                'channel_pfi%d_time_nsec' % (i)).putRow(
                                    Int64(1), Int64Array([nsec.value]), t)

                        tmp = self.ni6682Obj.libts.NI6682_GetTimestamp(
                            c_int(boardId), c_int(i), byref(sec), byref(nsec))

                sleep(0.25)

            # Disarm the channels
            for i in range(0, 3):

                self.ni6682Obj.libts.NI6682_DisarmChannel(
                    c_int(boardId), c_int(i))
                pass

            print("Storeman::run(): STOPPED")
Example #2
0
 def scaled(self):
     with Tree(self.tree, self.shot + 7, 'NEW') as ptree:
         node = ptree.addNode('S')
         ptree.write()
     ptree.normal()
     srt, end, dt = -1000, 1000, 1000
     d = Int64Array(range(srt, end + 1, dt))
     v = Int16Array(range(srt, end + 1, dt))
     node.makeSegment(srt, end, d, v)
     self.assertEqual(True, (node.getSegment(0).data() == v.data()).all())
     node.setSegmentScale(Int64(2))
     self.assertEqual(node.getSegmentScale().decompile(), "$VALUE * 2Q")
     self.assertEqual(
         ptree.tdiExecute("GetSegmentScale(S)").decompile(), "$VALUE * 2Q")
     self.assertEqual(True, (node.record.data() == v.data() * 2).all())
     node.setSegmentScale(Int16Array([1, 2]))
     self.assertEqual(True, (node.record.data() == v.data() * 2 + 1).all())
     self.assertEqual(True, (node.getSegment(0) == v * 2 + 1).all())
     self.assertEqual(
         ptree.tdiExecute("GetSegment(S,0)").decompile(),
         "Build_Signal($VALUE * 2W + 1W, Word([-1000,0,1000]), [-1000Q,0Q,1000Q])"
     )
     ptree.tdiExecute("SetSegmentScale(S,as_is($VALUE+1D0))")
     self.assertEqual(
         ptree.tdiExecute("S").decompile(),
         "Build_Signal($VALUE + 1D0, Word([-1000,0,1000]), [-1000Q,0Q,1000Q])"
     )
Example #3
0
        def test():
            from MDSplus import Tree, Int64, Int64Array, Int32Array, tdi, tcl
            #Tree.setTimeContext() # test initPinoDb
            #self.assertEquals(Tree.getTimeContext(),(None,None,None))
            with Tree(self.tree, self.shot, 'NEW') as ptree:
                node = ptree.addNode('S')
                ptree.write()
            node.tree = Tree(self.tree, self.shot)
            for i in range(-9, 9, 3):
                d = Int64Array(range(3)) * 10 + i * 10
                v = Int32Array(range(3)) + i
                node.beginSegment(d[0], d[2], d, v)
            self.assertEqual(
                node.getSegmentList(20, 59).dim_of(0).tolist(), [0, 30])
            self.assertEqual(
                node.getSegmentList(20, 60).dim_of(0).tolist(), [0, 30, 60])
            self.assertEqual(
                node.getSegmentList(21, 60).dim_of(0).tolist(), [30, 60])
            self.assertEqual(node.record.data().tolist(), list(range(-9, 9)))
            node.tree.setTimeContext(Int64(30), Int64(70), Int64(20))
            #        Tree.setTimeContext(1,2,3) # test privacy to Tree
            self.assertEquals(node.tree.getTimeContext(), (30, 70, 20))
            #       self.assertEquals(Tree.getTimeContext(),(1,2,3))
            self.assertEqual(node.record.data().tolist(),
                             [3, 5] + [6])  # delta is applied per segment
            node.tree.setTimeContext()

            self.assertEquals(node.tree.getTimeContext(), (None, None, None))
            self.assertEqual(node.record.data().tolist(), list(range(-9, 9)))

            #self.assertEquals(Tree.getTimeContext(),(1,2,3))
            tdi('treeopen($,$)', self.tree, self.shot)
            Tree.setTimeContext(1, 2, 3)  # test privacy to Tree
            self.assertEquals(Tree.getTimeContext(), (1, 2, 3))
            tdi('treeopennew($,$)', self.tree, self.shot + 1)
            self.assertEquals(Tree.getTimeContext(), (None, None, None))
            Tree.setTimeContext(2, 3, 4)  # test privacy to Tree
            self.assertEquals(Tree.getTimeContext(), (2, 3, 4))
            tdi('treeopen($,$)', self.tree, self.shot)
            self.assertEquals(Tree.getTimeContext(), (1, 2, 3))
            tdi('treeclose()')
            self.assertEquals(Tree.getTimeContext(), (2, 3, 4))
            tdi('treeclose()', self.tree, self.shot)
            self.assertEquals(Tree.getTimeContext(), (1, 2, 3))
Example #4
0
 def test():
     from MDSplus import Tree, Int32, Int64, Dimension, Range, Window, DIVIDE, ADD, MULTIPLY
     from numpy import arange, ones, int16, int64
     slp = 3.3
     off = 1.1
     trg = -1000000
     clk = 1000000
     with Tree(self.tree, self.shot, 'NEW') as ptree:
         sig = ptree.addNode('SIG').record = ADD(
             MULTIPLY(ptree.addNode('RAW'), ptree.addNode('SLP')),
             ptree.addNode('OFF'))
         ptree.addNode('TRG').record = Int64(trg)
         ptree.addNode('CLK').record = Int32(clk)
         ptree.write()
     ptree = Tree(self.tree, self.shot)
     trig = ptree.TRG
     raw = ptree.RAW
     sig = ptree.SIG
     dt = DIVIDE(Int64(1e9), ptree.CLK)
     rng = Range(None, None, dt)
     wnd = Window(None, None, trig)
     ptree.SLP.record = slp
     ptree.OFF.record = off
     length, seglen = 100, 10
     dat = ones(seglen, dtype=int16)
     for i0 in range(0, length, seglen):
         i1 = i0 + seglen - 1
         wnd[0], wnd[1] = Int64(i0), Int64(i1)
         dim = Dimension(wnd, rng)
         d0 = Int64(i0 * dt + trig)
         d1 = Int64(i1 * dt + trig)
         self.assertEqual(dim.data()[0], d0.data())
         self.assertEqual(dim.data()[-1], d1.data())
         raw.makeSegment(d0, d1, dim, dat)
     self.assertEqual(
         str(raw.getSegment(0)),
         "Build_Signal(Word([1,1,1,1,1,1,1,1,1,1]), *, Build_Dim(Build_Window(0Q, 9Q, TRG), * : * : 1000000000Q / CLK))"
     )
     self.assertEqual(str(sig.record), "RAW * SLP + OFF")
     self.assertTrue(sig.dim_of().tolist(),
                     (arange(0, length, dtype=int64) * int(1e9 / clk) +
                      trg).tolist())
     self.assertTrue(
         (abs(sig.data() -
              (ones(length, dtype=int16) * slp + off)) < 1e-5).all(),
         "Stored data does not match expected array")
     #        ptree.close()
     #        ptree.compressDatafile() # this will break the functionality of updateSegment
     #        ptree.open()
     trig.record = 0
     for i in range(int(length / seglen)):
         dim = raw.getSegmentDim(i)
         raw.updateSegment(dim.data()[0], dim.data()[-1], dim, i)
     self.assertEqual(
         str(raw.getSegment(0)),
         "Build_Signal(Word([1,1,1,1,1,1,1,1,1,1]), *, Build_Dim(Build_Window(0Q, 9Q, TRG), * : * : 1000000000Q / CLK))"
     )
     self.assertTrue(sig.dim_of().tolist(),
                     (arange(0, length, dtype=int64) *
                      int(1e9 / clk)).tolist())
Example #5
0
 def test():
     from MDSplus import Tree, Int64, Int64Array, Int32Array
     with Tree(self.tree, self.shot, 'NEW') as ptree:
         node = ptree.addNode('S')
         ptree.write()
     node.tree = Tree(self.tree, self.shot)
     for i in range(-9, 9, 3):
         d = Int64Array(range(3)) * 10 + i * 10
         v = Int32Array(range(3)) + i
         node.beginSegment(d[0], d[2], d, v)
     self.assertEqual(
         node.getSegmentList(20, 59).dim_of(0).tolist(), [0, 30])
     self.assertEqual(
         node.getSegmentList(20, 60).dim_of(0).tolist(), [0, 30, 60])
     self.assertEqual(
         node.getSegmentList(21, 60).dim_of(0).tolist(), [30, 60])
     self.assertEqual(node.record.data().tolist(), list(range(-9, 9)))
     node.tree.setTimeContext(Int64(30), Int64(70), Int64(20))
     self.assertEqual(node.record.data().tolist(),
                      [3, 5] + [6])  # delta is applied per segment
     node.tree.setTimeContext()
     self.assertEqual(node.record.data().tolist(), list(range(-9, 9)))
Example #6
0
 def CompressTimestampedSegments(self):
     from MDSplus import Tree, Int32, Int64
     with Tree(self.tree,self.shot+10,'NEW') as ptree:
         s = ptree.addNode('s', 'SIGNAL')
         ptree.write()
     ptree.normal()
     for i in range(2):  # time is even, data is odd
         data = [i*10+j*2 for j in range(5)]
         s.makeTimestampedSegment(Int64(data), Int32(data)+1)
     before = s.record
     ptree.compressDatafile()
     ptree.readonly()
     after = s.record
     self.assertEqual(True,(before.data()==after.data()).all(), "%r != %r" % (before.value, after.value) )
     self.assertEqual(True,(before.dim_of().data()==after.dim_of().data()).all(), "%r != %r" % (before.dim_of(), after.dim_of()))
Example #7
0
        def run(self):

            poll = select.poll()
            for fd in self.device.devFd:
                if fd == -1:
                    continue
                print("Poll register fd", fd)
                poll.register(fd, select.POLLIN)

            nTimestamps = c_int(1000)
            #ts = self.device.nisyncTimestampNanos()
            ts = (self.device.nisyncTimestampNanos * 1000)()

            try:
                tai_utc_delay = self.device.taiutc_delay.data()
            except:
                tai_utc_delay = 37000000000
                self.device.taiutc_delay.putData(Int64(tai_utc_delay))

            timeout = 1000
            ts_nanos_prev = 0
            while not self.stopReq:
                poolfd = poll.poll(timeout)
                for fd1, event in poolfd:
                    print("fd    = ", fd1)
                    print("event = ", event)
                    count = NI6683REC.NiSyncLib.nisync_read_timestamps_ns(
                        fd1, byref(ts), nTimestamps)
                    print("count = ", count)
                    print("------------------------------------------------")
                    for i in range(count):
                        print(1000000000. / (ts[i].nanos - ts_nanos_prev),
                              ts[i].nanos, count)
                        dt = datetime.fromtimestamp(ts[i].nanos // 1000000000)
                        dt_str = dt.strftime('%Y-%m-%d %H:%M:%S') + "." + str(
                            int(((ts[i].nanos - tai_utc_delay) %
                                 1000000000))).zfill(9)
                        print(dt_str)

                        nids = self.device.timeNid[fd1]
                        try:
                            if (len(nids) == 2):
                                print(nids[0].getPath())
                                nids[0].putData(Int64(ts[i].nanos))
                                print(nids[0].getPath())
                                nids[1].putData(dt_str)
                            else:
                                print(nids[0].getPath())
                                nids[0].putRow(1000, Int64(ts[i].nanos),
                                               Int64(ts[i].nanos))
                        except BaseException as e:
                            print(e)
                            print('Error save timestamp')
                        """
                       try:
                           self.device.pulse_time_tai_ns.putData( Int64(ts.nanos))
                           self.device.pulse_time_tai_s.putData(Int64(ts.nanos//1000000000))
                           self.device.pulse_time_date.putData(dt_str)
                       except BaseException as e:
                           print e
                           print('Error save timestamp')
                       """
                        ts_nanos_prev = ts[i].nanos
                    #break
                    print("------------------------------------------------")
                time.sleep(1)

            for fd in self.device.devFd:
                if fd == -1:
                    continue
                poll.unregister(fd)

            print('AsynchStore stop')

            return
Example #8
0
    def time_context(self):
        Tree.setTimeContext()  # test initPinoDb
        self.assertEqual(Tree.getTimeContext(), (None, None, None))
        with Tree(self.tree, self.shot + 5, 'NEW') as ptree:
            node = ptree.addNode('S')
            ptree.write()
        ptree.normal()
        for i in range(-90, 90, 30):
            d = Int64Array(range(30)) * 10 + i * 10
            v = Float32Array(range(30)) + i
            node.makeSegment(d[0], d[29], d, v)
        self.assertEqual(
            node.getSegmentList(200, 599).dim_of(0).tolist(), [0, 300])
        self.assertEqual(
            node.getSegmentList(200, 600).dim_of(0).tolist(), [0, 300, 600])
        self.assertEqual(
            node.getSegmentList(291, 600).dim_of(0).tolist(), [300, 600])
        self.assertEqual(node.record.data().tolist(), list(range(-90, 90)))

        sig = node.getXYSignal(xmin=0., xmax=3e-8, num=5)
        self.assertEqual(sig.data().tolist(), [0, 1, 2, 3])
        self.assertEqual(sig.dim_of().data().tolist(), [0, 10, 20, 30])

        node.tree.setTimeContext(Int64(300), Int64(700), Int64(150))
        Tree.setTimeContext(1, 2, 3)
        self.assertEqual(Tree.getTimeContext(), (1, 2, 3))
        self.assertEqual(node.tree.getTimeContext(), (300, 700, 150))

        set_default_resample_mode("m")  # minmax
        sig = node.record
        self.assertEqual(sig.data().tolist(), [30, 44, 45, 59, 60, 74])
        self.assertEqual(sig.dim_of().data().tolist(),
                         [375, 375, 525, 525, 675, 675])

        set_default_resample_mode("i")  # interpolation
        sig = node.record
        self.assertEqual(sig.data().tolist(), [30, 45, 60])
        self.assertEqual(sig.dim_of().data().tolist(), [300, 450, 600])

        node.setExtendedAttribute("ResampleMode", "Average")
        sig = node.record
        self.assertEqual(sig.data().tolist(), [37, 52, 67])
        self.assertEqual(sig.dim_of().data().tolist(), [375, 525, 675])

        node.setExtendedAttribute("ResampleMode", "MinMax")
        sig = node.record
        self.assertEqual(sig.data().tolist(), [30, 44, 45, 59, 60, 74])
        self.assertEqual(sig.dim_of().data().tolist(),
                         [375, 375, 525, 525, 675, 675])

        node.setExtendedAttribute("ResampleMode", "INTERP")
        sig = node.record
        self.assertEqual(sig.data().tolist(), [30, 45, 60])
        self.assertEqual(sig.dim_of().data().tolist(), [300, 450, 600])

        node.setExtendedAttribute("ResampleMode", "Previous")
        sig = node.record
        self.assertEqual(sig.data().tolist(), [30, 44, 60])
        self.assertEqual(sig.dim_of().data().tolist(), [300, 450, 600])

        node.setExtendedAttribute("ResampleMode", "Closest")
        sig = node.record
        self.assertEqual(sig.data().tolist(), [30, 45, 60])
        self.assertEqual(sig.dim_of().data().tolist(), [300, 450, 600])

        node.tree.setTimeContext()
        self.assertEqual(node.tree.getTimeContext(), (None, None, None))
        self.assertEqual(node.record.data().tolist(), list(range(-90, 90)))
        self.assertEqual(Tree.getTimeContext(), (1, 2, 3))
        tdi('treeopen($,$)', self.tree, self.shot + 5)
        Tree.setTimeContext(1, 2, 3)  # test privacy to Tree
        self.assertEqual(Tree.getTimeContext(), (1, 2, 3))
        tdi('treeopennew($,$)', self.tree, self.shot + 6)
        self.assertEqual(Tree.getTimeContext(), (None, None, None))
        Tree.setTimeContext(2, 3, 4)  # test privacy to Tree
        self.assertEqual(Tree.getTimeContext(), (2, 3, 4))
        tdi('treeopen($,$)', self.tree, self.shot + 5)
        self.assertEqual(Tree.getTimeContext(), (1, 2, 3))
        tdi('treeclose()')
        self.assertEqual(Tree.getTimeContext(), (2, 3, 4))
        tdi('treeclose()')
        self.assertEqual(Tree.getTimeContext(), (2, 3, 4))