Skip to content

Commit 7cfe154

Browse files
bump adafruit libs, new kalman filter
1 parent 93a37ba commit 7cfe154

File tree

10 files changed

+36
-21
lines changed

10 files changed

+36
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
### Upcoming
22

33
- adding dirs to exported data zips
4+
- new kalman filter
5+
- new system logs
6+
- fixed stirrer not spinning on Pioreactor page (UI)
47

58
### 25.5.1
69

pioreactor/background_jobs/growth_rate_calculating.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ def get_precomputed_values(
299299

300300
od_blank = self.get_od_blank_from_cache()
301301

302+
# check that od_variances is not zero:
303+
# this means that the sensor is not working properly.
304+
if any(v == 0.0 for v in od_variances.values()):
305+
raise ValueError(
306+
"OD variance is zero - this means that the sensor is not working properly. Please check the sensor."
307+
)
308+
302309
# what happens if od_blank is near / less than od_normalization_factors?
303310
# this means that the inoculant had near 0 impact on the turbidity => very dilute.
304311
# I think we should not use od_blank if so

pioreactor/background_jobs/leader/mqtt_to_db_streaming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def callback(message: pt.MQTTMessage) -> None:
120120
except Exception as e:
121121
self.logger.warning(f"Encountered error in saving to DB: {e}. See logs.")
122122
self.logger.debug(
123-
f"Error in {parser.__name__}. Payload that caused error: `{message.payload.decode()}`. Topic: `{message.topic}`",
123+
f"Error in {parser.__name__}. Payload: `{message.payload.decode()}`. Topic: `{message.topic}`",
124124
exc_info=True,
125125
)
126126
return

pioreactor/background_jobs/od_reading.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,19 +1317,18 @@ def click_od_reading(
13171317
"""
13181318

13191319
if snapshot:
1320-
od = start_od_reading(
1320+
with start_od_reading(
13211321
od_angle_channel1,
13221322
od_angle_channel2,
13231323
fake_data=fake_data or whoami.is_testing_env(),
13241324
interval=None,
1325-
)
1326-
od.logger.debug(od.record_from_adc())
1327-
# end early
1328-
return
1325+
) as od:
1326+
od.logger.debug(od.record_from_adc())
1327+
# end early
13291328
else:
1330-
od = start_od_reading(
1329+
with start_od_reading(
13311330
od_angle_channel1,
13321331
od_angle_channel2,
13331332
fake_data=fake_data or whoami.is_testing_env(),
1334-
)
1335-
od.block_until_disconnected()
1333+
) as od:
1334+
od.block_until_disconnected()

pioreactor/background_jobs/stirring.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,6 @@ def click_stirring(target_rpm: float, use_rpm: bool) -> None:
596596
"""
597597
Start the stirring of the Pioreactor.
598598
"""
599-
st = start_stirring(target_rpm=target_rpm, use_rpm=use_rpm)
600-
st.block_until_rpm_is_close_to_target()
601-
st.block_until_disconnected()
599+
with start_stirring(target_rpm=target_rpm, use_rpm=use_rpm) as st:
600+
st.block_until_rpm_is_close_to_target()
601+
st.block_until_disconnected()

pioreactor/background_jobs/temperature_automation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def start_temperature_automation(
597597
)
598598

599599
except Exception as e:
600-
logger = create_logger("temperature_automation")
600+
logger = create_logger("temperature_automation", experiment=experiment)
601601
logger.error(e)
602602
logger.debug(e, exc_info=True)
603603
raise e

pioreactor/cluster_management/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def get_active_workers_in_experiment(experiment: str) -> tuple[str, ...]:
4444
@click.command(name="add", short_help="add a pioreactor worker")
4545
@click.argument("hostname")
4646
@click.option("--password", "-p", default="raspberry")
47-
@click.option("--model-version", "-v", required=True, type=click.STRING)
4847
@click.option("--model-name", "-m", type=click.Choice(["pioreactor_20ml", "pioreactor_40ml"]), required=True)
48+
@click.option("--model-version", "-v", required=True, type=click.Choice(["1.0", "1.1"]))
4949
@click.option("--address", "-a")
5050
def add_worker(
51-
hostname: str, password: str, model_version: str, model_name: str, address: str | None
51+
hostname: str, password: str, model_name: str, model_version: str, address: str | None
5252
) -> None:
5353
"""
5454
Add a new pioreactor worker to the cluster. The pioreactor should already have the worker image installed and is turned on.

pioreactor/hardware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545

4646
if rpi_version_info.startswith("Raspberry Pi 5"):
4747
GPIOCHIP = 4
48-
SDA = (4, 2)
49-
SCL = (4, 3)
48+
SDA = 2
49+
SCL = 3
5050
else:
5151
GPIOCHIP = 0
5252
SDA = 2

pioreactor/utils/streaming_calculations.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,14 @@ def update(self, observation_: list[float], dt: float, recent_dilution=False):
274274
kalman_gain_[1:, 0] = 0
275275

276276
### update estimates
277-
self.state_ = state_prediction + kalman_gain_ @ residual_state
278-
self.covariance_ = (np.eye(self.n_states) - kalman_gain_ @ H) @ covariance_prediction
277+
state_ = state_prediction + kalman_gain_ @ residual_state
278+
covariance_ = (np.eye(self.n_states) - kalman_gain_ @ H) @ covariance_prediction
279+
280+
if np.isnan(state_).any():
281+
raise ValueError("NaNs detected after calculation.")
282+
283+
self.state_ = state_
284+
self.covariance_ = covariance_
279285

280286
return self.state_, self.covariance_
281287

requirements/requirements_worker.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
-r requirements.txt
2-
Adafruit-Blinka==8.43.0
2+
Adafruit-Blinka==8.57.0
33
adafruit-circuitpython-ads1x15==2.2.23
44
adafruit-circuitpython-busdevice==5.2.9
55
adafruit-circuitpython-connectionmanager==3.1.1
66
adafruit-circuitpython-requests==4.1.3
77
adafruit-circuitpython-typing==1.10.3
8-
Adafruit-PlatformDetect==3.71.0
8+
Adafruit-PlatformDetect==3.78.0
99
Adafruit-PureIO==1.1.11
1010
DAC43608==0.2.7
1111
plotext==5.2.8

0 commit comments

Comments
 (0)