diff --git a/maxwell_integrate_to_h5.py b/maxwell_integrate_to_h5.py index 1665d11e348dd1b84044d669beeca15cf0e2455c..cc09f1122930dacb10f3f4537687a62213371621 100644 --- a/maxwell_integrate_to_h5.py +++ b/maxwell_integrate_to_h5.py @@ -122,6 +122,12 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"): subdir_name = os.path.basename(os.path.normpath(subdir_path_int)) results_df.to_csv(os.path.join(subdir_path_int, f"{subdir_name}.csv"), index=False) results_df.to_hdf(os.path.join(subdir_path_int, f"{subdir_name}.h5"), key='data', mode='w') + with pd.HDFStore(os.path.join(subdir_path_int, f"{subdir_name}.h5"), mode='w') as hdf_store: + for result in results_data: + filename_key = os.path.basename(result["filename"]) + hdf_store.put(f"measurements/{filename_key}/q", pd.Series(result["q"])) + hdf_store.put(f"measurements/{filename_key}/I", pd.Series(result["I"])) + hdf_store.put(f"measurements/{filename_key}/dI", pd.Series(result["dI"])) print(f"Results for subdirectory {subdir_name} saved to CSV and HDF5 files.") del results_df else: