From 324d527a02e0667523513e81cf8d5d1a134bb7b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=B6ne=2C=20Tjark=20Leon=20Raphael?=
<tjark.leon.raphael.groene@uni-hamburg.de>
Date: Tue, 17 Jun 2025 10:49:10 +0200
Subject: [PATCH] Update file maxwell_integrate_to_h5.py
---
maxwell_integrate_to_h5.py | 45 ++++++++++++++++++++++++--------------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git a/maxwell_integrate_to_h5.py b/maxwell_integrate_to_h5.py
index dc5b14c..a2bb63f 100644
--- a/maxwell_integrate_to_h5.py
+++ b/maxwell_integrate_to_h5.py
@@ -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:
- entry = h5.create_group(f"/{subdir_name}")
- entry.attrs["NX_class"] = "NXentry"
- entry.attrs["default"] = "last_plot" # reference to the last spectrum
+ h5.attrs["NX_class"] = "NXroot"
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
- detector = scan_group.create_group("instrument/detector")
+ detector = entry.create_group("instrument/detector")
detector.attrs["NX_class"] = "NXdetector"
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"):
detector["I"].attrs["interpretation"] = "spectrum"
# Measurement group (holds soft links)
- meas = scan_group.create_group("measurement")
+ meas = entry.create_group("measurement")
meas.attrs["NX_class"] = "NXdata"
meas.attrs["signal"] = "I"
meas.attrs["axes"] = "q"
meas.attrs["filename"] = result["filename"]
- meas["I"] = h5py.SoftLink(f"/{subdir_name}/{scan_name}/instrument/detector/I")
- meas["q"] = h5py.SoftLink(f"/{subdir_name}/{scan_name}/instrument/detector/q")
- meas["dI"] = h5py.SoftLink(f"/{subdir_name}/{scan_name}/instrument/detector/dI")
+ meas["I"] = h5py.SoftLink(f"/{subdir_name}/{entry_name}/instrument/detector/I")
+ meas["q"] = h5py.SoftLink(f"/{subdir_name}/{entry_name}/instrument/detector/q")
+ meas["dI"] = h5py.SoftLink(f"/{subdir_name}/{entry_name}/instrument/detector/dI")
# Optional display-friendly names
meas["I"].attrs["long_name"] = "Intensity"
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:
- scan_group.attrs["default"] = "measurement"
+ entry.attrs["default"] = "plotselect"
# Optional global default plot group
if idx == len(results_data): # mark the last one as global default
- entry["last_plot"] = h5py.SoftLink(f"/{subdir_name}/{scan_name}/measurement")
-
- # Title or metadata
- entry["title"] = "Collected Q-I scans"
-
- h5.flush()
+ entry["last_plot"] = h5py.SoftLink(f"/{subdir_name}/{entry_name}/measurement")
+
# h5 = h5py.File(output_file, "w")
# h5["/entry/instrument/q/data"] = result["q"]
--
GitLab