Skip to content

Commit ac0d5d9

Browse files
committed
Get buffer size from device config
1 parent 91967d4 commit ac0d5d9

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

mio/data/config/process/denoise_example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ noise_patch:
55
enable: true
66
method: gradient # gradient or mean_error
77
threshold: 20
8-
buffer_size: 5032 # Better to get this from device configuration
8+
device_config_id: wireless-200px
99
buffer_split: 8
1010
diff_multiply: 1
1111
output_result: true

mio/models/process.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from mio.models import MiniscopeConfig
1010
from mio.models.mixins import ConfigYAMLMixin
11+
from mio.models.stream import StreamDevConfig
1112

1213

1314
class InteractiveDisplayConfig(BaseModel):
@@ -69,10 +70,9 @@ class NoisePatchConfig(BaseModel):
6970
default=20,
7071
description="Threshold for detecting noise.",
7172
)
72-
buffer_size: int = Field(
73-
default=5032,
74-
description="Size of the buffers composing the image."
75-
"This premises that the noisy area will appear in units of buffer_size.",
73+
device_config_id: Optional[str] = Field(
74+
default=None,
75+
description="ID of the stream device configuration.",
7676
)
7777
buffer_split: int = Field(
7878
default=1,
@@ -99,6 +99,17 @@ class NoisePatchConfig(BaseModel):
9999
description="Whether to output the noisy frames as an independent video stream.",
100100
)
101101

102+
_device_config: Optional[StreamDevConfig] = None
103+
104+
@property
105+
def device_config(self) -> StreamDevConfig:
106+
"""
107+
Get the stream device configuration.
108+
"""
109+
if self._device_config is None:
110+
self._device_config = StreamDevConfig.from_any(self.device_config_id)
111+
return self._device_config
112+
102113

103114
class FreqencyMaskingConfig(BaseModel):
104115
"""

mio/models/stream.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ class StreamDevConfig(MiniscopeConfig, ConfigYAMLMixin):
267267
adc_scale: Optional[ADCScaling] = ADCScaling()
268268
runtime: StreamDevRuntime = StreamDevRuntime()
269269

270+
_px_per_buffer: int = None
271+
270272
@field_validator("preamble", mode="before")
271273
def preamble_to_bytes(cls, value: Union[str, bytes, int]) -> bytes:
272274
"""
@@ -304,3 +306,18 @@ def ensure_exists(cls, value: Optional[Path]) -> Optional[Path]:
304306
value.exists()
305307
), f"Configured to use bitstream file {value}, but it does not exist"
306308
return value
309+
310+
@property
311+
def px_per_buffer(self) -> int:
312+
"""
313+
Number of pixels per buffer
314+
"""
315+
316+
px_per_word = 32 / self.pix_depth
317+
if self._px_per_buffer is None:
318+
self._px_per_buffer = (
319+
self.buffer_block_length * self.block_size * px_per_word
320+
- self.header_len / self.pix_depth
321+
- px_per_word * self.dummy_words
322+
)
323+
return self._px_per_buffer

mio/process/frame_helper.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ def detect_frame_with_noisy_buffer(
4747
Tuple[bool, np.ndarray]: A boolean indicating if the frame is noisy,
4848
and a spatial mask showing noisy regions.
4949
"""
50-
logger.debug(f"Buffer size: {config.buffer_size}")
50+
if config.device_config is not None:
51+
px_per_buffer = config.device_config.px_per_buffer
52+
else:
53+
px_per_buffer = 1000
54+
logger.warning(
55+
f"Device configuration not found. Using default buffer size: {px_per_buffer}"
56+
)
57+
logger.debug(f"Buffer size: {px_per_buffer}")
5158

5259
frame_width = current_frame.shape[1]
5360
frame_height = current_frame.shape[0]
@@ -63,7 +70,7 @@ def detect_frame_with_noisy_buffer(
6370
serialized_previous = previous_frame.flatten().astype(np.int16)
6471
logger.debug(f"Serialized previous frame size: {len(serialized_previous)}")
6572

66-
split_size = config.buffer_size // config.buffer_split + 1
73+
split_size = px_per_buffer // config.buffer_split + 1
6774

6875
split_shape = []
6976

0 commit comments

Comments
 (0)