From 3f6df844b129ea4833f38c2b80235206e5a85200 Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Mon, 6 Jan 2025 13:48:58 -0500 Subject: [PATCH] more calibration stuff --- pioreactor/actions/pump.py | 2 +- pioreactor/calibrations/od_calibration.py | 2 +- pioreactor/calibrations/pump_calibration.py | 6 +++--- .../calibrations/stirring_calibration.py | 2 +- pioreactor/cli/calibrations.py | 5 +++++ pioreactor/structs.py | 2 +- pioreactor/tests/test_calibrations.py | 2 +- pioreactor/tests/test_dosing_automation.py | 2 +- pioreactor/tests/test_mqtt_to_db_streaming.py | 2 +- pioreactor/tests/test_od_reading.py | 18 +++++++++--------- pioreactor/tests/test_pumps.py | 14 +++++++------- pioreactor/tests/test_stirring.py | 2 +- update_scripts/upcoming/update.sh | 2 +- 13 files changed, 33 insertions(+), 28 deletions(-) diff --git a/pioreactor/actions/pump.py b/pioreactor/actions/pump.py index 050cc38b..a5245c8d 100644 --- a/pioreactor/actions/pump.py +++ b/pioreactor/actions/pump.py @@ -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, diff --git a/pioreactor/calibrations/od_calibration.py b/pioreactor/calibrations/od_calibration.py index 361f4250..521b659f 100644 --- a/pioreactor/calibrations/od_calibration.py +++ b/pioreactor/calibrations/od_calibration.py @@ -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), diff --git a/pioreactor/calibrations/pump_calibration.py b/pioreactor/calibrations/pump_calibration.py index 76f1442c..3595e9d8 100644 --- a/pioreactor/calibrations/pump_calibration.py +++ b/pioreactor/calibrations/pump_calibration.py @@ -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": []}, ), ) @@ -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": []}, ) @@ -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_], diff --git a/pioreactor/calibrations/stirring_calibration.py b/pioreactor/calibrations/stirring_calibration.py index bbaa43b6..1bff9ffb 100644 --- a/pioreactor/calibrations/stirring_calibration.py +++ b/pioreactor/calibrations/stirring_calibration.py @@ -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", diff --git a/pioreactor/cli/calibrations.py b/pioreactor/cli/calibrations.py index 510bc1a1..8016ca5c 100644 --- a/pioreactor/cli/calibrations.py +++ b/pioreactor/cli/calibrations.py @@ -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} ✅" diff --git a/pioreactor/structs.py b/pioreactor/structs.py index cf5a77ad..bfafe846 100644 --- a/pioreactor/structs.py +++ b/pioreactor/structs.py @@ -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" diff --git a/pioreactor/tests/test_calibrations.py b/pioreactor/tests/test_calibrations.py index b017b4e2..ae3bdcf3 100644 --- a/pioreactor/tests/test_calibrations.py +++ b/pioreactor/tests/test_calibrations.py @@ -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", diff --git a/pioreactor/tests/test_dosing_automation.py b/pioreactor/tests/test_dosing_automation.py index c8d09f30..5b7211f0 100644 --- a/pioreactor/tests/test_dosing_automation.py +++ b/pioreactor/tests/test_dosing_automation.py @@ -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") diff --git a/pioreactor/tests/test_mqtt_to_db_streaming.py b/pioreactor/tests/test_mqtt_to_db_streaming.py index 785b0221..919b9c50 100644 --- a/pioreactor/tests/test_mqtt_to_db_streaming.py +++ b/pioreactor/tests/test_mqtt_to_db_streaming.py @@ -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, ), ) diff --git a/pioreactor/tests/test_od_reading.py b/pioreactor/tests/test_od_reading.py index 302ae04a..9f70fc76 100644 --- a/pioreactor/tests/test_od_reading.py +++ b/pioreactor/tests/test_od_reading.py @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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, diff --git a/pioreactor/tests/test_pumps.py b/pioreactor/tests/test_pumps.py index 5caf03dd..8e39e351 100644 --- a/pioreactor/tests/test_pumps.py +++ b/pioreactor/tests/test_pumps.py @@ -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") @@ -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: @@ -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: @@ -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( @@ -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) @@ -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( @@ -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) diff --git a/pioreactor/tests/test_stirring.py b/pioreactor/tests/test_stirring.py index b59f4a6d..ee70ea90 100644 --- a/pioreactor/tests/test_stirring.py +++ b/pioreactor/tests/test_stirring.py @@ -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", diff --git a/update_scripts/upcoming/update.sh b/update_scripts/upcoming/update.sh index d6296765..2aeccd32 100644 --- a/update_scripts/upcoming/update.sh +++ b/update_scripts/upcoming/update.sh @@ -16,4 +16,4 @@ touch $DB touch $DB-shm touch $DB-wal -chown -R $USERNAME:www-data $DB* \ No newline at end of file +chown -R $USERNAME:www-data $DB*