-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bound stream computed field with physical limits #82
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 12058948228Details
💛 - Coveralls |
seems fine to me, i guess my question is when does this occur? seems like if the device is giving us impossible values that's a problem with the device not the i/o software, and setting this to 0 could mask that problem. i trust ya but can i have it explained to me why it's preferable to have 0 in the recorded values rather than the value itself, which can be clamped in analysis? |
miniscope_io/models/stream.py
Outdated
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use -1 to make it unambiguous from the value actually being zero (which should never happen, but thinking about downstream data analysis)
Also I think we are getting to the point where we want to have a separate like T = TypeVar("T", bound = Union[int, float])
class ScaledValue(BaseModel, Generic[T]):
factor: T = 1
maximum: Optional[T] = None
minimum: Optional[T] = None
def scale(self, value: T) -> T:
return np.clip(value * factor, self.minimum, self.maximum) So then for example class StreamConfig(BaseModel):
battery_voltage: ScaledValue[float] = ScaledValue(factor = 10, maximum = 20)
vin_voltage: ScaledValue[float] = ScaledValue(factor=1000, maximum = 20) where idk we could compute that battery_voltage:
factor: 100
maximum: 10
# ... cfg = StreamConfig()
cfg.battery_voltage.scale(100) |
e6a24de
to
c713ac7
Compare
32927fc
to
42c564f
Compare
_adc_scale: ADCScaling = PrivateAttr() | ||
_battery_voltage_scaling: ScaledValue = PrivateAttr() | ||
_input_voltage_scaling: ScaledValue = PrivateAttr() | ||
|
||
def __init__(self, adc_scale: ADCScaling, **data: dict): | ||
super().__init__(**data) | ||
self._adc_scale = adc_scale | ||
self._battery_voltage_scaling = ScaledValue( | ||
scaling_factor=( | ||
1 | ||
/ (2**self._adc_scale.bitdepth) | ||
* self._adc_scale.ref_voltage | ||
* self._adc_scale.battery_div_factor | ||
), | ||
maximum=self._adc_scale.battery_max_voltage, | ||
) | ||
self._input_voltage_scaling = ScaledValue( | ||
scaling_factor=( | ||
1 | ||
/ (2**self._adc_scale.bitdepth) | ||
* self._adc_scale.ref_voltage | ||
* self._adc_scale.vin_div_factor | ||
), | ||
maximum=self._adc_scale.vin_max_voltage, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Notes for whenever I can come back] Not done yet. Doing this for every header input feels like a waste and also makes the header-filling process inconsistent. So, it is probably better to define a helper class that is set once with the device config and converts StreamBufferHeader into scaled values.
This mostly happens when the channel or DAQ hardware introduces some bit errors. We're using uint32 to send 8-bit ADC values to simplify the buffer structure, so any flip in the higher bits messes up the metadata plot. I'll change the mask value to |
zero-1
if it exceeds the limits.📚 Documentation preview 📚: https://miniscope-io--82.org.readthedocs.build/en/82/