clears comments

This commit is contained in:
2026-05-13 09:54:16 +02:00
parent a6d4c72f9c
commit cbf5cdd115

View File

@@ -174,57 +174,8 @@ def deduplicate_instruments_from_layers(layers):
"deposition_chamber": ", ".join(ded_chambers), "deposition_chamber": ", ".join(ded_chambers),
"rheed_system": ", ".join(ded_rheeds), "rheed_system": ", ".join(ded_rheeds),
} # dictionary's name is a joke } # dictionary's name is a joke
# updated_dict = {} # use this for containing the final dataset
# for ded in elegant_dict:
# if len(elegant_dict[ded]) == 0:
# # if len of list is 0 - empty list - raise error
# raise IndexError(f"Missing data: no Laser System, Chamber and/or RHEED System is specified in any of the Deposition-type experiments related to this sample. Fix this on eLabFTW before retrying. Affected list: {ded}.")
# elif len(elegant_dict[ded]) > 1:
# # if len of list is > 1 - too many values - allow the user to pick one
# print("Warning: different instruments have been used for different layers - which is currently not allowed.")
# # there's a better way to do this but I can't remember now for the life of me...
# i = 0
# while i < len(elegant_dict[ded]):
# print(f"{i} - {elegant_dict[ded][i]}")
# i += 1
# ans = None
# while not type(ans) == int or not ans in range(0, len(elegant_dict[ded])):
# ans = input("Please pick one of the previous (0, 1, ...) [default = 0]: ") or "0"
# if ans.isdigit():
# ans = int(ans)
# continue # unnecessary?
# updated_dict[ded] = elegant_dict[ded][ans]
# elif elegant_dict[ded][0] in ["", 0, None]:
# # if len is 1 BUT value is "", 0 or None raise error
# raise ValueError(f"Missing data: a Laser System, Chamber and/or RHEED System which is specified across all the Deposition-type experiments related to this sample is either empty or invalid. Fix this on eLabFTW before retrying. Affected list: {ded}.")
# else:
# # if none of the previous (only 1 value), that single value is used
# updated_dict[ded] = elegant_dict[ded][0]
# instruments_used_dict = {
# "laser_system": updated_dict["Laser Systems"],
# "deposition_chamber": updated_dict["Deposition Chamber"],
# "rheed_system": updated_dict["RHEED Systems"],
# }
return elegant_dict return elegant_dict
### OLD CODE
# if 0 in [ len(i) for i in elegant_list ]:
# # i.e. if length of one of the lists in elegant_list is zero (missing data):
# raise IndexError("Missing data: no Laser System, Chamber and/or RHEED System is specified in any of the Deposition-type experiments related to this sample.")
# if not all([ len(i) == 1 for i in elegant_list ]):
# print("Warning: different instruments have been used for different layers - which is currently not allowed.")
# # for every element in elegant list check if len > 1 and if it is
# print("Selecting the first occurence for every category...")
###
# lasers = { f"layer_{lyr.layer_number}": lyr.laser_system for lyr in layers }
# chambers = { f"layer_{lyr.layer_number}": lyr.deposition_chamber for lyr in layers }
# rheeds = { f"layer_{lyr.layer_number}": lyr.rheed_system for lyr in layers }
# instruments_used_dict = {
# "laser_system": lasers,
# "deposition_chamber": chambers,
# "rheed_system": rheeds,
# }
def select_rheed_data(layer): def select_rheed_data(layer):
""" """
@@ -505,7 +456,17 @@ def make_nexus_schema_dictionary(substrate_object, layers):
return pld_fabrication return pld_fabrication
def build_nexus_file(pld_fabrication, output_path): def build_nexus_file(pld_fabrication, output_path="output/nffa-di_unnamed.h5"):
"""
The function which actually builds the NeXus file for *PLD DEPOSITIONS*.
Saves the file in the specified directory.
Args:
pld_fabrication:
output_path: The full path to the output file, including filename complete with extension.
It's a string, which should be produced with os.path.
Default value is: "output/nffa-di_unnamed.h5" - which is NOT NFFA-DI compliant.
"""
# NOTE: look at the mail attachment from Emiliano... # NOTE: look at the mail attachment from Emiliano...
with h5py.File(output_path, "w") as f: with h5py.File(output_path, "w") as f:
nx_pld_entry = f.create_group("pld_fabrication") nx_pld_entry = f.create_group("pld_fabrication")
@@ -845,6 +806,7 @@ def build_nexus_file(pld_fabrication, output_path):
if image_path and os.path.isfile(image_path): if image_path and os.path.isfile(image_path):
img = Image.open(image_path).convert("L") img = Image.open(image_path).convert("L")
heatmap_matrix = np.array(img, dtype=np.uint8) # or None heatmap_matrix = np.array(img, dtype=np.uint8) # or None
# heatmap_matrix = heatmap_matrix.astype(np.float32) / 255.0 # toggle to normalize matrix values
if heatmap_matrix is not None: if heatmap_matrix is not None:
heatmap = nx_rheed_layer.create_dataset( heatmap = nx_rheed_layer.create_dataset(
@@ -874,21 +836,6 @@ def build_nexus_file(pld_fabrication, output_path):
# * Layer.fetch_textual_uploads() - dictionary # * Layer.fetch_textual_uploads() - dictionary
# * Layer.fetch_images() - dictionary # * Layer.fetch_images() - dictionary
# nx_rheed = nx_pld_entry.create_group("rheed_data")
# nx_rheed.attrs["NX_class"] = "NXdata"
# nx_rheed.create_dataset("time", data=rheed_osc["time"])
# nx_rheed["time"].attrs["units"] = "s"
# nx_rheed.create_dataset("intensity", data=rheed_osc["intensity"])
# #nx_rheed["intensity"].attrs["units"] = "counts"
# nx_rheed["intensity"].attrs["long_name"] = "RHEED intensity"
# nx_rheed.attrs["signal"] = "intensity"
# nx_rheed.attrs["axes"] = "layer:time:channel"
# nx_rheed.attrs["layer_indices"] = [0] # asse layer
# nx_rheed.attrs["time_indices"] = [1] # asse tempo
# nx_rheed.attrs["channel_indices"] = [2]
if __name__ == "__main__": if __name__ == "__main__":
# TO-DO: place the API base URL somewhere else. # TO-DO: place the API base URL somewhere else.
@@ -907,7 +854,6 @@ if __name__ == "__main__":
substrate_object = chain_entrypoint_to_batch(sample) # Substrate-class object substrate_object = chain_entrypoint_to_batch(sample) # Substrate-class object
layers = chain_entrypoint_to_layers(sample) # list of Layer-class objects layers = chain_entrypoint_to_layers(sample) # list of Layer-class objects
n_layers = len(layers) # total number of layers on the sample n_layers = len(layers) # total number of layers on the sample
result = make_nexus_schema_dictionary(substrate_object, layers)
# print(make_nexus_schema_dictionary(substrate_object, layers)) # debug # print(make_nexus_schema_dictionary(substrate_object, layers)) # debug
fn_base = ( fn_base = (
"nffa-di_" "nffa-di_"
@@ -916,17 +862,9 @@ if __name__ == "__main__":
+ "_" + "_"
+ sample_name + sample_name
) )
result = make_nexus_schema_dictionary(substrate_object, layers)
with open(f"output/{fn_base}.json", "w") as f: with open(f"output/{fn_base}.json", "w") as f:
json.dump(result, f, indent=3) json.dump(result, f, indent=3)
# TO-DO: remove the hard-coded path of the RWA file
# ideally the script should download a TXT/CSV file from each layer
# (IF PRESENT ←→ also handle missing file error)
# and merge all data in a single file to analyse it
# WARNING: fails if file is missing
# This one tries to open a png image.
# Emiliano said to keep it to one image per layer tops.
# In this test I will only consider one image.
# TO-DO: make it format-agnostic. If not possible, make it PNG-only.
# mx = mx.astype(np.float32) / 255.0 # consider deleting???
build_nexus_file(result, output_path=f"output/{fn_base}.h5") build_nexus_file(result, output_path=f"output/{fn_base}.h5")