#!/usr/bin/env python ''' Writes a simple NeXus HDF5 file using h5py with links according to the example from Figure 2.1 in the Design chapter ''' import my_lib INPUT_FILE = 'input.dat' HDF5_FILE = 'writer_2_1.hdf5' #--------------------------- tthData, countsData = my_lib.get2ColumnData(INPUT_FILE) f = my_lib.makeFile(HDF5_FILE) # create the HDF5 NeXus file nxentry = my_lib.makeGroup(f, 'entry', 'NXentry') nxinstrument = my_lib.makeGroup(nxentry, 'instrument', 'NXinstrument') nxdetector = my_lib.makeGroup(nxinstrument, 'detector', 'NXdetector') tth = my_lib.makeDataset(nxdetector, "two_theta", tthData, units='degrees') counts = my_lib.makeDataset(nxdetector, "counts", countsData, units='counts', signal=1, axes='two_theta') nxdata = my_lib.makeGroup(nxentry, 'data', 'NXdata') my_lib.makeLink(nxdetector, tth, nxdata.name + '/two_theta')
#!/usr/bin/env python ''' Writes the simplest NeXus HDF5 file using a simple helper library with h5py and numpy calls according to the example from Figure 1.3 in the Introduction chapter ''' import my_lib INPUT_FILE = 'input.dat' HDF5_FILE = 'writer_1_3.hdf5' #--------------------------- tthData, countsData = my_lib.get2ColumnData(INPUT_FILE) f = my_lib.makeFile(HDF5_FILE) # since this is a simple example, no attributes are used at this point nxentry = my_lib.makeGroup(f, 'Scan', 'NXentry') nxdata = my_lib.makeGroup(nxentry, 'data', 'NXdata') my_lib.makeDataset(nxdata, "two_theta", tthData, units='degrees') my_lib.makeDataset(nxdata, "counts", countsData, units='counts', signal=1, axes='two_theta') f.close() # be CERTAIN to close the file
''' import my_lib FILE_INPUT = 'input.dat' FILE_HDF5_MASTER = 'external_master.hdf5' FILE_HDF5_ANGLES = 'external_angles.hdf5' FILE_HDF5_COUNTS = 'external_counts.hdf5' #--------------------------- # get some data tthData, countsData = my_lib.get2ColumnData(FILE_INPUT) # put the angle data in an external (non-NeXus) HDF5 data file f = my_lib.makeFile(FILE_HDF5_ANGLES) # create an HDF5 file (non-NeXus) tth = my_lib.makeDataset(f, "angles", tthData, units='degrees') f.close() # be CERTAIN to close the file # put the detector counts in an external NeXus HDF5 data file f = my_lib.makeFile(FILE_HDF5_COUNTS) nxentry = my_lib.makeGroup(f, 'entry', 'NXentry') nxinstrument = my_lib.makeGroup(nxentry, 'instrument', 'NXinstrument') nxdetector = my_lib.makeGroup(nxinstrument, 'detector', 'NXdetector') counts = my_lib.makeDataset(nxdetector, "counts", countsData, units='counts', signal=1, axes='two_theta') # make a link since "two_theta" has not been stored here
import my_lib # uses h5py print "Write a NeXus HDF5 file" fileName = "prj_test.nexus.hdf5" timestamp = "2010-10-18T17:17:04-0500" # load data from two column format data = numpy.loadtxt('input.dat').T mr_arr = data[0] i00_arr = numpy.asarray(data[1], 'int32') # create the HDF5 NeXus file f = my_lib.makeFile(fileName, file_name=fileName, file_time=timestamp, instrument="APS USAXS at 32ID-B", creator="BasicWriter.py", NeXus_version="4.3.0", HDF5_Version=h5py.version.hdf5_version, h5py_version=h5py.version.version) nxentry = my_lib.makeGroup(f, "entry", "NXentry") my_lib.makeDataset(nxentry, 'title', data='1-D scan of I00 v. mr') nxdata = my_lib.makeGroup(nxentry, "mr_scan", "NXdata") my_lib.makeDataset(nxdata, "mr", mr_arr, units='degrees', long_name='USAXS mr (degrees)')
#!/usr/bin/env python """ Writes a simple NeXus HDF5 file using h5py with links according to the example from Figure 2.1 in the Design chapter """ import my_lib INPUT_FILE = "input.dat" HDF5_FILE = "writer_2_1.hdf5" # --------------------------- tthData, countsData = my_lib.get2ColumnData(INPUT_FILE) f = my_lib.makeFile(HDF5_FILE) # create the HDF5 NeXus file nxentry = my_lib.makeGroup(f, "entry", "NXentry") nxinstrument = my_lib.makeGroup(nxentry, "instrument", "NXinstrument") nxdetector = my_lib.makeGroup(nxinstrument, "detector", "NXdetector") tth = my_lib.makeDataset(nxdetector, "two_theta", tthData, units="degrees") counts = my_lib.makeDataset(nxdetector, "counts", countsData, units="counts", signal=1, axes="two_theta") nxdata = my_lib.makeGroup(nxentry, "data", "NXdata") my_lib.makeLink(nxdetector, tth, nxdata.name + "/two_theta") my_lib.makeLink(nxdetector, counts, nxdata.name + "/counts") f.close() # be CERTAIN to close the file
import my_lib # uses h5py print "Write a NeXus HDF5 file" fileName = "prj_test.nexus.hdf5" timestamp = "2010-10-18T17:17:04-0500" # load data from two column format data = numpy.loadtxt('input.dat').T mr_arr = data[0] i00_arr = numpy.asarray(data[1],'int32') # create the HDF5 NeXus file f = my_lib.makeFile(fileName, file_name=fileName, file_time=timestamp, instrument="APS USAXS at 32ID-B", creator="BasicWriter.py", NeXus_version="4.3.0", HDF5_Version=h5py.version.hdf5_version, h5py_version=h5py.version.version) nxentry = my_lib.makeGroup(f, "entry", "NXentry") my_lib.makeDataset(nxentry, 'title', data='1-D scan of I00 v. mr') nxdata = my_lib.makeGroup(nxentry, "mr_scan", "NXdata") my_lib.makeDataset(nxdata, "mr", mr_arr, units='degrees', long_name='USAXS mr (degrees)') my_lib.makeDataset(nxdata, "I00", i00_arr, units='counts', signal=1, # Y axis of default plot axes='mr', # name "mr" as X axis
Writes the simplest NeXus HDF5 file using a simple helper library with h5py and numpy calls according to the example from Figure 1.3 in the Introduction chapter ''' import my_lib INPUT_FILE = 'input.dat' HDF5_FILE = 'writer_1_3.hdf5' #--------------------------- tthData, countsData = my_lib.get2ColumnData(INPUT_FILE) f = my_lib.makeFile(HDF5_FILE) # since this is a simple example, no attributes are used at this point nxentry = my_lib.makeGroup(f, 'Scan', 'NXentry') nxdata = my_lib.makeGroup(nxentry, 'data', 'NXdata') my_lib.makeDataset(nxdata, "two_theta", tthData, units='degrees') my_lib.makeDataset(nxdata, "counts", countsData, units='counts', signal=1, axes='two_theta') f.close() # be CERTAIN to close the file