-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bb99a4
commit 1b882ca
Showing
46 changed files
with
720 additions
and
688 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
73 changes: 73 additions & 0 deletions
73
manual/source/examples/h5py/external_example_write/external_example_write.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Writes a NeXus HDF5 file using h5py with links to data in other HDF5 files. | ||
This example is based on ``writer_2_1``. | ||
""" | ||
|
||
import os | ||
import h5py | ||
import numpy | ||
|
||
FILE_HDF5_MASTER = "external_master.hdf5" | ||
FILE_HDF5_ANGLES = "external_angles.hdf5" | ||
FILE_HDF5_COUNTS = "external_counts.hdf5" | ||
|
||
# --------------------------- | ||
|
||
# get some data | ||
filename = os.path.join(os.path.dirname(__file__), "..", "simple_example.dat") | ||
buffer = numpy.loadtxt(filename).T | ||
tthData = buffer[0] # float[] | ||
countsData = numpy.asarray(buffer[1], "int32") # int[] | ||
|
||
# put the angle data in an external (non-NeXus) HDF5 data file | ||
f = h5py.File(FILE_HDF5_ANGLES, "w") | ||
ds = f.create_dataset("angles", data=tthData) | ||
ds.attrs["units"] = "degrees" | ||
f.close() # be CERTAIN to close the file | ||
|
||
|
||
# put the detector counts in an external HDF5 data file | ||
# with *incomplete* NeXus structure (no NXdata group) | ||
f = h5py.File(FILE_HDF5_COUNTS, "w") | ||
nxentry = f.create_group("entry") | ||
nxentry.attrs["NX_class"] = "NXentry" | ||
nxinstrument = nxentry.create_group("instrument") | ||
nxinstrument.attrs["NX_class"] = "NXinstrument" | ||
nxdetector = nxinstrument.create_group("detector") | ||
nxdetector.attrs["NX_class"] = "NXdetector" | ||
ds = nxdetector.create_dataset("counts", data=countsData) | ||
ds.attrs["units"] = "counts" | ||
# link the "two_theta" data stored in separate file | ||
local_addr = nxdetector.name + "/two_theta" | ||
f[local_addr] = h5py.ExternalLink(FILE_HDF5_ANGLES, "/angles") | ||
f.close() | ||
|
||
# create a master NeXus HDF5 file | ||
f = h5py.File(FILE_HDF5_MASTER, "w") | ||
f.attrs["default"] = "entry" | ||
nxentry = f.create_group("entry") | ||
nxentry.attrs["NX_class"] = "NXentry" | ||
nxentry.attrs["default"] = "data" | ||
nxdata = nxentry.create_group("data") | ||
nxdata.attrs["NX_class"] = "NXdata" | ||
|
||
# link in the signal data | ||
local_addr = "/entry/data/counts" | ||
external_addr = "/entry/instrument/detector/counts" | ||
f[local_addr] = h5py.ExternalLink(FILE_HDF5_COUNTS, external_addr) | ||
nxdata.attrs["signal"] = "counts" | ||
|
||
# link in the axes data | ||
local_addr = "/entry/data/two_theta" | ||
f[local_addr] = h5py.ExternalLink(FILE_HDF5_ANGLES, "/angles") | ||
nxdata.attrs["axes"] = "two_theta" | ||
nxdata.attrs["two_theta_indices"] = [ | ||
0, | ||
] | ||
|
||
local_addr = "/entry/instrument" | ||
f[local_addr] = h5py.ExternalLink(FILE_HDF5_COUNTS, "/entry/instrument") | ||
|
||
f.close() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.