Skip to content

Commit

Permalink
fix calibibrations near 0
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jan 15, 2025
1 parent ae6625e commit 2d4e807
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
1 change: 0 additions & 1 deletion pioreactor/background_jobs/od_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,4 +1260,3 @@ def click_od_reading(
calibration=possible_calibration,
)
od.block_until_disconnected()

25 changes: 10 additions & 15 deletions pioreactor/tests/test_od_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def test_linear_data_produces_linear_curve_in_range_even_if_high_degree() -> Non


def test_mandys_data_for_pathological_poly() -> None:

od = [0.0, 0.139, 0.155, 0.378, 0.671, 0.993, 1.82, 4.061]
v = [0.0, 0.0158, 0.0322, 0.0589, 0.1002, 0.1648, 0.4045, 0.5463]

Expand All @@ -38,20 +37,16 @@ def test_mandys_data_for_pathological_poly() -> None:
assert abs(curve_callable(0.002) - 0.002) < 0.1

mcal = ODCalibration(
calibration_name='mandy',
calibrated_on_pioreactor_unit='pio1',
created_at=current_utc_datetime(),
curve_data_=curve_data_,
curve_type='poly',
recorded_data={'x': od, 'y': v},
ir_led_intensity=70.0,
angle='90',
pd_channel='2')
calibration_name="mandy",
calibrated_on_pioreactor_unit="pio1",
created_at=current_utc_datetime(),
curve_data_=curve_data_,
curve_type="poly",
recorded_data={"x": od, "y": v},
ir_led_intensity=70.0,
angle="90",
pd_channel="2",
)

assert abs(mcal.predict(0.002) - curve_callable(0.002)) < 1e-10
assert abs(mcal.ipredict(0.002) - 0.002) < 0.1





20 changes: 18 additions & 2 deletions pioreactor/tests/test_od_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,5 +1124,21 @@ 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', created_at=current_utc_datetime(), curve_data_=[-0.03112259838616315, 0.14606367297714123, 0.05224678328234911, 0.009665339167023364], curve_type='poly', x='voltage', y='od600s', recorded_data={'x': [0.0, 0.139, 0.155, 0.378, 0.671, 0.993, 1.82, 4.061], 'y': [0.0, 0.0158, 0.0322, 0.0589, 0.1002, 0.1648, 0.4045, 0.5463]}, ir_led_intensity=70.0, angle='90', pd_channel='2')
assert 0.0 < mcal.ipredict(0.002, enforce_bounds=True) < 1.0

mcal = structs.ODCalibration(
calibration_name="mandy",
calibrated_on_pioreactor_unit="pio1",
created_at=current_utc_datetime(),
curve_data_=[-0.03112259838616315, 0.14606367297714123, 0.05224678328234911, 0.009665339167023364],
curve_type="poly",
x="voltage",
y="od600s",
recorded_data={
"x": [0.0, 0.139, 0.155, 0.378, 0.671, 0.993, 1.82, 4.061],
"y": [0.0, 0.0158, 0.0322, 0.0589, 0.1002, 0.1648, 0.4045, 0.5463],
},
ir_led_intensity=70.0,
angle="90",
pd_channel="2",
)
assert 0.0 < mcal.ipredict(0.002, enforce_bounds=True) < 1.0

0 comments on commit 2d4e807

Please sign in to comment.