Skip to content

Commit

Permalink
move this downstream
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jan 15, 2025
1 parent 2d4e807 commit cb989b2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
14 changes: 8 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
- An `Event Logs` page for seeing the logs generated by your Pioreactors
- A detailed overview of your cluster's leader-specific duties on the new `Leader`'s page.
- See the Leader's filesystem, logs, update cluster clocks, and view important running jobs.
- View different Pioreactors' plugins on the `Plugins` page, and install to specific Pioreactor vs entire cluster.
- Manage your calibrations from the UI's new `Calibrations` page.
- View existing calibrations, set active calibrations, and download calibration files.
- View different Pioreactors' plugins on the `Plugins` page, and install to specific Pioreactor vs entire cluster.
- Manage your calibrations from the UI's new `Calibrations` page.
- View existing calibrations, set active calibrations, and download calibration files.
- New calibrations API. A calibration now creates a YAML file as an artifact, stored in `~/.pioreactor/calibrations`. This makes editing, creating, sharing, and transferring calibrations much easier.
- There's also a new CLI for calibrations:
```
Expand All @@ -24,6 +24,7 @@
list List existing calibrations for the given device.
run Run an interactive calibration assistant for a specific device.
set-active Mark a specific calibration as 'active' for that device
analyze Analyze the data from a calibration.
```
For example, to run a pump calibration, use `pio calibrations run --device media_pump`. View all your media pump calibrations with: `pio calibrations list --device media_pump`. And to duplicate a
Expand Down Expand Up @@ -70,6 +71,7 @@
### Enhancements
- new SQL table for `historical_experiment_assignments` that stores historical assignments to experiments.
- UI performance improvements
- Better terminal plots
### Breaking changes
- `use_calibration` under `od_reading.config` is deprecated. Use the calibrations "active" state instead.
Expand Down Expand Up @@ -97,9 +99,9 @@
- removed `pioreactor.utils.gpio_helpers`

### Bug fixes
- fix PWM3 not cleaning up correctly
- fixed Stirring not updating to best DC % when using a calibration after changing target RPM

- Fix PWM3 not cleaning up correctly
- Fixed Stirring not updating to best DC % when using a calibration after changing target RPM
- Fixed a bug that could cause OD calibrations to map a small voltage value to a max OD.

### 24.12.10
- Hotfix for UI settings bug
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/background_jobs/od_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def hydate_models(self, calibration_data: structs.ODCalibration | None) -> None:
f"Using OD calibration `{name}` for channel {channel}, {calibration_data.curve_type=}, {calibration_data.curve_data_=}"
)

def _hydrate_model(self, calibration_data: structs.ODCalibration) -> Callable[[float], float]:
def _hydrate_model(self, calibration_data: structs.ODCalibration) -> Callable[[pt.Voltage], pt.OD]:
if calibration_data.curve_type == "poly":
"""
Finds the smallest root in the range [minOD, maxOD] calibrated against.
Expand Down
18 changes: 16 additions & 2 deletions pioreactor/calibrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def calculate_poly_curve_of_best_fit(x: list[float], y: list[float], degree: int
weights = np.ones_like(x)
weights[0] = n / 2

x, y = zip(*sorted(zip(x, y), key=lambda t: t[0]))
x, y = zip(*sorted(zip(x, y), key=lambda t: t[0])) # type: ignore

try:
coefs = np.polyfit(x, y, deg=degree, w=weights)
Expand Down Expand Up @@ -65,6 +65,17 @@ def curve_callable(x):
raise NotImplementedError()


def linspace(start: float, stop: float, num: int = 50):
num = int(num)
start = start * 1.0
stop = stop * 1.0

step = (stop - start) / (num - 1)

for i in range(num):
yield start + step * i


def plot_data(
x: list[float],
y: list[float],
Expand All @@ -81,7 +92,10 @@ def plot_data(
plt.clf()

if interpolation_curve:
plt.plot(sorted(x), [interpolation_curve(x_) for x_ in sorted(x)], color=204)
x_min, x_max = min(x) - 0.1, max(x) + 0.1
xs = list(linspace(x_min, x_max, num=100))
ys = [interpolation_curve(x_) for x_ in xs]
plt.plot(xs, ys, color=204)
plt.plot_size(145, 26)

plt.scatter(x, y, marker="hd")
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ def ipredict(self, y: Y, enforce_bounds=False) -> X:
from pioreactor.utils.math_helpers import closest_point_to_domain

poly = self.curve_data_
min_X, max_X = min(self.recorded_data["x"]), max(self.recorded_data["x"])

coef_shift = zeros_like(poly)
coef_shift[-1] = y
Expand All @@ -221,6 +220,7 @@ def ipredict(self, y: Y, enforce_bounds=False) -> X:
if not enforce_bounds:
return sol

min_X, max_X = min(self.recorded_data["x"]), max(self.recorded_data["x"])
# if we are here, we let the downstream user decide how to proceed
if min_X <= sol <= max_X:
return sol
Expand Down
1 change: 1 addition & 0 deletions pioreactor/tests/test_od_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_linear_data_produces_linear_curve_in_range_even_if_high_degree() -> Non


def test_mandys_data_for_pathological_poly() -> None:
# https://forum.pioreactor.com/t/very-low-od-readings-map-to-max/630/5
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 Down

0 comments on commit cb989b2

Please sign in to comment.