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())
def data(self): shot = self.shot + 7 with Tree('pytree', shot, 'new') as pytree: pytree.default.addNode('pytreesub', 'subtree').include_in_pulse = True pytree.write() with Tree('pytreesub', shot, 'new') as pytreesub: node = pytreesub.addNode('.rog', 'structure') for i in range(10): node = node.addNode('.child', 'structure') node = node.addNode('rogowski', 'structure') node.tag = 'MAG_ROGOWSKI' node = node.addNode('signals', 'structure') node = node.addNode('rog_fg', 'signal') node.record = Signal(Range(1., 1000.), None, Range(1., 100., .1)) node = pytreesub.addNode('btor', 'signal') node.tag = 'BTOR' node.compress_on_put = True node.record = Signal(Range(2., 2000., 2.), None, Range(1., 1000.)) ip = pytreesub.addNode('ip', 'signal') ip.tag = "IP" rec = pytreesub.tdiCompile( "Build_Signal(Build_With_Units(\\MAG_ROGOWSKI.SIGNALS:ROG_FG + 2100. * \\BTOR, 'ampere'), *, DIM_OF(\\BTOR))" ) ip.record = rec pytreesub.versions_in_pulse = True pytreesub.write() pytree.readonly() ip = pytree.getNode('\\IP') pytree.setDefault(ip) self.assertEqual( str(ip.record), 'Build_Signal(Build_With_Units(\\MAG_ROGOWSKI.SIGNALS:ROG_FG + 2100. * \\BTOR, "ampere"), *, DIM_OF(\\BTOR))' ) self.assertEqual(str(ip.record), str(ip.getData())) self.assertEqual(ip.segmented, ip.isSegmented()) self.assertEqual(ip.versions, ip.containsVersions()) self.assertEqual(ip.versions, False) self.assertEqual(ip.getNumSegments(), 0) self.assertEqual(ip.getSegment(0), None) pytree.normal() ip.record = ADD(1, COMPILE("\\BTOR")) self.assertEqual(ip.versions, True) self.assertEqual(ip.record.decompile(), '1 + COMPILE("\\\\BTOR")') self.assertEqual(ip.record.data().tolist(), (pytree.getNode("\\BTOR").data() + 1).tolist())
def thick(self): def testnci(thick, local, con, nci): l = local.S.__getattribute__(nci) t = thick.S.__getattribute__(nci) if nci.endswith("_nids"): l, t = str(l), str(t) try: c = str(con.get("getnci(getnci(S,$),'nid_number')", nci)) except TreeNNF: c = '[]' else: c = con.get("getnci(S,$)", nci) try: self.assertEqual(t, c) self.assertEqual(t, l) except: print(nci, t, l, c) raise server, server_port = self._setup_mdsip('ACTION_SERVER', 'ACTION_PORT', 7000 + self.index, True) svr, svr_log = self._start_mdsip(server, server_port, 'thick') try: con = Connection(server) self.assertEqual( con.get("zero([1,1,1,1,1,1,1,1],1)").tolist(), [[[[[[[[0]]]]]]]]) with Tree(self.tree, -1, "new") as local: local.addNode(self.treesub, "SUBTREE") s = local.addNode("S", "SIGNAL") s.addTag("tagS") s.record = ADD(Float32(1), Float32(2)) t = local.addNode("T", "TEXT") t.addNode("TT", "TEXT").addTag("tagTT") t.record = t.TT t.TT = "recTT" local.write() with Tree(self.treesub, -1, "new") as sub: sub.addNode("OK") sub.write() local.normal() Tree.setCurrent(self.tree, 7) setenv("%s_path" % self.tree, "%s::" % server) print(con.get("getenv($//'_path')", self.tree)) con.get("TreeShr->TreeOpen(ref($),val($),val(1))", self.tree, -1) thick = Tree(self.tree, -1) thick.createPulse(1) thick1 = Tree(self.tree, 1) self.assertEqual( getattr(local, self.treesub.upper()).OK.nid, getattr(thick1, self.treesub.upper()).OK.nid) local_filename = local.getFileName() thick_filename = thick.getFileName() self.assertTrue("::" in thick_filename, thick_filename) self.assertTrue(local_filename, thick_filename.split("::", 1)[1]) """ TreeTurnOff / TreeTurnOn """ thick.S.on = False self.assertEqual(local.S.on, False) thick.S.on = True self.assertEqual(local.S.on, True) """ TreeSetCurrentShotId / TreeGetCurrentShotId """ Tree.setCurrent(self.tree, 1) self.assertEqual(Tree.getCurrent(self.tree), 1) """ TreeGetRecord / TreeSetRecord """ self.assertEqual(str(local.S.record), "1. + 2.") self.assertEqual(str(thick.S.record), "1. + 2.") thick.S.record = ADD(Float32(2), Float32(4)) self.assertEqual(str(local.S.record), "2. + 4.") self.assertEqual(str(thick.S.record), "2. + 4.") self.assertEqual(str(local.T.record), str(thick.T.record)) """ GetDefaultNid / SetDefaultNid """ self.assertEqual(thick.getDefault(), thick.top) thick.setDefault(thick.S) self.assertEqual(thick.getDefault(), thick.top.S) thick.setDefault(thick.top) """ FindNodeWildRemote """ self.assertEqual(str(thick.getNodeWild("T*")), str(local.getNodeWild("T*"))) """ FindTagWildRemote """ self.assertEqual(thick.findTags("*"), local.findTags("*")) """ nci """ thick.S.write_once = True self.assertEqual(thick.S.write_once, True) for nci in ( 'on', 'depth', 'usage_str', 'dtype', 'length', 'rlength', 'fullpath', 'minpath', 'member_nids', 'children_nids', 'rfa', 'write_once', ): testnci(thick, local, con, nci) """ new stuff """ self.assertEqual(local.getFileName(), con.get("treefilename($,-1)", self.tree)) finally: if svr_log: svr_log.close() self._stop_mdsip((svr, server))