|
| 1 | +import numpy as np |
| 2 | +import openpmd_api as io |
| 3 | + |
| 4 | + |
| 5 | +def main(): |
| 6 | + if "bp" in io.file_extensions: |
| 7 | + filename = "../samples/custom_hierarchy.bp" |
| 8 | + else: |
| 9 | + filename = "../samples/custom_hierarchy.json" |
| 10 | + s = io.Series(filename, io.Access.create) |
| 11 | + it = s.write_iterations()[100] |
| 12 | + |
| 13 | + # write openPMD part |
| 14 | + temp = it.meshes["temperature"] |
| 15 | + temp.axis_labels = ["x", "y"] |
| 16 | + temp.unit_dimension = {io.Unit_Dimension.T: 1} |
| 17 | + temp.position = [0.5, 0.5] |
| 18 | + temp.grid_spacing = [1, 1] |
| 19 | + temp.grid_global_offset = [0, 0] |
| 20 | + temp.reset_dataset(io.Dataset(np.dtype("double"), [5, 5])) |
| 21 | + temp[()] = np.zeros((5, 5)) |
| 22 | + |
| 23 | + # write NeXus part |
| 24 | + nxentry = it["Scan"] |
| 25 | + nxentry.set_attribute("NX_class", "NXentry") |
| 26 | + nxentry.set_attribute("default", "data") |
| 27 | + |
| 28 | + data = nxentry["data"] |
| 29 | + data.set_attribute("NX_class", "NXdata") |
| 30 | + data.set_attribute("signal", "counts") |
| 31 | + data.set_attribute("axes", ["two_theta"]) |
| 32 | + data.set_attribute("two_theta_indices", [0]) |
| 33 | + |
| 34 | + counts = data.as_container_of_datasets()["counts"] |
| 35 | + counts.set_attribute("units", "counts") |
| 36 | + counts.set_attribute("long_name", "photodiode counts") |
| 37 | + counts.reset_dataset(io.Dataset(np.dtype("int"), [15])) |
| 38 | + counts[()] = np.zeros(15, dtype=np.dtype("int")) |
| 39 | + |
| 40 | + two_theta = data.as_container_of_datasets()["two_theta"] |
| 41 | + two_theta.set_attribute("units", "degrees") |
| 42 | + two_theta.set_attribute("long_name", "two_theta (degrees)") |
| 43 | + two_theta.reset_dataset(io.Dataset(np.dtype("double"), [15])) |
| 44 | + two_theta[()] = np.zeros(15) |
| 45 | + |
| 46 | + |
| 47 | +if __name__ == "__main__": |
| 48 | + main() |
0 commit comments