2 Commits
main ... dev

Author SHA256 Message Date
59e82f0b66 rheed_data/layer_N has now attr NXclass set to "NXsubentry" 2026-05-18 12:41:58 +02:00
7721ca5805 main.py code rearranged
now many of the instructions prev. under the __name__ = "__main__"
condition have their own function (now called main())
2026-05-18 12:36:36 +02:00

View File

@@ -771,6 +771,7 @@ def build_nexus_file(pld_fabrication, output_path="output/nffa-di_unnamed.h5"):
rheed_data = pld_fabrication["rheed_data"] rheed_data = pld_fabrication["rheed_data"]
for layer in rheed_data: for layer in rheed_data:
nx_rheed_layer = nx_rheed.create_group(layer) nx_rheed_layer = nx_rheed.create_group(layer)
nx_rheed_layer.attrs["NX_class"] = "NXsubentry"
layer_dict = rheed_data[layer] layer_dict = rheed_data[layer]
n = layer_dict["layer_number"] n = layer_dict["layer_number"]
@@ -873,6 +874,39 @@ def build_nexus_file(pld_fabrication, output_path="output/nffa-di_unnamed.h5"):
# * Layer.fetch_images() - dictionary # * Layer.fetch_images() - dictionary
def main(
api_key,
ELABFTW_API_URL,
elabid,
):
handler = APIHandler(api_key, ELABFTW_API_URL)
sample_raw_data = handler.get_entry_from_elabid(elabid)
sample = Entrypoint(sample_raw_data)
sample_name = sample.name.strip().replace(
" ", "-"
) # returns error if no "title" or title is not str
# Less important variables:
operative_unit = os.getenv("operative_unit") or None
if operative_unit:
operative_unit = operative_unit.strip().replace(" ", "-")
if sample.proposal:
sample_proposal = call_proposal_from_elabid(sample.proposal)
else:
sample_proposal = None
substrate_object = chain_entrypoint_to_batch(sample) # Substrate-class object
layers = chain_entrypoint_to_layers(sample) # list of Layer-class objects
# n_layers = len(layers) # total number of layers on the sample
fn_base = (
"nffa-di_"
+ (f"{sample_proposal}_" if sample_proposal else "")
+ (f"{operative_unit}_" if operative_unit else "")
+ "PLD_"
+ sample_name[:9]
)
result = make_nexus_schema_dictionary(substrate_object, layers)
return {"result": result, "fn_base": fn_base}
if __name__ == "__main__": if __name__ == "__main__":
load_dotenv() load_dotenv()
api_key = os.getenv("api_key") or getpass("Paste API key here: ", echo_char="*") api_key = os.getenv("api_key") or getpass("Paste API key here: ", echo_char="*")
@@ -884,32 +918,16 @@ if __name__ == "__main__":
ELABFTW_API_URL = os.getenv("ELABFTW_API_URL") or input( ELABFTW_API_URL = os.getenv("ELABFTW_API_URL") or input(
"Enter a valid eLabFTW API URL (ends with '/api/v2)': " "Enter a valid eLabFTW API URL (ends with '/api/v2)': "
) )
handler = APIHandler(api_key, ELABFTW_API_URL)
data = handler.get_entry_from_elabid(elabid) output = main(
sample = Entrypoint(data) api_key,
sample_name = sample.name.strip().replace( ELABFTW_API_URL,
" ", "-" elabid,
) # returns error if no "title" or title is not str
operative_unit = os.getenv("operative_unit") or None
if operative_unit:
operative_unit = operative_unit.strip().replace(" ", "-")
if sample.proposal:
sample_proposal = call_proposal_from_elabid(sample.proposal)
else:
sample_proposal = None
substrate_object = chain_entrypoint_to_batch(sample) # Substrate-class object
layers = chain_entrypoint_to_layers(sample) # list of Layer-class objects
n_layers = len(layers) # total number of layers on the sample
# print(make_nexus_schema_dictionary(substrate_object, layers)) # debug
fn_base = (
"nffa-di_"
+ (f"{sample_proposal}_" if sample_proposal else "")
+ (f"{operative_unit}_" if operative_unit else "")
+ "PLD_"
+ sample_name[:9]
) )
result = make_nexus_schema_dictionary(substrate_object, layers) result = output["result"]
fn_base = output["fn_base"]
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)