Skip to content

Commit

Permalink
types and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Jul 9, 2023
1 parent 70a24cf commit d2b29bb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
9 changes: 5 additions & 4 deletions pioreactor/actions/self_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from pioreactor.background_jobs import stirring
from pioreactor.background_jobs.od_reading import ADCReader
from pioreactor.background_jobs.od_reading import ALL_PD_CHANNELS
from pioreactor.background_jobs.od_reading import average_over_pd_channel_to_voltages
from pioreactor.background_jobs.od_reading import IR_keyword
from pioreactor.background_jobs.od_reading import REF_keyword
from pioreactor.background_jobs.od_reading import start_od_reading
Expand Down Expand Up @@ -153,13 +154,13 @@ def test_all_positive_correlations_between_pds_and_leds(
)

# record from ADC, we'll average them
readings1 = adc_reader.take_reading()
readings2 = adc_reader.take_reading()
avg_reading = average_over_pd_channel_to_voltages(
adc_reader.take_reading(), adc_reader.take_reading()
)

# Add to accumulating list
for pd_channel in ALL_PD_CHANNELS:
reading = 0.5 * (readings1[pd_channel] + readings2[pd_channel])
varying_intensity_results[pd_channel].append(reading)
varying_intensity_results[pd_channel].append(avg_reading[pd_channel])

# compute the linear correlation between the intensities and observed PD measurements
for pd_channel in ALL_PD_CHANNELS:
Expand Down
4 changes: 2 additions & 2 deletions pioreactor/automations/led/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def execute(self) -> Optional[events.AutomationEvent]:
def most_stale_time(self) -> datetime:
return min(self.latest_normalized_od_at, self.latest_growth_rate_at)

def set_led_intensity(self, channel: pt.LedChannel, intensity: float) -> bool:
def set_led_intensity(self, channel: pt.LedChannel, intensity: pt.LedIntensityValue) -> bool:
"""
This first checks the lock on the LED channel, and will wait a few seconds for it to clear,
and error out if it waits too long.
Expand Down Expand Up @@ -262,7 +262,7 @@ def on_disconnected(self) -> None:
self.run_thread.join()

led_intensity(
{channel: 0 for channel in self.edited_channels},
{channel: 0.0 for channel in self.edited_channels},
unit=self.unit,
experiment=self.experiment,
source_of_event=f"{self.job_name}:{self.automation_name}",
Expand Down
14 changes: 7 additions & 7 deletions pioreactor/background_jobs/od_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ def __init__(

# setup the ADC by turning off all LEDs.
with led_utils.change_leds_intensities_temporarily(
self.ir_led_on_and_rest_off_state,
{ch: 0.0 for ch in led_utils.ALL_LED_CHANNELS},
unit=self.unit,
experiment=self.experiment,
source_of_event=self.job_name,
Expand All @@ -834,19 +834,19 @@ def __init__(
):
with led_utils.lock_leds_temporarily(self.non_ir_led_channels):
# IR led is on
sleep(0.1)

self.start_ir_led()
sleep(0.10)
self.adc_reader.setup_adc() # determine best gain, max-signal, etc.

# IR led is off so we can set blanks
self.stop_ir_led()
sleep(0.15)
sleep(0.10)

blank_reading = average_over_pd_channel_to_voltages(
self.adc_reader.take_reading(),
avg_blank_reading = average_over_pd_channel_to_voltages(
self.adc_reader.take_reading(),
self.adc_reader.take_reading(),
)
self.adc_reader.set_offsets(blank_reading) # determine offset
self.adc_reader.set_offsets(avg_blank_reading) # set dark offset

# clear the history in adc_reader, so that we don't blank readings in later inference.
self.adc_reader.clear_batched_readings()
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def publish_to_pioreactor_cloud(
from pioreactor.utils.timing import current_utc_timestamp
from json import dumps

assert data_dict is not None and data_str is not None
assert (data_dict is not None) or (data_str is not None)

if is_testing_env():
return
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/tests/test_dosing_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def test_changing_morbidostat_parameters_over_mqtt() -> None:
)
pause()
assert algo.target_growth_rate == new_target
assert algo.pid.pid.setpoint == new_target
assert algo.pid.setpoint == new_target
algo.clean_up()


Expand Down
12 changes: 10 additions & 2 deletions pioreactor/tests/test_temperature_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ def test_heating_is_reduced_when_set_temp_is_exceeded() -> None:
with temperature_control.TemperatureController(
"only_record_temperature", unit=unit, experiment=experiment
) as t:
setattr(t.tmp_driver, "get_temperature", lambda *args: t.MAX_TEMP_TO_REDUCE_HEATING + 0.1)
setattr(
t.heating_pcb_tmp_driver,
"get_temperature",
lambda *args: t.MAX_TEMP_TO_REDUCE_HEATING + 0.1,
)
pause()
t._update_heater(50)
pause()
Expand Down Expand Up @@ -146,7 +150,11 @@ def test_heating_stops_when_max_temp_is_exceeded() -> None:
target_temperature=25,
) as t:
# monkey patch the driver
setattr(t.tmp_driver, "get_temperature", lambda *args: t.MAX_TEMP_TO_DISABLE_HEATING + 0.1)
setattr(
t.heating_pcb_tmp_driver,
"get_temperature",
lambda *args: t.MAX_TEMP_TO_DISABLE_HEATING + 0.1,
)
pause()
pause()
t._update_heater(50)
Expand Down

0 comments on commit d2b29bb

Please sign in to comment.