Skip to content

Commit 24ff34f

Browse files
move to curve data structs, and remove curve_type
1 parent 8a2b98e commit 24ff34f

28 files changed

+366
-722
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- You can now restart the web server (lighttpd), and the background task queue, Huey, from the UI. Go to Leader -> "Long-running jobs", and see the "web server and queue" line.
2424
- Added spline curve support for calibrations, including OD standards sessions and calibration charts.
2525
- `pio calibrations analyze` now supports `--fit poly|spline` (default poly). You can use this to re-fit a dataset to a spline curve.
26+
- Added an update helper to migrate calibration curve data into the new tagged format (`poly`/`spline`).
2627

2728
#### Breaking changes
2829
- Moved Self-test to the Inventory page. Pioreactors no longer need to be assigned to an experiment to run self-test.
@@ -34,6 +35,8 @@
3435
- Self-test no longer creates a stirring calibration.
3536
- OD Reading charts in the UI previously had a sensor label next to the unit, ex: `worker01-2`. Now it is the corresponding angle from config.ini. Note: only the global config.ini is used, not specific unit_config.inis.
3637
- New OD and stirring calibrations are now fit with a spline, and not a polynomial.
38+
- Calibration curve data is now serialized as tagged structs (`poly`/`spline`) instead of raw lists. `curve_type` is removed in fao existing calibration files are migrated during the update.
39+
3740

3841
#### Bug fixes
3942

core/pioreactor/actions/pump.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def get_default_calibration() -> structs.SimplePeristalticPumpCalibration:
3939
hz=250.0,
4040
dc=100.00,
4141
voltage=-1,
42-
curve_type="poly",
43-
curve_data_=[0.0911, 0.0] if not is_testing_env() else [5.0, 0], # go fast if in testing
42+
curve_data_=structs.PolyFitCoefficients(
43+
coefficients=[0.0911, 0.0] if not is_testing_env() else [5.0, 0]
44+
), # go fast if in testing
4445
recorded_data={"x": [], "y": []},
4546
)
4647

core/pioreactor/background_jobs/od_reading.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ def hydate_models(self, calibration_data: structs.ODCalibration | None) -> None:
793793
self.models[channel], self.verifiers[channel] = self._hydrate_model(calibration_data)
794794
self.models[channel].calibration_name = calibration_name # type: ignore
795795
self.logger.debug(
796-
f"Using OD calibration `{calibration_name}` of type `{cal_type}` for PD channel {channel}, {calibration_data.curve_type=}, {calibration_data.curve_data_=}"
796+
f"Using OD calibration `{calibration_name}` of type `{cal_type}` for PD channel {channel}, {calibration_data.curve_data_=}"
797797
)
798798

799799
def _hydrate_model(
@@ -805,11 +805,13 @@ def _hydrate_model(
805805
self.logger.error(f"Calibration {calibration_data.calibration_name} has wrong type.")
806806
raise exc.CalibrationError(f"Calibration {calibration_data.calibration_name} has wrong type.")
807807

808-
higher_order_terms = calibration_data.curve_data_[:-1]
809-
if len(higher_order_terms) == 0 or all(c == 0.0 for c in higher_order_terms):
810-
self.logger.warning(
811-
"Calibration curve is y(x)=constant. This is probably wrong. Check the calibration YAML file's curve_data_."
812-
)
808+
if calibration_data.curve_data_.type == "poly":
809+
coefficients = calibration_data.curve_data_.coefficients
810+
higher_order_terms = coefficients[:-1]
811+
if len(higher_order_terms) == 0 or all(c == 0.0 for c in higher_order_terms):
812+
self.logger.warning(
813+
"Calibration curve is y(x)=constant. This is probably wrong. Check the calibration YAML file's curve_data_."
814+
)
813815

814816
def _verify(od_reading: structs.ODReading) -> bool:
815817
"""

core/pioreactor/calibrations/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def list_devices() -> list[str]:
8787
from pioreactor.calibrations.protocols.od_reference_standard import (
8888
ODReferenceStandardProtocol,
8989
) # noqa: F401,E402
90-
from pioreactor.calibrations.protocols.od_single_vial import SingleVialODProtocol # noqa: F401,E402
9190
from pioreactor.calibrations.protocols.od_standards import StandardsODProtocol # noqa: F401,E402
9291
from pioreactor.calibrations.protocols.pump_duration_based import DurationBasedPumpProtocol # noqa: F401,E402
9392
from pioreactor.calibrations.protocols.stirring_dc_based import DCBasedStirringProtocol # noqa: F401,E402

core/pioreactor/calibrations/protocols/od_reference_standard.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ def advance(self, ctx: SessionContext) -> SessionStep | None:
195195
calibration_name=f"od{angle}-optics-calibration-jig-{timestamp}",
196196
angle=angle,
197197
curve_data_=curve_data_,
198-
curve_type="poly",
199198
recorded_data={"x": recorded_ods, "y": recorded_voltages},
200199
ir_led_intensity=ir_led_intensity,
201200
pd_channel=pd_channel,
@@ -219,7 +218,6 @@ def advance(self, ctx: SessionContext) -> SessionStep | None:
219218
calibration_name=f"od{angle}-optical-reference-standard-{timestamp}",
220219
angle=angle,
221220
curve_data_=curve_data_,
222-
curve_type="poly",
223221
recorded_data={"x": recorded_ods, "y": recorded_voltages},
224222
ir_led_intensity=ir_led_intensity,
225223
pd_channel=pd_channel,

0 commit comments

Comments
 (0)