completes methods for class Material

This commit is contained in:
2026-02-09 16:27:52 +01:00
parent 03d7811904
commit 46df7a948f

View File

@@ -24,6 +24,8 @@ class Layer:
''' '''
Layer(layer_data) - where layer_data is a Python dictionary. Layer(layer_data) - where layer_data is a Python dictionary.
Meant to be used for eLabFTW Experiments of the "PLD Deposition" category.
eLabFTW experiments contain most of the data required by the NeXus file - although every layer is on a different eLab entry; eLabFTW experiments contain most of the data required by the NeXus file - although every layer is on a different eLab entry;
unfortunately, some data like the target's chemical formula must be retrieved through additional HTTP requests. unfortunately, some data like the target's chemical formula must be retrieved through additional HTTP requests.
Attributes 'target_elabid', 'rheed_system_elabid' and 'laser_system_elabid' contain elabid's for these resources, which are all items. Attributes 'target_elabid', 'rheed_system_elabid' and 'laser_system_elabid' contain elabid's for these resources, which are all items.
@@ -92,6 +94,8 @@ class Entrypoint:
''' '''
Entrypoint(sample_data) - where sample_data is a Python dictionary. Entrypoint(sample_data) - where sample_data is a Python dictionary.
Meant to be used for eLabFTW Resources of the "Sample" category.
The entrypoint is the starting point of the process of resolving the data chain. The entrypoint is the starting point of the process of resolving the data chain.
The entrypoint must be a dictionary containing the data of a sample, created directly from the JSON of the item endpoint on eLabFTW - which can be done through the function get_entry_from_elabid. The entrypoint must be a dictionary containing the data of a sample, created directly from the JSON of the item endpoint on eLabFTW - which can be done through the function get_entry_from_elabid.
''' '''
@@ -113,6 +117,8 @@ class Material:
''' '''
Material(material_data) - where material_data is a Python dictionary. Material(material_data) - where material_data is a Python dictionary.
Meant to be used for eLabFTW Resources of either the "PLD Target" or the "Substrate" categories.
Both a PLD Target and a Substrate are materials made of a certain compound, of which we want to know: Both a PLD Target and a Substrate are materials made of a certain compound, of which we want to know:
* Name and formula; * Name and formula;
* Shape and dimensions; * Shape and dimensions;
@@ -126,11 +132,21 @@ class Material:
# Some keys are not required and can be called through the .get() method - which is permissive and allows null values; # Some keys are not required and can be called through the .get() method - which is permissive and allows null values;
# Other keys are required so if they can't be called (invalid or null) raise error and stop execution of the program: # Other keys are required so if they can't be called (invalid or null) raise error and stop execution of the program:
raise KeyError(f"The provided dictionary lacks a \"{k}\" key. Check the target/substrate entry on eLabFTW and make sure you used the correct Resource template.") raise KeyError(f"The provided dictionary lacks a \"{k}\" key. Check the target/substrate entry on eLabFTW and make sure you used the correct Resource template.")
def get_compound(self): def get_compound_data(self):
compound_data = get_entry_from_elabid(self.compound_elabid, entryType="items") raw_compound_data = get_entry_from_elabid(self.compound_elabid, entryType="items")
formula = compound_data["metadata_decoded"]["extra_fields"].get("Chemical formula") name = raw_compound_data["title"]
formula_value = formula.get("value") extra = raw_compound_data["metadata_decoded"]["extra_fields"]
return formula_value formula = extra.get("Chemical formula")
cas = extra.get("CAS number ") or { "value": None }
compound_data = {
"name" : name,
"chemical_formula" : formula.get("value"),
"cas_number" : cas.get("value")
}
return compound_data
def get_compound_formula(self):
formula = self.get_compound_data().get("chemical_formula")
return formula
@@ -173,7 +189,7 @@ if __name__=="__main__":
item = Entrypoint(data) item = Entrypoint(data)
elif data.get("category_title") in ["PLD Target", "Substrate"]: elif data.get("category_title") in ["PLD Target", "Substrate"]:
item = Material(data) item = Material(data)
print(item.get_compound()) print(item.get_compound_formula())
result = item.__dict__ result = item.__dict__
result.pop("extra") result.pop("extra")
print(result) print(result)