コード例 #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")
コード例 #2
0
ファイル: segment_case.py プロジェクト: santorofer/mdsplus
 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])"
     )
コード例 #3
0
 def CompressSegments(self):
     from MDSplus import Tree,DateToQuad,ZERO,Int32,Int32Array,Int64Array,Range
     with Tree(self.tree,self.shot+9,'NEW') as ptree:
         node = ptree.addNode('S')
         node.compress_on_put = False
         ptree.write()
     ptree.cleanDatafile()
     ptree.normal()
     te = DateToQuad("now")
     sampperseg = 50
     data = ZERO(Int32Array([sampperseg]),Int32(0))
     numsegs = 128
     for i in range(numsegs):
         t0=te+1;te=t0+sampperseg-1
         node.makeSegment(t0,te,Int64Array(range(t0,te+1)),data+Int32(i))
     node.compress_segments=True
     ptree.createPulse(self.shot+11)
     Tree.compressDatafile(self.tree,self.shot+11)
     ptree1 = Tree(self.tree,self.shot+11)
     node1  = ptree1.S
     self.assertEqual(True,(node.record==node1.record).all())
     self.assertEqual(True,ptree.getDatafileSize()>ptree1.getDatafileSize())
     for i in range(numsegs):
         srt,end = node.getSegmentLimits(i)
         dim = Range(srt,end)
         node.updateSegment(srt,end,dim,i)
         if i%16==0:
             self.assertEqual(dim.decompile(),node.getSegmentDim(i).decompile())
     ptree.compressDatafile()
     ptree.readonly()
     self.assertEqual(numsegs,node1.getNumSegments())
     self.assertEqual(True,ptree.getDatafileSize()<ptree1.getDatafileSize())
     for i in range(numsegs):
         self.assertEqual(node.getSegmentDim(i).data().tolist(),node1.getSegmentDim(i).data().tolist())
コード例 #4
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))
コード例 #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)))
コード例 #6
0
 def test():
     from MDSplus import Tree, DateToQuad, ZERO, Int32, Int32Array, Int64Array, Range
     with Tree('seg_tree', self.shot, 'NEW') as ptree:
         node = ptree.addNode('S')
         node.compress_on_put = False
         ptree.write()
     ptree.normal()
     ptree.compressDatafile()
     te = DateToQuad("now")
     sampperseg = 50
     data = ZERO(Int32Array([sampperseg]), Int32(0))
     for i in range(513):
         t0 = te + 1
         te = t0 + sampperseg - 1
         node.makeSegment(t0, te, Int64Array(range(t0, te + 1)),
                          data + Int32(i))
     node.compress_segments = True
     ptree.createPulse(self.shot + 1)
     Tree.compressDatafile(self.tree, self.shot + 1)
     ptree1 = Tree(self.tree, self.shot + 1)
     node1 = ptree1.S
     self.assertEqual(True, (node.record == node1.record).all())
     self.assertEqual(
         True,
         ptree.getDatafileSize() > ptree1.getDatafileSize())
     for i in range(node.getNumSegments()):
         str, end = node.getSegmentLimits(i)
         node.updateSegment(str, end, Range(str, end), i)
     ptree.close()
     ptree.compressDatafile()
     ptree.readonly()
     self.assertEqual(
         True,
         ptree.getDatafileSize() < ptree1.getDatafileSize())
     for i in range(node1.getNumSegments()):
         self.assertEqual(
             node.getSegmentDim(i).data().tolist(),
             node1.getSegmentDim(i).data().tolist())
コード例 #7
0
ファイル: segment_case.py プロジェクト: santorofer/mdsplus
    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))