Skip to content

Commit

Permalink
Add Python example for custom hierarchies
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed May 24, 2023
1 parent 74f642c commit ced895b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions examples/14_custom_hierarchy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import numpy as np
import openpmd_api as io


def main():
s = io.Series("../samples/custom_hierarchy.bp", io.Access.create)
it = s.write_iterations()[100]

# write openPMD part
temp = it.meshes["temperature"]
temp.axis_labels = ["x", "y"]
temp.unit_dimension = {io.Unit_Dimension.T: 1}
temp.position = [0.5, 0.5]
temp.grid_spacing = [1, 1]
temp.grid_global_offset = [0, 0]
temp.reset_dataset(io.Dataset(np.dtype("double"), [5, 5]))
temp[()] = np.zeros((5, 5))

# write NeXus part
nxentry = it["Scan:NXentry"]
nxentry.set_attribute("NX_class", "NXentry")
nxentry.set_attribute("default", "data")

data = nxentry["data:Nxdata"]
data.set_attribute("NX_class", "NXdata")
data.set_attribute("signal", "counts")
data.set_attribute("axes", ["two_theta"])
data.set_attribute("two_theta_indices", [0])

counts = data.datasets()["counts"]
counts.set_attribute("units", "counts")
counts.set_attribute("long_name", "photodiode counts")
counts.reset_dataset(io.Dataset(np.dtype("int"), [15]))
counts[()] = np.zeros(15, dtype=np.dtype("int"))

two_theta = data.datasets()["two_theta"]
two_theta.set_attribute("units", "degrees")
two_theta.set_attribute("long_name", "two_theta (degrees)")
two_theta.reset_dataset(io.Dataset(np.dtype("double"), [15]))
two_theta[()] = np.zeros(15)



if __name__ == "__main__":
main()

0 comments on commit ced895b

Please sign in to comment.