diff --git a/frappy/lib/__init__.py b/frappy/lib/__init__.py index 79c7fa5f..b227c13c 100644 --- a/frappy/lib/__init__.py +++ b/frappy/lib/__init__.py @@ -492,15 +492,3 @@ def delayed_import(modname): except Exception: return _Raiser(modname) return module - - -class LazyImport: - module = None - - def __init__(self, modulename): - self.modulename = modulename - - def __getattr__(self, name): - if self.module is None: - self.module = __import__(self.modulename) - return getattr(self.module, name) \ No newline at end of file diff --git a/frappy_psi/lakeshore.py b/frappy_psi/lakeshore.py index 5db8fe44..24d8b4c7 100644 --- a/frappy_psi/lakeshore.py +++ b/frappy_psi/lakeshore.py @@ -22,6 +22,8 @@ import time import math import random import threading +import numpy as np +from numpy.testing import assert_approx_equal from frappy.core import Module, Readable, Parameter, Property, \ HasIO, StringIO, Writable, IDLE, ERROR, BUSY, DISABLED, nopoll, Attached @@ -30,15 +32,12 @@ from frappy.datatypes import IntRange, FloatRange, StringType, \ from frappy.errors import CommunicationFailedError, ConfigError, \ HardwareError, DisabledError, ImpossibleError, secop_error, SECoPError from frappy.lib.units import NumberWithUnit, format_with_unit -from frappy.lib import formatStatusBits, LazyImport +from frappy.lib import formatStatusBits +from frappy_psi.calcurve import CalCurve from frappy_psi.convergence import HasConvergence from frappy.mixins import HasOutputModule, HasControlledBy from frappy.extparams import StructParam -np = LazyImport('numpy') -np_testing = LazyImport('numpy.testing') -calcurve_module = LazyImport('frappy_psi.calcurve') - def string_to_num(string): try: @@ -420,7 +419,7 @@ class Device(HasLscIO, Module): """check whether a returned calibration point is equal within curve point precision""" for v1, v2, eps in zip(left, right, fixeps): try: - np_testing.assert_approx_equal(v1, v2, significant, verbose=False) + assert_approx_equal(v1, v2, significant, verbose=False) except AssertionError: return abs(v1 - v2) < eps return True @@ -465,7 +464,7 @@ class CurveRequest: self.action = device.find_curve self.new_sensors = set() self.sensors = {sensor.channel: sensor} - calcurve = calcurve_module.CalCurve(sensor.calcurve) + calcurve = CalCurve(sensor.calcurve) equipment_id = device.propertyValues.get('original_id') or device.secNode.equipment_id name = f"{equipment_id.split('.')[0]}.{sensor.name}" sn = calcurve.calibname @@ -613,16 +612,19 @@ class Sensor(Base, Readable): @nopoll def read_value(self): - self.status, value, self.raw = self.get_data() + self.status, value, raw = self.get_data() if isinstance(value, SECoPError): - raise value.copy() + raise value + if not isinstance(raw, SECoPError): + self.raw = raw return value @nopoll def read_raw(self): - self.status, self.value, raw = self.get_data() + self.status, value, raw = self.get_data() if isinstance(raw, SECoPError): - raise raw.copy() + raise raw + self.value = value return raw def read_status(self):