Skip to content

Commit c7dd04e

Browse files
committed
fixup! make params private; produce exception when from gets invalid values
1 parent a305adc commit c7dd04e

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

lumicks/pylake/force_calibration/calibration_item.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _fitted_diode(self):
3939
return "f_diode (Hz)" in self or "alpha" in self
4040

4141
@property
42-
def diode_calibration(self) -> DiodeCalibrationModel:
42+
def diode_calibration(self) -> DiodeCalibrationModel | None:
4343
"""Diode calibration model
4444
4545
The detector used to measure forces has a limited bandwidth. This bandwidth is typically
@@ -66,7 +66,10 @@ def diode_calibration(self) -> DiodeCalibrationModel:
6666
assert diode_parameters["fixed_diode"] == item.diode_frequency
6767
assert diode_parameters["fixed_alpha"] == item.diode_relaxation_factor
6868
"""
69-
return DiodeCalibrationModel.from_calibration_dict(self.data)
69+
try:
70+
return DiodeCalibrationModel.from_calibration_dict(self.data)
71+
except ValueError:
72+
return None # No diode calibration present
7073

7174
@property
7275
def trap_power(self):

lumicks/pylake/force_calibration/calibration_models.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,10 @@ class DiodeCalibrationModel:
8282
8383
This model takes a trap voltage and returns the diode parameters at that voltage. These
8484
parameters can be passed directly to :func:`~lumicks.pylake.calibrate_force`.
85-
86-
Attributes
87-
----------
88-
params : dict
89-
Dictionary of diode parameters
9085
"""
9186

9287
_model_fun: Callable = field(repr=False)
93-
params: dict
88+
_params: dict = field(repr=False)
9489

9590
@staticmethod
9691
def from_calibration_dict(calibration_dict):
@@ -104,7 +99,7 @@ def from_calibration_dict(calibration_dict):
10499
"max_alpha": calibration_dict["Diode alpha max"],
105100
}
106101
except KeyError:
107-
return None
102+
raise ValueError("No diode calibration present in the dictionary.")
108103

109104
def diode_fun(trap_voltage, params):
110105
f_diode, alpha, _ = diode_params_from_voltage(trap_voltage, **params)
@@ -120,7 +115,7 @@ def __call__(self, trap_voltage):
120115
trap_voltage : array_like
121116
Array of trap voltages [V].
122117
"""
123-
return self._model_fun(trap_voltage, self.params)
118+
return self._model_fun(trap_voltage, self._params)
124119

125120

126121
def density_of_water(temperature, molarity, pressure=0.101325):

lumicks/pylake/force_calibration/tests/test_calibration_item.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def test_diode_model(trap_power, reference_values):
351351
diode_calibration = item.diode_calibration
352352
assert item.trap_power == ref_passive_fixed_diode_with_height["Trap sum power (V)"]
353353
assert diode_calibration(trap_power) == reference_values
354-
assert diode_calibration.params == {
354+
assert diode_calibration._params == {
355355
"delta_f_diode": ref_passive_fixed_diode_with_height["Diode frequency delta"],
356356
"rate_f_diode": ref_passive_fixed_diode_with_height["Diode frequency rate"],
357357
"max_f_diode": ref_passive_fixed_diode_with_height["Diode frequency max"],

0 commit comments

Comments
 (0)