Skip to content

Commit

Permalink
fixup! make params private; produce exception when from gets invali…
Browse files Browse the repository at this point in the history
…d values
  • Loading branch information
JoepVanlier committed Oct 18, 2024
1 parent a305adc commit c7dd04e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
7 changes: 5 additions & 2 deletions lumicks/pylake/force_calibration/calibration_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
11 changes: 3 additions & 8 deletions lumicks/pylake/force_calibration/calibration_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit c7dd04e

Please sign in to comment.