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

Update file maxwell_integrate_to_h5.py

parent d04b6a0c
No related branches found
No related tags found
No related merge requests found
......@@ -213,13 +213,20 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"):
for idx, result in enumerate(results_data, start=1):
if not result["q"].size or not result["I"].size:
print(f"Skipping invalid scan data for entry {entry_name}")
continue
entry_name = f"{idx:05d}.1"
entry = h5.create_group(entry_name)
entry["title"] = "Collected Q-I scans"
entry.attrs["NX_class"] = "NXentry"
entry.create_dataset("time", data=results_metadata[idx-1]["dateString"].encode('utf-8'), dtype=h5py.string_dtype(encoding='utf-8'))
# entry.create_dataset("time", data=results_metadata[idx-1]["dateString"].encode('utf-8'), dtype=h5py.string_dtype(encoding='utf-8'))
entry.attrs["time"] = results_metadata[idx-1]["dateString"].encode('utf-8')
if image_sequence_number.isdigit():
entry.attrs["image sequence number"] = int(image_sequence_number)
if any(results_metadata[idx-1][key] for key in ["userComment1", "userComment2", "userComment3", "userComment4"]):
......@@ -240,7 +247,7 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"):
detector.attrs["NX_class"] = "NXdetector"
chunk_size = 512
detector.create_dataset("q", data=np.asarray(result["q"], dtype=np.float64), chunks=(chunk_size,), dtype="f8", compression_opts=4, compression="gzip")
detector.create_dataset("q [1/Å]", data=np.asarray(result["q"], dtype=np.float64), chunks=(chunk_size,), dtype="f8", compression_opts=4, compression="gzip")
detector.create_dataset("I", data=np.asarray(result["I"], dtype=np.float64), chunks=(chunk_size,), dtype="f8", compression_opts=4, compression="gzip")
detector.create_dataset("dI", data=np.asarray(result["dI"], dtype=np.float64), chunks=(chunk_size,), dtype="f8", compression_opts=4, compression="gzip")
......@@ -255,14 +262,12 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"):
if width.isdigit() and height.isdigit():
det_size = detector.create_group("detector size")
det_size.attrs["NX_class"] = "NXcollection"
det_size.create_dataset("detector width [pixel]", data=np.asarray([int(width)], dtype=np.int64), dtype="i4", compression_opts=4, compression="gzip")
det_size.create_dataset("detector height [pixel]", data=np.asarray([], dtype=np.int64), dtype="i4", compression_opts=4, compression="gzip")
det_size.create_dataset("detector width [pixel]", data=np.asarray([int(width)], dtype=np.int32), dtype="i4", compression_opts=4, compression="gzip")
det_size.create_dataset("detector height [pixel]", data=np.asarray([int(height)], dtype=np.int32), dtype="i4", compression_opts=4, compression="gzip")
if exposure_time.isdigit():
detector.create_dataset("exposure time", data=np.asarray([float(exposure_time)], dtype=np.float32), dtype="f4", compression_opts=4, compression="gzip")
detector.create_dataset("exposure time [s]", data=np.asarray([float(exposure_time)], dtype=np.float32), dtype="f4", compression_opts=4, compression="gzip")
if summed_exposures.replace('.', '', 1).isdigit():
detector.create_dataset("summed exposures", data=np.asarray([int(summed_exposures)], dtype=np.int64), dtype="i4", compression_opts=4, compression="gzip")
if image_sequence_number.isdigit():
detector.create_dataset("image sequence number", data=np.asarray([int(image_sequence_number)], dtype=np.int64), dtype="i4", compression_opts=4, compression="gzip")
detector.create_dataset("summed exposures", data=np.asarray([int(summed_exposures)], dtype=np.int32), dtype="i4", compression_opts=4, compression="gzip")
# Add interpretation info (optional for PyMca)
detector["I"].attrs["interpretation"] = "spectrum"
......@@ -276,12 +281,12 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"):
meas["I"] = h5py.SoftLink(f"/{entry_name}/instrument/detector/I")
meas["q"] = h5py.SoftLink(f"/{entry_name}/instrument/detector/q")
meas["q [1/Å]"] = h5py.SoftLink(f"/{entry_name}/instrument/detector/q [1/Å]")
meas["dI"] = h5py.SoftLink(f"/{entry_name}/instrument/detector/dI")
# Optional display-friendly names
meas["I"].attrs["long_name"] = "Intensity"
meas["q"].attrs["long_name"] = "Q [1/A]"
meas["q [1/Å]"].attrs["long_name"] = "Q [1/Å]"
# Measurement group (holds soft links)
plotselect = entry.create_group("plotselect")
......@@ -290,11 +295,11 @@ def integrate_ims_in_dir(path_im, path_int, dtype_im=".tif", dtype_int=".dat"):
plotselect.attrs["axes"] = "q"
plotselect["I"] = h5py.SoftLink(f"/{entry_name}/instrument/detector/I")
plotselect["q"] = h5py.SoftLink(f"/{entry_name}/instrument/detector/q")
plotselect["q [1/Å]"] = h5py.SoftLink(f"/{entry_name}/instrument/detector/q [1/Å]")
# Optional display-friendly names
plotselect["I"].attrs["long_name"] = "Intensity"
plotselect["q"].attrs["long_name"] = "Q [1/A]"
plotselect["q [1/Å]"].attrs["long_name"] = "Q [1/A]"
# For PyMca auto-plot:
entry.attrs["default"] = "plotselect"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment