adds units of measurement (UoM) in Material class and children

This commit is contained in:
2026-02-16 11:30:08 +01:00
parent ca2cdbfded
commit 41ff025098

View File

@@ -139,7 +139,13 @@ class Material:
self.name = material_data["title"] # required self.name = material_data["title"] # required
self.extra = material_data["metadata_decoded"]["extra_fields"] self.extra = material_data["metadata_decoded"]["extra_fields"]
self.compound_elabid = self.extra["Compound"]["value"] self.compound_elabid = self.extra["Compound"]["value"]
self.dimensions = self.extra["Size"]["value"] self.dimensions = str(self.extra["Size"]["value"]) # strings have a .count() method
if self.dimensions.count("mm") == 2:
self.dimensions_unit = "mm x mm"
elif self.dimensions[-1] == '"':
self.dimensions_unit = "inches"
else:
self.dimensions_unit = None
except KeyError as k: except KeyError as k:
# 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:
@@ -166,6 +172,7 @@ class Substrate(Material):
try: try:
self.orientation = self.extra["Orientation"]["value"] self.orientation = self.extra["Orientation"]["value"]
self.miscut_angle = self.extra["Miscut Angle"]["value"] self.miscut_angle = self.extra["Miscut Angle"]["value"]
self.miscut_angle_unit = self.extra["Miscut Angle"]["unit"]
self.miscut_direction = self.extra["Miscut Direction"]["value"] self.miscut_direction = self.extra["Miscut Direction"]["value"]
# Not present (yet) on eLabFTW for Substrates: # Not present (yet) on eLabFTW for Substrates:
self.thickness = None #self.extra["Thickness"]["value"] self.thickness = None #self.extra["Thickness"]["value"]
@@ -180,13 +187,14 @@ class Target(Material):
super().__init__(material_data) super().__init__(material_data)
try: try:
self.thickness = self.extra["Thickness"]["value"] self.thickness = self.extra["Thickness"]["value"]
self.thickness_unit = self.extra["Thickness"]["unit"]
self.shape = self.extra["shape"]["value"] self.shape = self.extra["shape"]["value"]
self.solid_form = self.extra["Solid form"]["value"] self.solid_form = self.extra["Solid form"]["value"]
self.manufacturer = self.extra["Supplier"]["value"] self.manufacturer = self.extra["Supplier"]["value"]
except KeyError as k: except KeyError as k:
raise KeyError(f"The provided dictionary lacks a \"{k}\" key - which is specific for PLD targets. Check the {self.name} target entry on eLabFTW and make sure you used the correct Resource template.") raise KeyError(f"The provided dictionary lacks a \"{k}\" key - which is specific for PLD targets. Check the {self.name} target entry on eLabFTW and make sure you used the correct Resource template.")
# Non-required attributes: # Non-required attributes:
self.description = material_data.get("body") or "" self.description = material_data.get("body") or None