Exemplo n.º 1
0
    def test_unresolvable_link(self):
        f = nexus.create_file("unresolvable_link.nxs",overwrite=True)
        r = f.root()
        nexus.xml_to_nexus(dead_link_file,r,lambda x: True)
        r.close()
        f.close()

        result = self._check_output(args=["unresolvable_link.nxs"])
        print(result)
    def test_mdim_attribute(self):
        xml_to_nexus(mdim_attribute,self.field,lambda obj: True)
        a = get_object(self.root,"/data@vector")
        self.assertTrue(check_attribute(a,"vector","float32", (3,)))
        d = a[...]

        self.assertAlmostEqual(d[0],0.0)
        self.assertAlmostEqual(d[1],0.0)
        self.assertAlmostEqual(d[2],1.0)
Exemplo n.º 3
0
    def test_mdim_field_default(self):
        xml_to_nexus(mdim_field_default,self.root,lambda obj: True)
        f = get_object(self.root,"/mdim_field_default")
        self.assertTrue(check_field(f,"mdim_field_default","uint32",
                                    (2,3)))

        d = f[...]
        for (ref_value,data) in zip(range(1,7),d.flat):
            self.assertEqual(ref_value,data)
Exemplo n.º 4
0
    def test_multi_group(self):
        xml_to_nexus(multi_group,self.root)

        self.assertEqual(len(self.root),3)
        self.assertTrue(self._check_name_type(self.root["scan_1"],"scan_1",
                                                                  "NXentry"))
        self.assertTrue(self._check_name_type(self.root["scan_2"],"scan_2",
                                                                  "NXentry"))
        self.assertTrue(self._check_name_type(self.root["scan_3"],"scan_3",
                                                                  "NXentry"))
Exemplo n.º 5
0
    def test_nested_group(self):
        xml_to_nexus(nested_group,self.root)

        self.assertTrue(self._check_name_type(get_object(self.root,":NXentry"),
                                              "scan","NXentry"))
        self.assertTrue(self._check_name_type(
             get_object(self.root,":NXentry/:NXinstrument"),
             "instrument","NXinstrument"))
        self.assertTrue(self._check_name_type(
             get_object(self.root,":NXentry/:NXsample"),"sample","NXsample"))
        self.assertTrue(self._check_name_type(
             get_object(self.root,":NXentry/:NXmonitor"),
             "control","NXmonitor"))

        self.assertTrue(self._check_name_type(
             get_object(self.root,":NXentry/:NXinstrument/:NXdetector"),
             "detector","NXdetector"))
        self.assertTrue(self._check_name_type(
             get_object(self.root,":NXentry/:NXinstrument/:NXsource"),
             "source","NXsource"))
    def setUp(self):
        f = nexus.create_file(self.det_full_path,True)
        r = f.root()
        nexus.xml_to_nexus(detector_file_struct,r)
        r.close()
        f.close()

        f = nexus.create_file(self.master1_full_path,True)
        r = f.root()
        nexus.xml_to_nexus(master_file_struct_1,r)
        r.close()
        f.close()
        
        f = nexus.create_file(self.master2_full_path,True)
        r = f.root()
        nexus.xml_to_nexus(master_file_struct_2,r)
        r.close()
        f.close()
Exemplo n.º 7
0
    def test_scalar_field(self):
        xml_to_nexus(scalar_field,self.root)

        f = get_object(self.root,"/scalar_field")
        self.assertTrue(check_field(f,"scalar_field","float64",(1,)))
    def setUp(self):
        self.file = nexus.create_file(self.full_path,True)
        self.root = self.file.root()
        nexus.xml_to_nexus(file_struct,self.root)

        self.nxdata = nexus.get_object(self.root,"/:NXentry/:NXdata")
Exemplo n.º 9
0
def init_file(fname):
    f = nexus.create_file(fname,overwrite=True)
    r = f.root()
    nexus.xml_to_nexus(file_struct,r)

    return f
Exemplo n.º 10
0
 def test_mdim_field_custom(self):
     xml_to_nexus(mdim_field_custom,self.root)
     f = get_object(self.root,"/mdim_field_custom")
     self.assertTrue(check_field(f,"mdim_field_custom","uint32",
                                 (1,1024,512)))
Exemplo n.º 11
0
 def setUpClass(self):
     f=create_file(self.full_path,overwrite=True)
     f.close()
     f = create_file(self.det_path,overwrite=True)
     r = f.root()
     xml_to_nexus(detector_file,r)
