From 1a32ed8a9e789c1e4c06db57af57eaac1d1c7074 Mon Sep 17 00:00:00 2001 From: Jerome Carnis Date: Wed, 30 Mar 2022 10:30:22 +0200 Subject: [PATCH 1/4] attribute: use the VALUE if SETPOINT is None in `within_tolerance` --- kamzik3/devices/attribute.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamzik3/devices/attribute.py b/kamzik3/devices/attribute.py index b10d9d0..f78e05e 100755 --- a/kamzik3/devices/attribute.py +++ b/kamzik3/devices/attribute.py @@ -527,7 +527,7 @@ class Attribute(dict): :return: bool """ assert isinstance(value, Quantity) - setpoint = self.setpoint() + setpoint = self.setpoint() if self.setpoint() is not None else self.value() return bool( (setpoint - self.negative_tolerance()) <= value -- GitLab From 1a30c748e903c9c6d61a3a0a209a9e7a017a87c9 Mon Sep 17 00:00:00 2001 From: Jerome Carnis Date: Wed, 30 Mar 2022 12:16:57 +0200 Subject: [PATCH 2/4] deviceTango: check unit and discard it if not in pint.UnitRegistry() --- kamzik3/devices/deviceTango.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/kamzik3/devices/deviceTango.py b/kamzik3/devices/deviceTango.py index 34bc3bf..923c0df 100755 --- a/kamzik3/devices/deviceTango.py +++ b/kamzik3/devices/deviceTango.py @@ -6,7 +6,7 @@ from threading import Thread import numpy as np -from kamzik3 import DeviceError +from kamzik3 import DeviceError, units from kamzik3.constants import * from kamzik3.devices.device import Device from kamzik3.snippets.snippetsDecorators import expose_method @@ -147,6 +147,25 @@ class DeviceTango(Device, DeviceProxy): else: value = str(value) + try: + if tc.unit is None: + unit = "" + elif tc.unit == "%": + unit = tc.unit + elif tc.unit != "" and tc.unit not in units: + self.logger.info( + f"{self.device_id}: not a valid unit '{tc.unit}', " + "default unit to ''" + ) + unit = "" + else: + unit = tc.unit + except TypeError: # can't parse + self.logger.error( + f"{self.device_id}: can't parse {tc.unit}, default unit to ''" + ) + unit = "" + self.create_attribute( attribute, default_value=value, @@ -154,7 +173,7 @@ class DeviceTango(Device, DeviceProxy): description=tc.description, default_type=default_type, set_function=set_function, - unit=tc.unit, + unit=unit, min_value=min_value, max_value=max_value, decimals=decimals, -- GitLab From f604df7b551960008c5b5a7052fa90d4bfa3b3bd Mon Sep 17 00:00:00 2001 From: Jerome Carnis Date: Fri, 8 Apr 2022 09:02:54 +0200 Subject: [PATCH 3/4] Fix typing issues --- kamzik3/devices/attribute.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kamzik3/devices/attribute.py b/kamzik3/devices/attribute.py index f78e05e..ad27a63 100755 --- a/kamzik3/devices/attribute.py +++ b/kamzik3/devices/attribute.py @@ -491,7 +491,7 @@ class Attribute(dict): else: return [attribute] - def convert_units(self, value: Optional[Quantity]): + def convert_units(self, value: Quantity): """ Convert input value to current attribute unit. @@ -507,7 +507,7 @@ class Attribute(dict): return value.to(self[UNIT]) - def within_limits(self, value: Optional[Quantity]) -> bool: + def within_limits(self, value: Quantity) -> bool: """ Check if value is within limits. @@ -519,7 +519,7 @@ class Attribute(dict): assert isinstance(value, Quantity) return bool(self.minimum() <= value <= self.maximum()) - def within_tolerance(self, value: Optional[Quantity]) -> bool: + def within_tolerance(self, value: Quantity) -> bool: """ Check if value is within tolerance. @@ -527,7 +527,9 @@ class Attribute(dict): :return: bool """ assert isinstance(value, Quantity) - setpoint = self.setpoint() if self.setpoint() is not None else self.value() + setpoint = self.setpoint() + if setpoint is None: + setpoint = self.value() return bool( (setpoint - self.negative_tolerance()) <= value -- GitLab From 805e70b72fdd9d3474c06746c94a32928e964139 Mon Sep 17 00:00:00 2001 From: Jerome Carnis Date: Fri, 8 Apr 2022 09:45:44 +0200 Subject: [PATCH 4/4] deviceTango: catch ValueError in unit check with pint unit registry --- kamzik3/devices/deviceTango.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kamzik3/devices/deviceTango.py b/kamzik3/devices/deviceTango.py index 923c0df..276fc2f 100755 --- a/kamzik3/devices/deviceTango.py +++ b/kamzik3/devices/deviceTango.py @@ -149,9 +149,9 @@ class DeviceTango(Device, DeviceProxy): try: if tc.unit is None: - unit = "" + unit = "" # "" raises an AttributeError in pint elif tc.unit == "%": - unit = tc.unit + unit = tc.unit # "%" raises an AttributeError in pint elif tc.unit != "" and tc.unit not in units: self.logger.info( f"{self.device_id}: not a valid unit '{tc.unit}', " @@ -160,7 +160,7 @@ class DeviceTango(Device, DeviceProxy): unit = "" else: unit = tc.unit - except TypeError: # can't parse + except (ValueError, TypeError): # issue with parsing in pint self.logger.error( f"{self.device_id}: can't parse {tc.unit}, default unit to ''" ) @@ -494,14 +494,14 @@ class DeviceTangoEigerDetector(DeviceTango): :param Exposure: desired exposure time per frame """ - self.logger.info(f"Live view has started.") + self.logger.info("Live view has started.") self.set_attribute(["TriggerMode", VALUE], 3) if self.file_writer is not None: - self.logger.info(f"FileWriter disabled") + self.logger.info("FileWriter disabled") self.set_attribute(["FileWriter", "Mode", VALUE], 1) self.set_attribute(["FileWriter", "NimagesPerFile", VALUE], 1000000) if self.eiger_stream is not None: - self.logger.info(f"EigerStream disabled") + self.logger.info("EigerStream disabled") self.set_attribute(["EigerStream", "Mode", VALUE], 1) Exposure = float(device_units(self, "FrameTime", Exposure).m) # According to Jan 10ms is lowest frame time -- GitLab