diff --git a/pioreactor/structs.py b/pioreactor/structs.py index 13a7ec16..364aa251 100644 --- a/pioreactor/structs.py +++ b/pioreactor/structs.py @@ -210,7 +210,7 @@ def ipredict(self, y: Y, enforce_bounds=False) -> X: poly = self.curve_data_ - coef_shift = zeros_like(poly) + coef_shift = zeros_like(poly, dtype=float) coef_shift[-1] = y solve_for_poly = poly - coef_shift roots_ = roots(solve_for_poly).tolist() diff --git a/pioreactor/tests/test_calibrations.py b/pioreactor/tests/test_calibrations.py index 4969f822..6488b32a 100644 --- a/pioreactor/tests/test_calibrations.py +++ b/pioreactor/tests/test_calibrations.py @@ -163,9 +163,9 @@ def test_ipredict_multiple_solutions(calibration) -> None: def test_ipredict_solution_below_domain(calibration) -> None: calibration.curve_data_ = [5, 3, 2] # 5x^2 + 3x + 2 calibration.recorded_data = {"x": [0, 1], "y": [10, 20]} - y = 100 # Solution below domain + y = 1.99 # Solution below domain with pytest.raises(exc.SolutionBelowDomainError): - calibration.ipredict(y) + calibration.ipredict(y, enforce_bounds=True) def test_ipredict_solution_above_domain(calibration) -> None: @@ -173,7 +173,7 @@ def test_ipredict_solution_above_domain(calibration) -> None: calibration.recorded_data = {"x": [0, 1], "y": [0, 100]} y = 50 # Solution above domain with pytest.raises(exc.SolutionAboveDomainError): - calibration.ipredict(y) + calibration.ipredict(y, enforce_bounds=True) def test_predict_ipredict_consistency(calibration) -> None: @@ -194,9 +194,9 @@ def test_linear_data_produces_linear_curve_in_range_even_if_high_degree() -> Non ) od = np.insert(od, 0, 0) - v = 0.5 * od + 0.01 * np.random.randn(od.shape[0]) + v = 0.5 * od + 0.005 * np.random.randn(od.shape[0]) - curve_data_ = calculate_poly_curve_of_best_fit(v, od, degree=4) # type: ignore + curve_data_ = calculate_poly_curve_of_best_fit(od, v, degree=4) # type: ignore curve_callable = curve_to_callable("poly", curve_data_) for od_, v_ in zip(od, curve_callable(od)): assert (v_ - od_ * 0.5) < 0.035 diff --git a/pioreactor/tests/test_od_reading.py b/pioreactor/tests/test_od_reading.py index 09bceb84..731ce3e0 100644 --- a/pioreactor/tests/test_od_reading.py +++ b/pioreactor/tests/test_od_reading.py @@ -1123,8 +1123,6 @@ def test_missing_calibration_data(): def test_mandys_calibration(): - from pioreactor.calibrations import load_calibration - mcal = structs.ODCalibration( calibration_name="mandy", calibrated_on_pioreactor_unit="pio1", @@ -1141,4 +1139,15 @@ def test_mandys_calibration(): angle="90", pd_channel="2", ) + + with pytest.raises(exc.SolutionAboveDomainError): + assert 0.0 < mcal.ipredict(0.002, enforce_bounds=True) < 1.0 + + # correct the curve + mcal.curve_data_ = [ + -0.028385470467897377, + 0.12917002770232924, + 0.07787877483987993, + 0.0011023858538965646, + ] assert 0.0 < mcal.ipredict(0.002, enforce_bounds=True) < 1.0