From 41ff025098d967f8da3fab80610462b5c8ea39e46ed42406bc3f80395dd00718 Mon Sep 17 00:00:00 2001 From: PioApocalypse Date: Mon, 16 Feb 2026 11:30:08 +0100 Subject: [PATCH] adds units of measurement (UoM) in Material class and children --- src/classes.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/classes.py b/src/classes.py index 13be47f..c9eb5c0 100644 --- a/src/classes.py +++ b/src/classes.py @@ -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