Manual:Alarms and events
The The detector produces one engine score per analysis window, but you do not want an alert on every single noisy spike. A decision rule turns that stream of scores into alarms or events. Hydrofon currently has two layers: the live view still uses the simple legacy Alarm rule, while a newer event engine (app/events.py) is implemented and tested but not yet wired into the live GUI.
The legacy live alarm rule (Alarm)¶
In tab 1 · Listen & record, alarms are raised by the Alarm class in app/detector.py. Its three parameters live in Settings → Detector (defaults from app/settings.py):
| Setting | settings.json key |
Default | Meaning |
|---|---|---|---|
| Alarm threshold (0–1) | detector.threshold |
0.3 |
Minimum engine score for a window to count as positive. Drawn as the red dashed line on the score plot. |
| Windows in a row above threshold | detector.consecutive |
3 |
Number of consecutive positive windows needed before raising an alarm (minimum 1). Any window below threshold or a detector gap resets the counter. |
| Quiet time after alarm (s) | detector.cooldown_s |
10.0 |
Minimum seconds of stream time after an alarm before another alarm can fire. |
Starting a new audio source or saving settings resets the alarm state.
Events list, notifications and log files¶
When a live alarm triggers, the app does four things:
- Prepends a timestamped line (
HH:MM:SS <model> (score X.XX)) to the Events list on the right of tab 1. - Writes a
WARNINGline to the Log panel (anddata/logs/app.logif logging is enabled). - Shows a 5-second Windows tray notification titled
Engine detected?if Settings → Notifications → Enabled (notifications.enabled, default on) is checked. - Appends one JSON line to
data/logs/events.jsonlif Settings → Logging → Enabled and Log events (logging.log_events, default on) are checked.
Each line in data/logs/events.jsonl contains time (local ISO timestamp), stream_time_s, engine_score, model, source, recording (active WAV filename or null) and recording_time_s (seconds from recording start or null).
You can also enable Settings → Logging → Log every score (logging.log_scores, off by default because the file grows fast). When enabled, every window is appended to data/logs/scores.csv with columns time, stream_time_s, engine_score, model and top1.
Known limits of the legacy rule (audit finding F03)¶
The live view still uses the legacy Alarm rule
Although the new event engine (app/events.py) exists and passes its tests, it is not yet wired into the live view (app/ui.py). Live alarms, tray notifications and data/logs/events.jsonl still use the legacy Alarm class.
The code audit (finding F03, documented in docs/event_definition.md and reproduced in tests/test_events.py) confirmed two flaws in Alarm:
- Repeated alarms during one continuous engine run: as long as the score stays above threshold,
Alarmfires again everycooldown_sseconds. Sixty seconds of continuous high score at a 0.5 s step withcooldown_s = 10produces 6 alarms for a single passing boat. You can see this in the live screenshot on The detector (entries at12:57:45,12:57:55and12:58:05). - Time gaps are not checked by
Alarmitself:Alarm.update(t, score)counts calls without inspecting the gap between timestamps. Three positive windows at0,0.5and100seconds with nothing in between still satisfyconsecutive = 3and fire att = 100s. In the live UI,on_gapresetsalarm.run = 0when the detector explicitly reports a stream gap, which partially mitigates dropouts, but the rule itself lacks gap checking, hysteresis and event start/end tracking.
The new event engine (app/events.py)¶
The Qt-free module app/events.py (specified in docs/event_definition.md) fixes F03 by separating events (Event: a confirmed presence interval with onset_s, confirmed_s, offset_s, peak_score, left_censored and end_reason) from notifications (notify). One long engine pass is always one event, regardless of how many notifications are shown.
The hysteresis-event v1 rule (EventRule) supports these parameters:
| Parameter | Default | Meaning |
|---|---|---|
on_threshold |
required | Entry threshold: a positive window starts or extends the confirmation chain. |
off_threshold |
= on_threshold |
Release threshold while an event is active (<= on_threshold). Hysteresis keeps an active event alive without letting a sub-on_threshold score start a new one. |
confirm_windows |
1 |
Consecutive positive windows required to confirm onset. |
confirm_s |
0 |
Minimum audio span of the confirmation chain in seconds (t_end(last) - t_start(first)). |
release_s |
0 |
Seconds the score must remain below off_threshold before the event ends (released). Shorter dips merge into the same event. |
max_gap_s |
1.0 |
Maximum uncovered audio gap between windows before breaking the chain or ending an active event (gap). |
renotify_s |
None |
Optional repeat-notification interval during a long active event (None = one notification per event). |
notify |
True |
False suppresses notifications without changing the events themselves. |
smooth_windows |
1 |
Causal moving average over the last N valid windows (1 = no smoothing); cleared on any break. |
Missing scores (empty cell, NaN, Inf) are treated as missing windows rather than negative scores; backwards timestamps trigger an explicit time_backwards reset; events starting on the first window of a stream or right after a gap/reset are flagged left_censored = True (true onset unknown); and active events close with end_reason = "end_of_stream" at the end of a file. Default parameter values are unvalidated starting points—final thresholds and timings must be selected on development data and frozen before final testing (see The evaluation contract).
You can already test both rules offline using the replay command-line tool app.replay (see Command-line tools):
.venv\Scripts\python.exe -m app.replay SCORES.csv --rule event
.venv\Scripts\python.exe -m app.replay --wav FILE.wav --model wolfset-bands-v1 --rule legacy
See also¶
- The detector: the live detector and model scores
- Streams and windows: windows, sample timing and gap records
- The evaluation contract: how events are matched against ground truth
- Command-line tools: command-line tools, including
app.replay