From b03b90a86a2a30edadb4cb3729895ac941d5e203 Mon Sep 17 00:00:00 2001 From: appel_c Date: Wed, 7 May 2025 13:25:04 +0200 Subject: [PATCH] fix: fix range checks in Mo1Bragg and IonizationChamber --- .../devices/ionization_chambers/ionization_chamber.py | 10 +++++----- debye_bec/devices/mo1_bragg/mo1_bragg_utils.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/debye_bec/devices/ionization_chambers/ionization_chamber.py b/debye_bec/devices/ionization_chambers/ionization_chamber.py index 53f9466..2b7bfd6 100644 --- a/debye_bec/devices/ionization_chambers/ionization_chamber.py +++ b/debye_bec/devices/ionization_chambers/ionization_chamber.py @@ -187,7 +187,7 @@ class IonizationChamber0(PSIDeviceBase): hv (float) : Desired voltage for the 'HV' terminal. Voltage has to be between 0...3000 """ - if not 0 <= hv <= 3000: + if not (0 <= hv <= 3000): raise ValueError(f"specified HV {hv} not within range [0 .. 3000]") if not np.isclose(np.abs(hv - self.hv.grid_v.get()), 0, atol=3): raise ValueError(f"Grid {self.hv.grid_v.get()} must not be higher than HV {hv}!") @@ -215,7 +215,7 @@ class IonizationChamber0(PSIDeviceBase): grid (float) : Desired voltage for the 'Grid' terminal, Grid Voltage has to be between 0...3000 """ - if not 0 <= grid <= 3000: + if not (0 <= grid <= 3000): raise ValueError(f"specified Grid {grid} not within range [0 .. 3000]") if not np.isclose(np.abs(grid - self.hv.hv_v.get()), 0, atol=3): raise ValueError(f"Grid {grid} must not be higher than HV {self.hv.hv_v.get()}!") @@ -256,13 +256,13 @@ class IonizationChamber0(PSIDeviceBase): wait (bool): If you like to wait for the filling to finish. """ - if 100 < conc1 < 0: + if not (0 <= conc1 <= 100): raise ValueError(f"Concentration 1 {conc1} out of range [0 .. 100 %]") - if 100 < conc2 < 0: + if not (0 <= conc2 <= 100): raise ValueError(f"Concentration 2 {conc2} out of range [0 .. 100 %]") if not np.isclose((conc1 + conc2), 100, atol=0.1): raise ValueError(f"Conc1 {conc1} and conc2 {conc2} must sum to 100 +- 0.1") - if 3 < pressure < 0: + if not (0 <= pressure <= 3): raise ValueError(f"Pressure {pressure} out of range [0 .. 3 bar abs]") self.gmes.gas1_req.set(gas1).wait(timeout=3) diff --git a/debye_bec/devices/mo1_bragg/mo1_bragg_utils.py b/debye_bec/devices/mo1_bragg/mo1_bragg_utils.py index 38d8409..b89a72c 100644 --- a/debye_bec/devices/mo1_bragg/mo1_bragg_utils.py +++ b/debye_bec/devices/mo1_bragg/mo1_bragg_utils.py @@ -37,12 +37,12 @@ def compute_spline( low_deg = low_deg - POSITION_COMPONSATION high_deg = high_deg + POSITION_COMPONSATION - if p_kink < 0 or p_kink > 100: + if not (0 <= p_kink <= 100): raise Mo1UtilsSplineError( "Kink position not within range of [0..100%]" + f"for p_kink: {p_kink}" ) - if e_kink_deg < low_deg or e_kink_deg > high_deg: + if not (low_deg < e_kink_deg < high_deg): raise Mo1UtilsSplineError( "Kink energy not within selected energy range of scan," + f"for e_kink_deg {e_kink_deg}, low_deg {low_deg} and"