Skip to content

Commit

Permalink
Merge branch 'bound-computed-field' into experiment-202411
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sasatani committed Nov 27, 2024
2 parents 8cf6426 + e6a24de commit 91a3a86
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions miniscope_io/data/config/WLMS_v02_200px.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ adc_scale:
bitdepth: 8
battery_div_factor: 5
vin_div_factor: 11.3
battery_max_voltage: 10.0
vin_max_voltage: 20.0

runtime:
serial_buffer_queue_size: 10
Expand Down
16 changes: 14 additions & 2 deletions miniscope_io/models/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ class ADCScaling(MiniscopeConfig):
11.3,
description="Voltage divider factor for the Vin voltage",
)
battery_max_voltage: float = Field(
10.0,
description="Maximum voltage of the battery."
"Scaled battery voltage will be 0 if it is greater than this value",
)
vin_max_voltage: float = Field(
20.0,
description="Maximum voltage of the Vin"
"Scaled Vin voltage will be 0 if it is greater than this value",
)

def scale_battery_voltage(self, voltage_raw: float) -> float:
"""
Expand Down Expand Up @@ -113,7 +123,8 @@ def battery_voltage(self) -> float:
if self._adc_scaling is None:
return self.battery_voltage_raw
else:
return self._adc_scaling.scale_battery_voltage(self.battery_voltage_raw)
battery_voltage = self._adc_scaling.scale_battery_voltage(self.battery_voltage_raw)
return battery_voltage if battery_voltage < self._adc_scaling.battery_max_voltage else 0

@computed_field
def input_voltage(self) -> float:
Expand All @@ -123,7 +134,8 @@ def input_voltage(self) -> float:
if self._adc_scaling is None:
return self.input_voltage_raw
else:
return self._adc_scaling.scale_input_voltage(self.input_voltage_raw)
vin_voltage = self._adc_scaling.scale_input_voltage(self.input_voltage_raw)
return vin_voltage if vin_voltage < self._adc_scaling.vin_max_voltage else 0


class StreamDevRuntime(MiniscopeConfig):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models/test_model_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def test_adc_scaling(scale, config_override):
example = config_override(CONFIG_DIR / "stream_daq_test_200px.yml", {"adc_scale": adc_scale})
instance_config = StreamDevConfig.from_yaml(example)

battery_voltage_raw = 200
input_voltage_raw = 250
battery_voltage_raw = 100
input_voltage_raw = 150

instance_header = StreamBufferHeader(
linked_list=0,
Expand Down

0 comments on commit 91a3a86

Please sign in to comment.