Skip to content

Commit

Permalink
more calibration stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jan 6, 2025
1 parent 1f64a5b commit 3f6df84
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pioreactor/actions/pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from pioreactor.whoami import get_unit_name

DEFAULT_PWM_CALIBRATION = structs.SimplePeristalticPumpCalibration(
pioreactor_unit=get_unit_name(),
calibrated_on_pioreactor_unit=get_unit_name(),
created_at=default_datetime_for_pioreactor(),
hz=200.0,
dc=100.0,
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/calibrations/od_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def save_results(
) -> structs.ODCalibration:
data_blob = structs.ODCalibration(
created_at=current_utc_datetime(),
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
calibration_name=name,
angle=angle,
maximum_od600=max(od600s),
Expand Down
6 changes: 3 additions & 3 deletions pioreactor/calibrations/pump_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def setup(
hz=hz,
dc=dc,
voltage=voltage_in_aux(),
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
recorded_data={"x": [], "y": []},
),
)
Expand Down Expand Up @@ -233,7 +233,7 @@ def run_tests(
dc=dc,
created_at=current_utc_datetime(),
voltage=voltage_in_aux(),
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
recorded_data={"x": [], "y": []},
)

Expand Down Expand Up @@ -314,7 +314,7 @@ def save_results(
) -> structs.SimplePeristalticPumpCalibration:
pump_calibration_result = structs.SimplePeristalticPumpCalibration(
calibration_name=name,
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
created_at=current_utc_datetime(),
curve_type="poly",
curve_data_=[duration_, bias_],
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/calibrations/stirring_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def run_stirring_calibration(
pwm_hz=config.getfloat("stirring.config", "pwm_hz"),
voltage=voltage_in_aux(),
calibration_name=f"stirring-calibration-{current_utc_datetime().strftime('%Y-%m-%d_%H-%M-%S')}",
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
created_at=current_utc_datetime(),
curve_data_=[rpm_coef, intercept],
curve_type="poly",
Expand Down
5 changes: 5 additions & 0 deletions pioreactor/cli/calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def run_calibration(ctx, device: str, protocol_name: str | None) -> None:
f"Do you want to set this calibration as the Active Calibration for {device}?", default=True
):
calibration_struct.set_as_active_calibration_for_device(device)
click.echo(f"Set{calibration_struct.calibration_name} as the active calibration for {device}.")
else:
click.echo(
f"Okay. You can use 'pio calibration set-active --device {device} --name {calibration_struct.calibration_name}' to set this calibration as the active one."
)

click.echo(
f"Calibration '{calibration_struct.calibration_name}' of device '{device}' saved to {out_file} ✅"
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Voltage(JSONPrintedStruct):

class CalibrationBase(Struct, tag_field="calibration_type", kw_only=True):
calibration_name: str
pioreactor_unit: str
calibrated_on_pioreactor_unit: str
created_at: t.Annotated[datetime, Meta(tz=True)]
curve_data_: list[float]
curve_type: str # ex: "poly"
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/tests/test_calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_save_and_load_calibration(temp_calibration_dir) -> None:
# 1. Create an ODCalibration object (fully valid).
od_cal = ODCalibration(
calibration_name="my_test_cal",
pioreactor_unit="unitA",
calibrated_on_pioreactor_unit="unitA",
created_at=datetime.now(timezone.utc),
curve_data_=[1.0, 2.0, 3.0],
curve_type="poly",
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/tests/test_dosing_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setup_function() -> None:
hz=100,
created_at=datetime(2010, 1, 1, tzinfo=timezone.utc),
voltage=-1.0,
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
)
cal.set_as_active_calibration_for_device("media_pump")
cal.set_as_active_calibration_for_device("alt_media_pump")
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/tests/test_mqtt_to_db_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_dosing_events_land_in_db() -> None:
hz=100,
created_at=current_utc_datetime(),
voltage=-1.0,
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
),
)

Expand Down
18 changes: 9 additions & 9 deletions pioreactor/tests/test_od_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def test_calibration_simple_linear_calibration_positive_slope() -> None:
x="voltage",
y="od600s",
pd_channel="2",
pioreactor_unit=get_unit_name(),
calibrated_on_pioreactor_unit=get_unit_name(),
)

cal.set_as_active_calibration_for_device("od")
Expand Down Expand Up @@ -692,7 +692,7 @@ def test_calibration_simple_linear_calibration_negative_slope() -> None:
x="voltage",
y="od600s",
pd_channel="2",
pioreactor_unit=get_unit_name(),
calibrated_on_pioreactor_unit=get_unit_name(),
)

cal.set_as_active_calibration_for_device("od")
Expand Down Expand Up @@ -737,7 +737,7 @@ def test_calibration_simple_quadratic_calibration() -> None:
x="voltage",
y="od600s",
pd_channel="2",
pioreactor_unit=get_unit_name(),
calibrated_on_pioreactor_unit=get_unit_name(),
)

