Skip to content

Commit

Permalink
improve self test for ref position
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jul 8, 2023
1 parent 9293288 commit 6b39cf0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
18 changes: 14 additions & 4 deletions pioreactor/actions/self_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def test_pioreactor_HAT_present(client: Client, logger: Logger, unit: str, exper
def test_REF_is_in_correct_position(
client: Client, logger: Logger, unit: str, experiment: str
) -> None:
# this _also_ uses stirring to increase the variance in the non-REF, so...
# this _also_ uses stirring to increase the variance in the non-REF.
# The idea is to trigger stirring on and off and the REF should not see a change in signal / variance, but the other PD should.
from statistics import variance

reference_channel = cast(PdChannel, config["od_config.photodiode_channel_reverse"][REF_keyword])
Expand All @@ -66,8 +67,8 @@ def test_REF_is_in_correct_position(
signal2 = []

with stirring.start_stirring(
target_rpm=450, unit=unit, experiment=experiment
), start_od_reading(
target_rpm=900, unit=unit, experiment=experiment
) as st, start_od_reading(
od_angle_channel1="90",
od_angle_channel2="90",
interval=1.15,
Expand All @@ -76,10 +77,17 @@ def test_REF_is_in_correct_position(
experiment=experiment,
use_calibration=False,
) as od_stream:
for i, reading in enumerate(od_stream):
st.block_until_rpm_is_close_to_target(abs_tolerance=100)

for i, reading in enumerate(od_stream, start=1):
signal1.append(reading.ods["1"].od)
signal2.append(reading.ods["2"].od)

if i % 5 == 0 and i % 2 == 0:
st.set_state("ready")
elif i % 5 == 0:
st.set_state("sleeping")

if i == 25:
break

Expand All @@ -88,6 +96,8 @@ def test_REF_is_in_correct_position(
"2": variance(signal2) / trimmed_mean(signal2) ** 2,
}

print(norm_variance_per_channel)

THRESHOLD = 1.0
if reference_channel == "1":
assert (
Expand Down
1 change: 0 additions & 1 deletion pioreactor/automations/temperature/thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __init__(self, target_temperature: float | str, **kwargs) -> None:
job_name=self.job_name,
target_name="temperature",
output_limits=(-25, 25), # avoid whiplashing
derivative_smoothing=0.90,
)

def execute(self) -> UpdatedHeaterDC:
Expand Down
6 changes: 3 additions & 3 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def rpi_is_having_power_problems(self) -> tuple[bool, float]:

def check_for_power_problems(self) -> None:
is_rpi_having_power_probems, voltage = self.rpi_is_having_power_problems()
self.logger.debug(f"PWM power supply at ~{voltage:.1f}V.")
self.logger.debug(f"PWM power supply at ~{voltage:.2f}V.")
self.voltage_on_pwm_rail = Voltage(
voltage=round(voltage, 2), timestamp=current_utc_datetime()
)
Expand All @@ -455,7 +455,7 @@ def check_and_publish_self_statistics(self) -> None:
cpu_usage_percent = round(
(psutil.cpu_percent() + psutil.cpu_percent() + psutil.cpu_percent()) / 3
) # this is a noisy process, and we average it over a small window.
if cpu_usage_percent <= 75:
if cpu_usage_percent <= 85:
self.logger.debug(f"CPU usage at {cpu_usage_percent}%.")
else:
# TODO: add documentation
Expand All @@ -464,7 +464,7 @@ def check_and_publish_self_statistics(self) -> None:
memory_usage_percent = 100 - round(
100 * psutil.virtual_memory().available / psutil.virtual_memory().total
)
if memory_usage_percent <= 60:
if memory_usage_percent <= 75:
self.logger.debug(f"Memory usage at {memory_usage_percent}%.")
else:
# TODO: add documentation
Expand Down
1 change: 1 addition & 0 deletions pioreactor/background_jobs/temperature_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def infer_temperature(self) -> None:
except exc.HardwareNotFoundError as e:
self.logger.debug(e, exc_info=True)
self.logger.error(e)
raise e
finally:
# we turned off the heater above - we should always turn if back on if there is an error.

Expand Down
5 changes: 4 additions & 1 deletion pioreactor/utils/streaming_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ def __init__(
self.output_limits = output_limits

# Smoothing factor for derivative term
assert 0.0 <= derivative_smoothing <= 1.0
self.derivative_smoothing = derivative_smoothing

# State variables
Expand All @@ -411,7 +412,9 @@ def __init__(
self.experiment = experiment
self.target_name = target_name
self.job_name = job_name
self.client = create_client(client_id=f"pid-{self.unit}-{self.experiment}")
self.client = create_client(
client_id=f"pid-{self.unit}-{self.experiment}-{self.target_name}"
)

def reset(self) -> None:
"""
Expand Down

0 comments on commit 6b39cf0

Please sign in to comment.