Callbacks¶
Callbacks run your code at defined points of a search, its hooks, e.g. to send an alert for every new detection during real-time monitoring. callbacks is a list of callbacks; Qseek calls each of them:
| Hook | When |
|---|---|
on_start |
the search starts |
on_batch_start, on_batch_end |
before and after each window of waveforms |
on_new_detection |
for every new detection, after its magnitudes and features |
on_stop |
the search ends |
Telegram alerts¶
Sends detection alerts to a Telegram chat. Set the bot token with the QSEEK_TELEGRAM_BOT_TOKEN environment variable: it is not stored in the run's search.json. Set the chat with chat_id in the configuration or with the QSEEK_TELEGRAM_CHAT_ID environment variable. The real-time monitoring guide shows the setup.
{
"callback": "TelegramAlert",
"magnitude_alert": 2.0,
"rate_alert_magnitude": 1.0,
"rate_alert_count": 10,
"rate_alert_window": "P1D"
}
TelegramAlert
pydantic-model
¶
Bases: Callback
Sends detection alerts to a Telegram chat.
bot_token is excluded from search.json so it never ends up on disk;
set it (and optionally chat_id) through the QSEEK_TELEGRAM_BOT_TOKEN /
QSEEK_TELEGRAM_CHAT_ID environment variables instead.
Fields:
-
callback(Literal['TelegramAlert']) -
bot_token(SecretStr) -
chat_id(str) -
magnitude_alert(float | None) -
rate_alert_magnitude(float) -
rate_alert_count(int) -
rate_alert_window(timedelta)
Validators:
-
_credentials_from_env
magnitude_alert
pydantic-field
¶
magnitude_alert: float | None = 2.0
Only notify for detections at or above this magnitude. Detections without a computed magnitude are not notified.
rate_alert_magnitude
pydantic-field
¶
rate_alert_magnitude: float = 1.0
Magnitude threshold considered for the rate alert.
rate_alert_count
pydantic-field
¶
rate_alert_count: int = 10
Number of events at or above rate_alert_magnitude within rate_alert_window that triggers a swarm alert.
rate_alert_window
pydantic-field
¶
Rolling time window for the rate alert.
on_batch_start
async
¶
Called before a waveform batch is processed.
on_batch_end
async
¶
Called after a waveform batch has been processed.
Custom callbacks¶
Write your own callback in a single Python file and list it in callback_scripts. The file subclasses Callback, implements the hooks it needs, and defines a top-level load() function that returns an instance.