Skip to content
Snippets Groups Projects
Commit 324d527a authored by Gröne, Tjark Leon Raphael's avatar Gröne, Tjark Leon Raphael
Browse files

Update file maxwell_integrate_to_h5.py

parent 1e1409d8
No related branches found
No related tags found
No related merge requests found
...@@ -138,16 +138,18 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"): ...@@ -138,16 +138,18 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"):
with h5py.File(output_file, "w") as h5: with h5py.File(output_file, "w") as h5:
entry = h5.create_group(f"/{subdir_name}") h5.attrs["NX_class"] = "NXroot"
entry.attrs["NX_class"] = "NXentry"
entry.attrs["default"] = "last_plot" # reference to the last spectrum
for idx, result in enumerate(results_data, start=1): for idx, result in enumerate(results_data, start=1):
scan_name = f"{idx:03d}" # e.g., '001'
scan_group = entry.create_group(scan_name) entry_name = f"{idx:05d}.1"
entry = h5.create_group(entry_name)
entry["title"] = "Collected Q-I scans"
entry.attrs["NX_class"] = "NXentry"
# Instrument / Detector group # Instrument / Detector group
detector = scan_group.create_group("instrument/detector") detector = entry.create_group("instrument/detector")
detector.attrs["NX_class"] = "NXdetector" detector.attrs["NX_class"] = "NXdetector"
chunk_size = min(len(result["I"]), 1000) chunk_size = min(len(result["I"]), 1000)
...@@ -159,31 +161,40 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"): ...@@ -159,31 +161,40 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"):
detector["I"].attrs["interpretation"] = "spectrum" detector["I"].attrs["interpretation"] = "spectrum"
# Measurement group (holds soft links) # Measurement group (holds soft links)
meas = scan_group.create_group("measurement") meas = entry.create_group("measurement")
meas.attrs["NX_class"] = "NXdata" meas.attrs["NX_class"] = "NXdata"
meas.attrs["signal"] = "I" meas.attrs["signal"] = "I"
meas.attrs["axes"] = "q" meas.attrs["axes"] = "q"
meas.attrs["filename"] = result["filename"] meas.attrs["filename"] = result["filename"]
meas["I"] = h5py.SoftLink(f"/{subdir_name}/{scan_name}/instrument/detector/I") meas["I"] = h5py.SoftLink(f"/{subdir_name}/{entry_name}/instrument/detector/I")
meas["q"] = h5py.SoftLink(f"/{subdir_name}/{scan_name}/instrument/detector/q") meas["q"] = h5py.SoftLink(f"/{subdir_name}/{entry_name}/instrument/detector/q")
meas["dI"] = h5py.SoftLink(f"/{subdir_name}/{scan_name}/instrument/detector/dI") meas["dI"] = h5py.SoftLink(f"/{subdir_name}/{entry_name}/instrument/detector/dI")
# Optional display-friendly names # Optional display-friendly names
meas["I"].attrs["long_name"] = "Intensity" meas["I"].attrs["long_name"] = "Intensity"
meas["q"].attrs["long_name"] = "Q [1/A]" meas["q"].attrs["long_name"] = "Q [1/A]"
# Measurement group (holds soft links)
plotselect = entry.create_group("plotselect")
plotselect.attrs["NX_class"] = "NXdata"
plotselect.attrs["signal"] = "I"
plotselect.attrs["axes"] = "q"
plotselect["I"] = h5py.SoftLink(f"/{subdir_name}/{entry_name}/instrument/detector/I")
plotselect["q"] = h5py.SoftLink(f"/{subdir_name}/{entry_name}/instrument/detector/q")
# Optional display-friendly names
plotselect["I"].attrs["long_name"] = "Intensity"
plotselect["q"].attrs["long_name"] = "Q [1/A]"
# For PyMca auto-plot: # For PyMca auto-plot:
scan_group.attrs["default"] = "measurement" entry.attrs["default"] = "plotselect"
# Optional global default plot group # Optional global default plot group
if idx == len(results_data): # mark the last one as global default if idx == len(results_data): # mark the last one as global default
entry["last_plot"] = h5py.SoftLink(f"/{subdir_name}/{scan_name}/measurement") entry["last_plot"] = h5py.SoftLink(f"/{subdir_name}/{entry_name}/measurement")
# Title or metadata
entry["title"] = "Collected Q-I scans"
h5.flush()
# h5 = h5py.File(output_file, "w") # h5 = h5py.File(output_file, "w")
# h5["/entry/instrument/q/data"] = result["q"] # h5["/entry/instrument/q/data"] = result["q"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment