Set Thresholds¶
The threshold command configures detection sensitivity for one or more detector channels. Each channel can have an independent threshold value.
Purpose of Threshold Configuration¶
Setting appropriate thresholds is critical for effective cosmic ray detection:
- Too high: Misses low-energy events, reducing detection efficiency
- Too low: Triggers excessive noise, depleting the event queue
- Balanced: Optimizes signal-to-noise ratio for your measurement
Basic Threshold Setting¶
Set thresholds for all three channels at once:
$ uv run kazunoko threshold "1:300;2:320;3:350"
{"type": "response", "status": "ok", "received_us": 1765550821.4822762, "sent_us": 1765550820582317, "channel": 1, "threshold": 300}
{"type": "response", "status": "ok", "received_us": 1765550821.626923, "sent_us": 1765550820728571, "channel": 2, "threshold": 320}
{"type": "response", "status": "ok", "received_us": 1765550821.83224, "sent_us": 1765550820932266, "channel": 3, "threshold": 350}
Set Thresholds for Specific Channels¶
You can set thresholds for arbitrary channels (not all three):
$ uv run kazunoko threshold "1:300;3:350"
{"type": "response", "status": "ok", "received_us": 1765550860.719664, "sent_us": 1765550859819251, "channel": 1, "threshold": 300}
{"type": "response", "status": "ok", "received_us": 1765550860.84657, "sent_us": 1765550859946255, "channel": 3, "threshold": 350}
Use Case: Threshold Optimization¶
A practical workflow for optimizing thresholds over time:
Shell Script Example¶
# optimize_thresholds.sh - Test different threshold configurations
configs=(
"1:300;2:320;3:350"
"1:300;2:360;3:330"
"1:320;2:360;3:330"
)
for config in "${configs[@]}"; do
echo "=== Measuring with thresholds: $config ==="
uv run kazunoko measure "$config" 60 --use-sec >> measurements.jsonl
echo ""
done
Python Script Example¶
#!/usr/bin/env python3
"""
optimize_thresholds.py - Test different threshold configurations
"""
from pathlib import Path
from kazunoko import connect, Measure, MeasureConfig, ResponseView
def main(duration: float = 60.0):
"""Test different threshold configurations."""
output_path = Path("measurements.jsonl")
# Different threshold configurations to test
thresholds = [
{1: 300, 2: 320, 3: 350},
{1: 300, 2: 360, 3: 330},
{1: 320, 2: 360, 3: 330},
]
with connect() as device:
for idx, config in enumerate(thresholds):
print(f"=== Config {idx}: {config} ===")
print(f"Recording events for {duration} seconds...")
measure = Measure(device, MeasureConfig(thresholds=config))
measure.setup()
count = 0
with output_path.open("a") as f:
for event in measure.stream_by_time(duration):
f.write(ResponseView(event).flat.model_dump_json() + "\n")
count += 1
if count % 100 == 0:
print(f" {count} events recorded")
print(f" Total: {count} events recorded\n")
if __name__ == "__main__":
main()
This pattern provides:
- Unified measurements: Each event includes threshold configuration and device metadata
- Comparable data: Analyze events across different threshold configurations
- Reproducibility: Full configuration and event history in a single file