def test_unresolvable_link(self): data = nexus.get_object(self.root,"/:NXentry/:NXdata") nexus.link("/entry/instrument/monochromator/energy",data,"data") l = nexus.get_object(self.root,"/:NXentry/:NXdata/data") self.assertTrue(isinstance(l,nexus.nxlink)) self.assertEqual(l.status,nexus.nxlink_status.INVALID) self.assertEqual(l.type,nexus.nxlink_type.SOFT) self.assertEqual(l.path,"/entry:NXentry/data:NXdata/data")
def test_link_from_path(self): """ Test link creation from a path. The target is only specified by its path. """ nexus.link("/entry/instrument/detector/data",self.nxdata,"plot_data") d = self.nxdata["plot_data"] self.assertEqual(d.name,"plot_data") self.assertEqual(d.size,0) self.assertEqual(d.dtype,"uint16") self.assertEqual(d.path,"/entry:NXentry/data:NXdata/plot_data")
def test_link_from_object(self): """ Test link creation from an object. The target is specified by an object. """ det_data = nexus.get_object(self.root,"/:NXentry/:NXinstrument/:NXdetector/data") nexus.link(det_data,self.nxdata,"plot_data") d = self.nxdata["plot_data"] self.assertEqual(d.name,"plot_data") self.assertEqual(d.size,0) self.assertEqual(d.dtype,"uint16") self.assertEqual(d.path,"/entry:NXentry/data:NXdata/plot_data")
def test_link_field_from_path(self): os.chdir(os.path.dirname(os.path.abspath(__file__))) f = nexus.open_file(self.master2_full_path,readonly=False) r = f.root() detector_group = nexus.get_object(r,"/:NXentry/:NXinstrument/:NXdetector") nexus.link("external_link_test_detector.nxs://entry/instrument/mca/data", detector_group,"mca_data") d = detector_group["mca_data"] self.assertEqual(d.name,"data") self.assertEqual(d.path,"/entry:NXentry/instrument:NXinstrument/mca:NXdetector/data") data = nexus.get_object(r,"/:NXentry/:NXdata") d = data["plot_data"]
def link(target, parent, name): """ create link :param target: file name :type target: :obj:`str` :param parent: parent object :type parent: :class:`FTObject` :param name: link name :type name: :obj:`str` :returns: link object :rtype: :class:`PNILink` """ nx.link(target, parent.h5object, name) lks = nx.get_links(parent.h5object) lk = [e for e in lks if e.name == name][0] el = PNILink(lk, parent) return el
def test_link_group_from_path(self): """ Test link creation from a path. The target is only specified by its path. """ os.chdir(os.path.dirname(os.path.abspath(__file__))) f = nexus.open_file(self.master1_full_path,readonly=False) r = f.root() instrument_group = nexus.get_object(r,"/:NXentry/:NXinstrument") nexus.link("external_link_test_detector.nxs://entry/instrument/mca", instrument_group,"detector") d = instrument_group["detector"] self.assertEqual(d.name,"mca") self.assertEqual(d.path,"/entry:NXentry/instrument:NXinstrument/mca:NXdetector") data = nexus.get_object(r,"/:NXentry/:NXdata") d = data["plot_data"]
</group> </group> """ f = nexus.create_file("internal_link.nxs",True) r = f.root() nexus.xml_to_nexus(file_struct,r,utils.write_everything) nxdata = nexus.get_object(r,"/:NXentry/:NXdata") #link an object data = nexus.get_object(r,"/:NXentry/:NXinstrument/:NXdetector/data") nexus.link(data,nxdata,"data") #link to a path nexus.link("/entry/sample/transformations/om",nxdata,"om") nexus.link("/entry/detector/transformations/tt",nxdata,"tt") #finalize the nxdata structure for easy plotting nxdata.attributes.create("signal","string")[...]="data" nxdata.attributes.create("axes","string",shape=(2,))[...] = \ numpy.array(["om","tt"]) nxdata.attributes.create("tt_indices","uint32")[...] = 0 nxdata.attributes.create("om_indices","uint32")[...] = 0
</dimensions> 12 9 199 150 123 99 65 87 94 55 </field> </group> </group> </group> """ detector_file = nexus.create_file("detector.nxs",True) root =detector_file.root() nexus.xml_to_nexus(detector_file_struct,root,utils.write_everything) root.close() detector_file.close() master_file = nexus.create_file("master_file.nxs",True) root = master_file.root() nexus.xml_to_nexus(master_file_struct,root) try: dg = nexus.get_object(root,"/:NXentry/:NXinstrument/:NXdetector") except KeyError: print("Could not find detector group in master file!") sys.exit(1) nexus.link("detector.nxs://entry/instrument/detector/data",dg,"data") data = nexus.get_object(root,"/:NXentry/:NXinstrument/:NXdetector/data") print(data[...])