From 9a7361d2e3ebc8d3be97508f4f93f90ea68d1dc1 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: Mon, 16 Jun 2025 22:55:17 +0200 Subject: [PATCH] Update file maxwell_integrate_to_h5.py --- maxwell_integrate_to_h5.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/maxwell_integrate_to_h5.py b/maxwell_integrate_to_h5.py index 51c817a..a79f9ec 100644 --- a/maxwell_integrate_to_h5.py +++ b/maxwell_integrate_to_h5.py @@ -125,29 +125,37 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"): # Prepare data for HDF5 file using silx hdf5_data = { - "entry": { - "definition": "NXdata", - "title": subdir_name, - "data": { - "@axes": "q", - "@signal": "I", - "@errors": "dI", - } + subdir_name: { + "@NX_class": "NXroot", } } - for result in results_data: - filename_key = os.path.basename(result["filename"]) - hdf5_data["entry"]["data"][filename_key] = { - "q": result["q"].tolist(), - "I": result["I"].tolist(), - "dI": result["dI"].tolist() + # Sort results_data by filename + results_data = sorted(results_data, key=lambda x: x["filename"].lower()) + + for idx, result in enumerate(results_data, start=1): + group_name = f"{idx}.1" + hdf5_data[subdir_name][group_name] = { + "@NX_class": "NXentry", + "description": os.path.basename(result["filename"]), + "measurements": { + "@NX_class": "NXcollection", + "q": result["q"].tolist(), + "I": result["I"].tolist(), + "dI": result["dI"].tolist() + } } # Save to HDF5 file using silx hdf5_file_path = os.path.join(subdir_path_int, f"{subdir_name}.h5") dicttoh5(hdf5_data, hdf5_file_path, mode="w") + print(f"Results for subdirectory {subdir_name} saved to HDF5 file using silx.") + + # Save to HDF5 file using silx + hdf5_file_path = os.path.join(subdir_path_int, f"{subdir_name}.h5") + dicttoh5(hdf5_data, hdf5_file_path, mode="w") + print(f"Results for subdirectory {subdir_name} saved to CSV and HDF5 files using silx.") del results_df else: -- GitLab