adds units of measurement (UoM) in Material class and children
This commit is contained in:
@@ -139,7 +139,13 @@ class Material:
|
||||
self.name = material_data["title"] # required
|
||||
self.extra = material_data["metadata_decoded"]["extra_fields"]
|
||||
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:
|
||||
# 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:
|
||||
@@ -166,6 +172,7 @@ class Substrate(Material):
|
||||
try:
|
||||
self.orientation = self.extra["Orientation"]["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"]
|
||||
# Not present (yet) on eLabFTW for Substrates:
|
||||
self.thickness = None #self.extra["Thickness"]["value"]
|
||||
@@ -180,13 +187,14 @@ class Target(Material):
|
||||
super().__init__(material_data)
|
||||
try:
|
||||
self.thickness = self.extra["Thickness"]["value"]
|
||||
self.thickness_unit = self.extra["Thickness"]["unit"]
|
||||
self.shape = self.extra["shape"]["value"]
|
||||
self.solid_form = self.extra["Solid form"]["value"]
|
||||
self.manufacturer = self.extra["Supplier"]["value"]
|
||||
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.")
|
||||
# Non-required attributes:
|
||||
self.description = material_data.get("body") or ""
|
||||
self.description = material_data.get("body") or None
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user