Exemplo n.º 12
0
    def test_external_link(self):
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        xml_to_nexus(master_entry,self.root)

        f = get_object(self.root,"/entry_2/:NXdata/data")
        self.assertTrue(check_field(f,"data","uint32",(1,)))
Exemplo n.º 13
0
 def test_mdim_attribute(self):
     xml_to_nexus(mdim_attribute,self.field)
     a = get_object(self.root,"/data@vector")
     self.assertTrue(check_attribute(a,"vector","float32", (3,)))
Exemplo n.º 14
0
import pni.io.nx.h5 as nx 

file_struct =  \
"""
<group name="entry" type="NXentry">
    <group name="instrument" type="NXinstrument"/>
    <group name="data" type="NXdata"/>
    <group name="control" type="NXmonitor"/>
</group>
"""

f = nx.create_file("xml1.nxs",True)
root = f.root()
nx.xml_to_nexus(file_struct,root)
f.close()

Exemplo n.º 15
0
    def test_internal_link(self):
        xml_to_nexus(internal_link,self.root)

        f = get_object(self.root,"/entry_1/:NXdata/data")
        self.assertTrue(check_field(f,"data","uint32",(1,)))
Exemplo n.º 16
0
    def test_scalar_attribute(self):
        xml_to_nexus(scalar_attribute,self.field)

        a = get_object(self.root,"/data@transformation_type")
        self.assertTrue(check_attribute(a,"transformation_type","string",(1,)))
Exemplo n.º 17
0
    def test_scalar_field(self):
        xml_to_nexus(scalar_field,self.root,lambda obj: True)

        f = get_object(self.root,"/scalar_field")
        self.assertTrue(check_field(f,"scalar_field","float64",(1,)))
        self.assertAlmostEqual(f[...],100.)
Exemplo n.º 18
0
        <field name="material" type="string">Si + Ge</field>
    </group>
</group>
"""

detector_struct = \
"""
<group name="mythen" type="NXdetector">
    <field name="layout" type="string">linear</field>
    <field name="x_pixel_size" type="float64" units="um">50</field>
    <field name="y_pixel_size" type="float64" units="mm">5</field>
</group>
"""


def write_if(obj):
    return (isinstance(obj,nx.nxfield) or 
           isinstance(obj,nx.nxattribute)) and obj.size ==1

f = nx.create_file("xml2.nxs",True)
root = f.root()

#create the basic object
nx.xml_to_nexus(file_struct,root,write_if)

instrument = nx.get_object(root,"/:NXentry/:NXinstrument")
nx.xml_to_nexus(detector_struct,instrument,write_if)

f.close()

Exemplo n.º 19
0
        <group name="detector" type="NXdetector">
            <field name="data" type="uint32" units="cps">
                <dimensions rank="1">
                    <dim index="1" value="10"/>
                </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")
Exemplo n.º 20
0
            1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.
            </field>
        </group>
    </group>

    <group name="data" type="NXdata">
    </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"])
Exemplo n.º 21
0
    def test_single_group(self):
        xml_to_nexus(single_group,self.root)

        g = get_object(self.root,"/:NXentry")
        self.assertTrue(self._check_name_type(g,"entry","NXentry"))
Exemplo n.º 22
0
            <field name="layout" type="string">linear</field>
            <field name="x_pixel_size" type="float64" units="um">50</field>
            <field name="y_pixel_size" type="float64" units="mm">5</field>
        </group>
    </group>
    <group name="data" type="NXdata"/>
    <group name="control" type="NXmonitor"/>
    <group name="sample" type="NXsample">
        <field name="name" type="string">VK007</field>
        <field name="material" type="string">Si + Ge</field>
    </group>
</group>
"""

f = nx.create_file("rec_group_iter.nxs",True)
root = f.root()

def write_if(obj):
    return (isinstance(obj,nx.nxfield) or 
           isinstance(obj,nx.nxattribute)) and obj.size ==1

nx.xml_to_nexus(file_struct,root,write_if)

for x in root.recursive:
    print nx.get_path(x)
    if isinstance(x,nx.nxfield):
        print "data: ",x[...]


f.close()
    def test_scalar_attribute(self):
        xml_to_nexus(scalar_attribute,self.field,lambda obj: True)

        a = get_object(self.root,"/data@transformation_type")
        self.assertTrue(check_attribute(a,"transformation_type","string",(1,)))
        self.assertEqual(a[...],"rotation")