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

Update file maxwell_integrate_to_h5.py

parent bdea655c
No related branches found
No related tags found
No related merge requests found
......@@ -121,14 +121,27 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"):
results_df = results_df.sort_values(by="filename", key=lambda col: col.str.lower())
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')
results_df.to_hdf(os.path.join(subdir_path_int, f"{subdir_name}.h5"), key='entry/data', mode='w', format='table')
with pd.HDFStore(os.path.join(subdir_path_int, f"{subdir_name}.h5"), mode='w') as hdf_store:
hdf_store.put("entry/definition", pd.Series(["NXdata"]), format='table')
hdf_store.put("entry/title", pd.Series([subdir_name]), format='table')
# Create the NXdata group with Nexus conventions
nxdata_group = {
"@axes": "q",
"@signal": "I",
"@errors": "dI"
}
hdf_store.put("entry/data/NXdata", pd.Series(nxdata_group), format='table')
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.")
hdf_store.put(f"entry/data/{filename_key}/q", pd.Series(result["q"]), format='table')
hdf_store.put(f"entry/data/{filename_key}/I", pd.Series(result["I"]), format='table')
hdf_store.put(f"entry/data/{filename_key}/dI", pd.Series(result["dI"]), format='table')
print(f"Results for subdirectory {subdir_name} saved to CSV and HDF5 files using Nexus conventions.")
del results_df
else:
print(f"No images were integrated in subdirectory {subdir}. No results DataFrame created.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment