diff --git a/src/main.py b/src/main.py index d3994fd..5832970 100644 --- a/src/main.py +++ b/src/main.py @@ -382,7 +382,7 @@ def make_nexus_schema_dictionary(substrate_object, layers): return pld_fabrication -def build_nexus_file(pld_fabrication, output_path, rheed_osc=None): +def build_nexus_file(pld_fabrication, output_path, rheed_osc=None, heatmap_matrix=None): # NOTE: look at the mail attachment from Emiliano... with h5py.File(output_path, "w") as f: nx_pld_entry = f.create_group("pld_fabrication") @@ -645,10 +645,10 @@ def build_nexus_file(pld_fabrication, output_path, rheed_osc=None): raise TypeError(te) # RHEED data section - if rheed_osc is not None: - nx_rheed = nx_pld_entry.create_group("rheed_data") - nx_rheed.attrs["NX_class"] = "NXdata" + nx_rheed = nx_pld_entry.create_group("rheed_data") + nx_rheed.attrs["NX_class"] = "NXdata" + if rheed_osc is not None: # Asse temporale t_ds = nx_rheed.create_dataset("time", data=rheed_osc["time"]) t_ds.attrs["units"] = "s" @@ -682,6 +682,14 @@ def build_nexus_file(pld_fabrication, output_path, rheed_osc=None): # nx_rheed.attrs["layer_indices"] = [0] # asse layer # nx_rheed.attrs["time_indices"] = [1] # asse tempo # nx_rheed.attrs["channel_indices"] = [2] + if heatmap_matrix is not None: + heatmap = nx_rheed.create_dataset("diffraction_image", data=heatmap_matrix) + heatmap.attrs["long_name"] = "Diffraction Image" + heatmap.attrs["units"] = "a.u." + # this is of my own initiative. good??? + heatmap.attrs["interpretation"] = "spectrum" + # suggested by DeepSeek, useful? + heatmap.attrs["suggested_colormap"] = "viridis" return @@ -721,9 +729,12 @@ if __name__ == "__main__": # TO-DO: make it format-agnostic. If not possible, make it PNG-only. if os.path.isfile("tests/LAO_16min50s_736C_STO.bmp"): # if BMP # if os.path.isfile("tests/LAO_16min50s_736C_STO.png"): # if PNG - with open() as img: - img = Image.open("tests/LAO_16min50s_736C_STO.bmp").convert("L") - mx = np.array(img, dtype=np.uint8) + img = Image.open("tests/LAO_16min50s_736C_STO.bmp").convert("L") + mx = np.array(img, dtype=np.uint8) + normalized_mx = mx.astype(np.float32) / 255.0 # consider deleting??? build_nexus_file( - result, output_path=f"output/sample-{sample_name}-nexus.h5", rheed_osc=rheed_osc + result, + output_path=f"output/sample-{sample_name}-nexus.h5", + rheed_osc=rheed_osc, + heatmap_matrix=normalized_mx, )