Exemplo n.º 1
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))
Exemplo n.º 2
0
 def importDevices(name):
     bname = version.tobytes(name)
     try:
         module = __import__(name)
         ans = [[version.tobytes(k),bname] for k,v in module.__dict__.items() if isinstance(v,int.__class__) and issubclass(v,Device)]
     except (ImportError, ImportWarning): ans = []
     tdidev = tdi("if_error(%s(),*)"%name)
     if tdidev is None: return ans
     tdidev = [[k.rstrip(), v.rstrip()] for k,v in tdidev.value.reshape((int(tdidev.value.size/2),2)).tolist()]
     return tdidev+ans
Exemplo n.º 3
0
 def XyzDevices(self, package, expected=None):
     if expected is None:
         expected = [
             s for s in (str(s).strip() for s, p in tdi('%s()' % package))
         ]
     expected.sort()
     passed = []
     with Tree('devtree', -1, 'new') as t:
         for model in expected:
             node, name = self.getNodeName(t, model)
             try:
                 node.addDevice(name, model)
                 passed.append(model)
                 if Device.debug: print('PASSED %s' % model)
             except:
                 if Device.debug: print('FAILED %s' % model)
     self.assertEqual(passed, expected)
     self.DevicesTests(package)
Exemplo n.º 4
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))