Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jan 16, 2025
1 parent ea6513e commit 7522a2c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pioreactor/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions pioreactor/tests/test_calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ 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:
calibration.curve_data_ = [25, -10, 1] # 25x^2 - 10x + 1
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:
Expand All @@ -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
Expand Down
13 changes: 11 additions & 2 deletions pioreactor/tests/test_od_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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

0 comments on commit 7522a2c

Please sign in to comment.