def setUp(self):
     self.gf = open_file(self.full_path,readonly=False)
     self.root = self.gf.root()
     self.generator = random_generator_factory(self._typecode)
     self.input_data = next(self.generator())
     self.input_array_data = numpy.array([next(self.generator())])
     self.scalar_type = iotu.scalars[self._typecode]
Exemplo n.º 2
0
    def test_read_only(self):
        """
        Open a single file in read only mode.
        """
        f = open_file(self.full_path) 
        self.assertTrue(f.readonly)
        r = f.root()

        self.assertRaises(ObjectError,r.create_group,"entry","NXentry")
Exemplo n.º 3
0
    def test_read_write(self):
        """
        Open a single file in read-write mode.
        """

        f = open_file(self.full_path,readonly=False)
        self.assertFalse(f.readonly)
        r = f.root()

        r.create_group("entry","NXentry")
Exemplo n.º 4
0
def open_file(filename, readonly=False, libver=None):
    """ open the new file

    :param filename: file name
    :type filename: :obj:`str`
    :param readonly: readonly flag
    :type readonly: :obj:`bool`
    :param libver: library version: 'lastest' or 'earliest'
    :type libver: :obj:`str`
    :returns: file object
    :rtype: :class:`PNIFile`
    """
    return PNIFile(nx.open_file(filename, readonly), filename)
Exemplo n.º 5
0
    def reopen(self, readonly=False, swmr=False, _=None):
        """ reopen file

        :param readonly: readonly flag
        :type readonly: :obj:`bool`
        :param swmr: swmr flag
        :type swmr: :obj:`bool`
        :param libver:  library version, default: 'latest'
        :type libver: :obj:`str`
        """

        if swmr:
            raise Exception("SWMR not supported")
        self._h5object = nx.open_file(self.name, readonly)
        filewriter.FTFile.reopen(self)
    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 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"]
 def setUp(self):
     self.gf = open_file(self.full_path,readonly=False)
     self.root = self.gf.root()
     self.generator = random_generator_factory(self._typecode)
     self.scalar_type = iotu.scalars[self._typecode]
     self.field = self.root["data"]
Exemplo n.º 9
0
 def setUp(self):
     self.gf = open_file(self.full_path,readonly=False)
     self.root = self.gf.root()
Exemplo n.º 10
0
from __future__ import print_function

import pni.io.nx.h5 as nx
import numpy

f = nx.create_file("test_attributes.nxs",True)
r = f.root()
a = r.attributes.create("test_scalar","string")
a[...] = "hello world"
a = r.attributes.create("test_array","string",shape=(2,3))
data = numpy.array([["hello","world","this"],["is","a","test"]])
print(data)
print(data.dtype)
a[...] = data
a.close()
r.close()
f.close()

f = nx.open_file("test_attributes.nxs")
r = f.root()
a = r.attributes["test_scalar"]
print(a[...])

a = r.attributes["test_array"]
print(a[...])
print(a[...].flat[...])
Exemplo n.º 11
0
#!/usr/bin/env python
#file: nxfile_ex2.py

import pni.io.nx.h5 as nexus

fname = "nxfile_ex2.nxs"
try:
    print "try to open an existing file ..."
    nxfile = nexus.open_file(fname)
except:
    print "Error opening file - recreate ..."
    nxfile = nexus.create_file(fname,overwrite=True)


nxfile.close()

Exemplo n.º 12
0
from __future__ import print_function

import pni.io.nx.h5 as nx
import numpy

f = nx.create_file("test_fields.nxs",True)
r = f.root()
field = r.create_field("test_scalar","string")
field[...] = "hello world"
field = r.create_field("test_array","string",shape=(2,3))
data = numpy.array([["hello","world","this"],["is","a","test"]])
print(data)
print(data.dtype)
field[...] = data
field.close()
r.close()
f.close()

f = nx.open_file("test_fields.nxs",False)
r = f.root()
field = r["test_scalar"]
print(field[...])

field = r["test_array"]
print(field[...])
Exemplo n.º 13
0
from __future__ import print_function
import pni.io.nx.h5 as nx

f = nx.create_file("test.nxs",overwrite=True)
f.close()

f = nx.open_file("test.nxs")
print(f.readonly)
f.close()

f = nx.open_file("test.nxs",readonly=False)
print(f.readonly)
f.close()
Exemplo n.º 14
0
from __future__ import print_function
import numpy
import pni.io.nx.h5 as nexus

#open the file 
det_path = "/:NXentry/:NXinstrument/:NXdetector/data"
f = nexus.open_file("image_writer.nxs")
data = nexus.get_object(f.root(),det_path)


for index in range(data.shape[0]):
    if numpy.equal(data[index,...],
                   index*numpy.ones((data.shape[1],data.shape[2]),dtype=data.dtype)).all():
        print("fame {frame_index} is ok".format(frame_index=index))

Exemplo n.º 15
0
from __future__ import print_function

import pni.io.nx.h5 as nx
import numpy

f = nx.create_file("test.nxs", True)
r = f.root()
a = r.attributes.create("test_scalar", "string")
a[...] = "hello world"
a = r.attributes.create("test_array", "string", shape=(2, 3))
data = numpy.array([["hello", "world", "this"], ["is", "a", "test"]])
print(data)
print(data.dtype)
a[...] = data
a.close()
r.close()
f.close()

f = nx.open_file("test.nxs")
r = f.root()
a = r.attributes["test_scalar"]
print(a.value)

a = r.attributes["test_array"]
print(a.value)