diff --git a/lumicks/pylake/force_calibration/calibration_item.py b/lumicks/pylake/force_calibration/calibration_item.py index 247704961..33802ef56 100644 --- a/lumicks/pylake/force_calibration/calibration_item.py +++ b/lumicks/pylake/force_calibration/calibration_item.py @@ -39,7 +39,7 @@ def _fitted_diode(self): return "f_diode (Hz)" in self or "alpha" in self @property - def diode_calibration(self) -> DiodeCalibrationModel: + def diode_calibration(self) -> DiodeCalibrationModel | None: """Diode calibration model The detector used to measure forces has a limited bandwidth. This bandwidth is typically @@ -66,7 +66,10 @@ def diode_calibration(self) -> DiodeCalibrationModel: assert diode_parameters["fixed_diode"] == item.diode_frequency assert diode_parameters["fixed_alpha"] == item.diode_relaxation_factor """ - return DiodeCalibrationModel.from_calibration_dict(self.data) + try: + return DiodeCalibrationModel.from_calibration_dict(self.data) + except ValueError: + return None # No diode calibration present @property def trap_power(self): diff --git a/lumicks/pylake/force_calibration/calibration_models.py b/lumicks/pylake/force_calibration/calibration_models.py index a99d3f618..40cd1c3f1 100644 --- a/lumicks/pylake/force_calibration/calibration_models.py +++ b/lumicks/pylake/force_calibration/calibration_models.py @@ -82,15 +82,10 @@ class DiodeCalibrationModel: This model takes a trap voltage and returns the diode parameters at that voltage. These parameters can be passed directly to :func:`~lumicks.pylake.calibrate_force`. - - Attributes - ---------- - params : dict - Dictionary of diode parameters """ _model_fun: Callable = field(repr=False) - params: dict + _params: dict = field(repr=False) @staticmethod def from_calibration_dict(calibration_dict): @@ -104,7 +99,7 @@ def from_calibration_dict(calibration_dict): "max_alpha": calibration_dict["Diode alpha max"], } except KeyError: - return None + raise ValueError("No diode calibration present in the dictionary.") def diode_fun(trap_voltage, params): f_diode, alpha, _ = diode_params_from_voltage(trap_voltage, **params) @@ -120,7 +115,7 @@ def __call__(self, trap_voltage): trap_voltage : array_like Array of trap voltages [V]. """ - return self._model_fun(trap_voltage, self.params) + return self._model_fun(trap_voltage, self._params) def density_of_water(temperature, molarity, pressure=0.101325): diff --git a/lumicks/pylake/force_calibration/tests/test_calibration_item.py b/lumicks/pylake/force_calibration/tests/test_calibration_item.py index cb0f0f8a7..da031eade 100644 --- a/lumicks/pylake/force_calibration/tests/test_calibration_item.py +++ b/lumicks/pylake/force_calibration/tests/test_calibration_item.py @@ -351,7 +351,7 @@ def test_diode_model(trap_power, reference_values): diode_calibration = item.diode_calibration assert item.trap_power == ref_passive_fixed_diode_with_height["Trap sum power (V)"] assert diode_calibration(trap_power) == reference_values - assert diode_calibration.params == { + assert diode_calibration._params == { "delta_f_diode": ref_passive_fixed_diode_with_height["Diode frequency delta"], "rate_f_diode": ref_passive_fixed_diode_with_height["Diode frequency rate"], "max_f_diode": ref_passive_fixed_diode_with_height["Diode frequency max"],