get_thresholds.py¶
Purpose: Scan threshold values and collect detection events at each step
Use case: Detector sensitivity analysis, determining optimal threshold settings
Features:
- Scans across a range of threshold values from center values
- Serial mode: scan each channel sequentially (default)
- Parallel mode: scan all channels simultaneously
- Generates one file per threshold-files combination with auto-generated names
- Writes a summary file (
thresholds_scanned.jsonl) for use withfit_thresholds.py
Scan range:
THRESHOLDS specifies the center value for each channel.
The script scans symmetrically around each center: center +/- nsteps × step_size.
For example, "1:300" with --nsteps 5 --step-size 2 scans channel 1 across [290, 292, 294, 296, 298, 300, 302, 304, 306, 308].
Scan modes:
| Mode | Behavior |
|---|---|
serial |
Scan CH1 → CH2 → CH3 sequentially (default) |
parallel |
Scan all channels at the same threshold simultaneously |
Usage:
# Serial scan: 10 steps, step size 1
uv run examples/get_thresholds.py "1:300;2:320;3:310" 100 1 --nsteps 10 --step-size 1
# Parallel scan: 5 steps, 3 files per threshold
uv run examples/get_thresholds.py "1:300;2:320;3:310" 100 3 --nsteps 5 --mode parallel
# Time-based (60 seconds per threshold)
uv run examples/get_thresholds.py "1:300;2:320;3:310" 60 2 --use-sec --nsteps 10
# With verbose logging redirected to a log file
uv run examples/get_thresholds.py "1:300;2:320;3:310" 100 1 --nsteps 10 --verbose 2> scan.log
# Test without hardware
uv run examples/get_thresholds.py "1:300;2:320;3:310" 100 1 --nsteps 5 --mock
CLI Options:
| Option | Default | Description |
|---|---|---|
THRESHOLDS |
(required) | Center threshold values as ch1:value;ch2:value;ch3:value |
EVENTS_OR_SECS |
(required) | Number of events (--use-event) or duration in seconds (--use-sec) |
FILES |
(required) | Number of files/measurements per threshold |
--nsteps / -ns |
50 |
Number of steps in scan range |
--step-size / -ss |
1 |
Size of each step |
--mode / -m |
serial |
Scan mode: serial or parallel |
--use-event / --use-sec |
--use-event |
Collect by event count or by duration |
--port / -p |
auto |
Serial port (auto for auto-detection) |
--timeout / -t |
0.1 |
Serial communication timeout in seconds |
--poll-count / -pc |
10 |
Events to poll per cycle (1–65535) |
--event-timeout / -et |
5.0 |
Timeout in seconds to wait for an event |
--overwrite |
off | Overwrite existing thresholds_scanned.jsonl |
--verbose / --quiet |
--quiet |
Show or suppress status messages |
--mock |
off | Use mock device for testing without hardware |
--log-level |
error |
Log level (debug, info, error) |