cal.set_as_active_calibration_for_device("od")
Expand Down Expand Up @@ -770,7 +770,7 @@ def test_calibration_multi_modal() -> None:
x="voltage",
y="od600s",
pd_channel="2",
pioreactor_unit=get_unit_name(),
calibrated_on_pioreactor_unit=get_unit_name(),
)

cal.set_as_active_calibration_for_device("od")
Expand Down Expand Up @@ -801,7 +801,7 @@ def test_calibration_errors_when_ir_led_differs() -> None:
x="voltage",
y="od600s",
pd_channel="2",
pioreactor_unit=get_unit_name(),
calibrated_on_pioreactor_unit=get_unit_name(),
)

cal.set_as_active_calibration_for_device("od")
Expand Down Expand Up @@ -846,7 +846,7 @@ def test_calibration_with_irl_data1() -> None:
x="voltage",
y="od600s",
pd_channel="2",
pioreactor_unit=get_unit_name(),
calibrated_on_pioreactor_unit=get_unit_name(),
)

cal.set_as_active_calibration_for_device("od")
Expand Down Expand Up @@ -929,7 +929,7 @@ def test_calibration_data_from_user1() -> None:
x="voltage",
y="od600s",
pd_channel="2",
pioreactor_unit=get_unit_name(),
calibrated_on_pioreactor_unit=get_unit_name(),
)

calibration.set_as_active_calibration_for_device("od")
Expand Down Expand Up @@ -971,7 +971,7 @@ def test_calibration_data_from_user2() -> None:
x="voltage",
y="od600s",
pd_channel="2",
pioreactor_unit=get_unit_name(),
calibrated_on_pioreactor_unit=get_unit_name(),
)

cal.set_as_active_calibration_for_device("od")
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def test_CachedCalibrationTransformer_with_real_calibration() -> None:
ir_led_intensity=50,
pd_channel="2",
created_at=current_utc_datetime(),
pioreactor_unit="pio1",
calibrated_on_pioreactor_unit="pio1",
recorded_data={
"x": [
1.359234153183015,
Expand Down
14 changes: 7 additions & 7 deletions pioreactor/tests/test_pumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def setup_function():
hz=100,
created_at=datetime(2010, 1, 1, tzinfo=timezone.utc),
voltage=-1.0,
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
)
cal.set_as_active_calibration_for_device("media_pump")
cal.set_as_active_calibration_for_device("alt_media_pump")
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_pump_can_be_interrupted() -> None:
hz=100,
created_at=datetime(2010, 1, 1, tzinfo=timezone.utc),
voltage=-1.0,
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
)

with PWMPump(unit=unit, experiment=experiment, pin=13, calibration=calibration) as p:
Expand Down Expand Up @@ -236,7 +236,7 @@ def test_pumps_can_run_in_background() -> None:
hz=100,
created_at=datetime(2010, 1, 1, tzinfo=timezone.utc),
voltage=-1.0,
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
)
with PWMPump(unit=unit, experiment=experiment, pin=13, calibration=calibration) as p:
with local_intermittent_storage("pwm_dc") as cache:
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_media_circulation_will_control_media_pump_if_it_has_a_higher_flow_rate(
hz=100,
created_at=datetime(2010, 1, 1, tzinfo=timezone.utc),
voltage=-1.0,
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
).set_as_active_calibration_for_device("media_pump")

structs.SimplePeristalticPumpCalibration(
Expand All @@ -310,7 +310,7 @@ def test_media_circulation_will_control_media_pump_if_it_has_a_higher_flow_rate(
hz=100,
created_at=datetime(2010, 1, 1, tzinfo=timezone.utc),
voltage=-1.0,
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
).set_as_active_calibration_for_device("waste_pump")

media_added, waste_removed = circulate_media(5.0, unit, exp)
Expand All @@ -329,7 +329,7 @@ def test_media_circulation_will_control_media_pump_if_it_has_a_lower_flow_rate()
hz=100,
created_at=datetime(2010, 1, 1, tzinfo=timezone.utc),
voltage=-1.0,
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
).set_as_active_calibration_for_device("media_pump")

structs.SimplePeristalticPumpCalibration(
Expand All @@ -341,7 +341,7 @@ def test_media_circulation_will_control_media_pump_if_it_has_a_lower_flow_rate()
hz=100,
created_at=datetime(2010, 1, 1, tzinfo=timezone.utc),
voltage=-1.0,
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
).set_as_active_calibration_for_device("waste_pump")

media_added, waste_removed = circulate_media(5.0, unit, exp)
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/tests/test_stirring.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def clean_up(self):
linear_term, constant_term = 10, -5
cal = SimpleStirringCalibration(
calibration_name="test_stirring_with_calibration",
pioreactor_unit=unit,
calibrated_on_pioreactor_unit=unit,
created_at=current_utc_datetime(),
curve_data_=[linear_term, constant_term],
curve_type="poly",
Expand Down
2 changes: 1 addition & 1 deletion update_scripts/upcoming/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ touch $DB
touch $DB-shm
touch $DB-wal

chown -R $USERNAME:www-data $DB*
chown -R $USERNAME:www-data $DB*

0 comments on commit 3f6df84

Please sign in to comment.