def nciInfo(self): with Tree('pytree',self.shot+7,'new') as pytree: pytree.addNode('pytreesub','subtree').include_in_pulse=True Device.PyDevice('TestDevice').Add(pytree,'TESTDEVICE') Device.PyDevice('CYGNET4K').Add(pytree,'CYGNET4K').on=False pytree.write() with Tree('pytreesub',self.shot+7,'new') as pytreesub: ip=pytreesub.addNode('ip','signal') ip.record=Signal(Int32(range(10)),None,Range(1.,10.)) ip.tag='MAG_PLASMA_CURRENT' ip.tag='MAGNETICS_PLASMA_CURRENT' ip.tag='MAG_IP' ip.tag='MAGNETICS_IP' ip.tag='IP' ip.setExtendedAttribute('ATT1',100) ip.setExtendedAttribute('ATT2',Range(1,200)) ip.setExtendedAttribute('ATT3','this is ip') ip.setExtendedAttribute('ATT3','this is plasma current') self.assertEqual(str(ip.getExtendedAttribute('ATT1')),'100') self.assertEqual(str(ip.getExtendedAttribute('ATT2')),'1 : 200 : *') self.assertEqual(str(ip.getExtendedAttribute('ATT3')),'this is plasma current') exattr = ip.getExtendedAttributes() self.assertEqual(exattr['ATT1'],100) self.assertEqual(str(exattr['ATT2']),'1 : 200 : *') self.assertEqual(exattr['ATT3'],'this is plasma current') for i in range(3): node=pytreesub.addNode('child%02d' % (i,),'structure') node.addDevice('dt200_%02d' % (i,),'dt200').on=False pytreesub.write() pytree.readonly() self.assertEqual(pytree.TESTDEVICE.__class__,Device.PyDevice('TESTDEVICE')) self.assertEqual(pytree.CYGNET4K.__class__,Device.PyDevice('CYGNET4K')) pytree.CYGNET4K.persistent = {} pytree.CYGNET4K.persistent['a'] = 1 self.assertEqual(pytree.getNode('CYGNET4K').frames.persistent['a'], 1) ip=pytree.getNode('\\ip') self.assertEqual(ip.getUsage(),'SIGNAL') self.assertEqual(ip.usage,ip.getUsage()) try: # do not continue and print when no match self.assertEqual(ip.getClass(),'CLASS_R') except AssertionError: print( "ip.nid=%d" % (ip.nid,)) print( "Error with ip in %s" % (str(ip.tree),)) raise self.assertEqual(ip.class_str,'CLASS_R') self.assertEqual(ip.compressible,False) self.assertEqual(ip.compressible,ip.isCompressible()) self.assertEqual(ip.compress_on_put,True) self.assertEqual(ip.compress_on_put,ip.isCompressOnPut()) self.assertEqual(ip.data_in_nci,False) self.assertEqual(ip.on,True) self.assertEqual(ip.on,ip.isOn()) self.assertEqual(ip.do_not_compress,False) self.assertEqual(ip.do_not_compress,ip.isDoNotCompress()) self.assertEqual(ip.dtype_str,'DTYPE_SIGNAL') self.assertEqual(ip.dtype_str,ip.getDtype()) self.assertEqual(ip.essential,False) self.assertEqual(ip.essential,ip.isEssential()) mhdtree=pytree.getNode('\\PYTREESUB::TOP') self.assertEqual(mhdtree.include_in_pulse,True) self.assertEqual(mhdtree.include_in_pulse,mhdtree.isIncludeInPulse()) self.assertEqual(ip.length,int(Data.execute('getnci($,"LENGTH")',ip))) self.assertEqual(ip.length,ip.getLength()) self.assertEqual(ip.no_write_shot,False) self.assertEqual(ip.no_write_shot,ip.isNoWriteShot()) self.assertEqual(ip.no_write_model,False) self.assertEqual(ip.no_write_model,ip.isNoWriteModel()) self.assertEqual(ip.write_once,False) self.assertEqual(ip.write_once,ip.isWriteOnce()) pydev = pytree.TESTDEVICE part = pydev.conglomerate_nids[1] self.assertEqual(part.PART_NAME(),':ACTIONSERVER') self.assertEqual(part.original_part_name,':ACTIONSERVER') self.assertEqual(str(Data.execute('GETNCI($,"ORIGINAL_PART_NAME")',part)),':ACTIONSERVER') self.assertEqual(pydev.__class__,Device.PyDevice('TestDevice')) devs = pytree.getNodeWild('\\PYTREESUB::TOP.***','DEVICE') part = devs[0].conglomerate_nids[3] self.assertEqual(part.original_part_name,':COMMENT') self.assertEqual(part.original_part_name,str(Data.execute('GETNCI($,"ORIGINAL_PART_NAME")',part))) self.assertEqual(ip.owner_id,ip.getOwnerId()) self.assertEqual(ip.rlength,136) self.assertEqual(ip.rlength,ip.getCompressedLength()) self.assertEqual(ip.setup_information,False) self.assertEqual(ip.setup_information,ip.isSetup()) self.assertEqual(ip.status,0) self.assertEqual(ip.status,ip.getStatus()) self.assertEqual((ip.tags==Array(['IP','MAGNETICS_IP','MAG_IP','MAGNETICS_PLASMA_CURRENT','MAG_PLASMA_CURRENT'])).all(),True) self.assertEqual((ip.tags==ip.getTags()).all(),True) self.assertEqual(ip.time_inserted,ip.getTimeInserted())
def nodeLinkage(self): with Tree('pytree',self.shot+6,'new') as pytree: pytree.default.addNode('pytreesub','subtree').include_in_pulse=True for i in range(10): node=pytree.addNode('val%02d' % (i,),'numeric') node.record=i node=pytree.top.addNode('sig%02d' % (i,),'signal') node.record=Signal(i,None,i) node=pytree.top.addNode('child%02d' % (i,),'structure') node.addNode('text','text') node.addNode('child','structure') pytree.write() with Tree('pytreesub',self.shot+6,'new') as pytreesub: ip=pytreesub.addNode('ip','signal') ip.tag='IP' for i in range(3): node=pytreesub.top.addNode('child%02d' % (i,),'structure') node.addDevice('dt200_%02d' % (i,),'dt200').on=False pytreesub.write() from numpy import array,int32 pytree.readonly() top=TreeNode(0,pytree) members=pytree.getNodeWild(':*') self.assertEqual((members==top.member_nids).all(),True) self.assertEqual((members==top.getMembers()).all(),True) self.assertEqual(top.member.nid_number,members[0].nid_number) member=top.member for idx in range(1,len(members)): self.assertEqual(member.brother.nid_number,members[idx].nid_number) member=member.brother children=pytree.getNodeWild('.*') self.assertEqual((children==top.children_nids).all(),True) self.assertEqual((children==top.getChildren()).all(),True) self.assertEqual(top.child.nid_number,children[0].nid_number) child=top.child for idx in range(1,len(children)): self.assertEqual(child.brother.nid_number,children[idx].nid_number) child=child.brother self.assertEqual(top.child.nid_number,pytree.getNode(str(top.child)).nid_number) self.assertEqual(top.child.child.parent.nid_number,top.child.nid_number) x=array(int32(0)).repeat(len(members)+len(children)) x[0:len(children)]=children.nid_number.data() x[len(children):]=members.nid_number.data() self.assertEqual((Array(x)==top.descendants.nid_number).all(),True) self.assertEqual((top.descendants.nid_number==top.getDescendants().nid_number).all(),True) self.assertEqual(top.child.child.depth,3) self.assertEqual(top.getNumDescendants(),len(x)) self.assertEqual(top.getNumMembers(),len(members)) self.assertEqual(top.getNumChildren(),len(children)) self.assertEqual(top.number_of_members,len(members)) self.assertEqual(top.number_of_children,len(children)) self.assertEqual(top.number_of_descendants,len(x)) devs=pytree.getNodeWild('\\PYTREESUB::TOP.***','DEVICE') dev=devs[0].conglomerate_nids self.assertEqual((dev.nid_number==devs[0].getConglomerateNodes().nid_number).all(),True) self.assertEqual((dev.conglomerate_elt==Array(array(range(len(dev)))+1)).all(),True) for idx in range(len(dev)): self.assertEqual(dev[idx].conglomerate_elt,idx+1) self.assertEqual(dev[idx].getConglomerateElt(),idx+1) self.assertEqual(top.child.is_child,True) self.assertEqual(top.child.is_member,False) self.assertEqual(top.member.is_child,False) self.assertEqual(top.member.is_member,True) self.assertEqual(top.child.is_child,top.child.isChild()) self.assertEqual(top.child.is_member,top.child.isMember()) ip=pytree.getNode('\\ip') pytree.setDefault(ip) self.assertEqual(ip.fullpath,"\\PYTREE::TOP.PYTREESUB:IP") self.assertEqual(ip.fullpath,ip.getFullPath()) self.assertEqual(ip.minpath,"\\IP") self.assertEqual(ip.minpath,ip.getMinPath()) self.assertEqual(ip.node_name,'IP') self.assertEqual(ip.node_name,ip.getNodeName()) self.assertEqual(ip.path,"\\PYTREESUB::IP") self.assertEqual(ip.path,ip.getPath())