Image functions¶
The image function turns the waveforms of each station into images of the P and S phase arrivals. Qseek stacks these images along the travel times to detect and locate earthquakes, see How Qseek works. After a detection, the picker of the image function picks the phase arrivals around their modeled arrival times.
| Image function | Image | Use for |
|---|---|---|
SeisBench |
Phase arrival probability of a machine learning picker | Most data sets. The default. |
StaLta |
Logarithm of the STA/LTA ratio | Data where no pre-trained model fits, or without a GPU. |
The phase_map assigns the P and S images to the phase descriptions of the ray tracers, e.g. {"P": "cake:P", "S": "cake:S"}. With weights, one phase can contribute more to the stack than the other.
SeisBench¶
SeisBench provides machine learning phase pickers, pre-trained on different data sets. The image is the probability of a P or S phase arrival.
- Model: PhaseNet is a good start. EQTransformer, OBSTransformer (ocean bottom seismometers) and LFEDetect (low-frequency earthquakes) suit specific settings.
- Pre-trained weights: choose weights trained on data similar to yours, e.g.
"instance"for Italy or"stead"for global data. - GPU: with
torch_use_cuda, the annotation runs on a CUDA GPU, which is much faster than on the CPU for large data sets.
{
"image": "SeisBench",
"picker": {
"threshold_p": 0.1,
"threshold_s": 0.1,
"search_window_seconds": 5.0,
"peak_separation_seconds": 0.1
},
"model": "PhaseNet",
"pretrained": "original",
"window_overlap_samples": 2000,
"torch_use_cuda": true,
"torch_cpu_threads": 4,
"batch_size": 128,
"stack_method": "avg",
"sampling_rate": 100.0,
"phase_map": {
"P": "cake:P",
"S": "cake:S"
},
"weights": {
"P": 1.0,
"S": 1.0
}
}
SeisBench
pydantic-model
¶
Bases: ImageFunction
Phase annotations from machine learning pickers in SeisBench.
The image is the probability of a P or S phase arrival, as annotated by a pre-trained SeisBench model, e.g. PhaseNet or EQTransformer.
Fields:
-
image(Literal['SeisBench']) -
model(ModelName) -
pretrained(PreTrainedName | FilePath) -
window_overlap_samples(int) -
torch_use_cuda(bool | int) -
torch_cpu_threads(PositiveInt) -
batch_size(int) -
stack_method(StackMethod) -
sampling_rate(PositiveFloat) -
phase_map(dict[PhaseName, str]) -
weights(dict[PhaseName, Annotated[float, Field(strict=True, ge=0.0)]]) -
picker(AnnotationPicker)
pretrained
pydantic-field
¶
pretrained: PreTrainedName | FilePath = 'original'
The pre-trained weights of the model, e.g. "original", "ethz", "instance" or "stead", or the path to a custom model .json file. The SeisBench documentation lists which weights are available for which model.
window_overlap_samples
pydantic-field
¶
window_overlap_samples: int = 2000
Window overlap in samples.
torch_use_cuda
pydantic-field
¶
Use CUDA for the inference. true uses the default device, a number selects the device, e.g. 0 for the first one. false runs on the CPU.
torch_cpu_threads
pydantic-field
¶
torch_cpu_threads: PositiveInt = 4
Number of CPU threads to use if only CPU is used.
batch_size
pydantic-field
¶
batch_size: int = 128
Batch size for inference, larger values can improve performance.
stack_method
pydantic-field
¶
How overlapping annotation windows are combined, by their average ("avg") or maximum ("max").
sampling_rate
pydantic-field
¶
sampling_rate: PositiveFloat = 100.0
Sampling rate in Hz that the model assumes for its input. A rate above the native rate of the model, e.g. 200 Hz for a model trained at 100 Hz, rescales the input by their ratio. This can help to detect high-frequency microseismic events.
phase_map
pydantic-field
¶
Phase mapping from SeisBench PhaseNet to Qseek travel time phases.
weights
pydantic-field
¶
Weights for each phase.
get_subclasses
classmethod
¶
get_subclasses() -> tuple[type[ImageFunction], ...]
Returns a tuple of all the subclasses of ImageFunction.
get_images
async
¶
Calculate the images of a waveform batch.
Images without traces are skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
WaveformBatch
|
Batch of waveforms. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
WaveformImages |
WaveformImages
|
Images of the batch. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no image has traces. |
iter_images
async
¶
iter_images(
batch_iterator: AsyncIterator[WaveformBatch],
) -> AsyncIterator[tuple[WaveformImages, WaveformBatch]]
Iterate over images from batches.
The images are calculated in a background task, ahead of the consumer.
Batches whose images cannot be calculated due to a ValueError are
skipped, other errors are raised to the consumer. The background task is
cancelled when the consumer stops iterating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_iterator
|
AsyncIterator[WaveformBatch]
|
Async iterator over batches. |
required |
Yields:
| Type | Description |
|---|---|
AsyncIterator[tuple[WaveformImages, WaveformBatch]]
|
tuple[WaveformImages, WaveformBatch]: Images and their batch. |
SeisBench picker¶
{
"threshold_p": 0.1,
"threshold_s": 0.1,
"search_window_seconds": 5.0,
"peak_separation_seconds": 0.1
}
AnnotationPicker
pydantic-model
¶
Bases: Picker
Pick phase arrivals from SeisBench annotations.
The pick is the annotation peak closest to the modeled arrival time within the search window. Peaks before the event origin time are rejected.
Fields:
-
threshold_p(float) -
threshold_s(float) -
search_window_seconds(PositiveFloat) -
peak_separation_seconds(NonNegativeFloat)
threshold_p
pydantic-field
¶
threshold_p: float = 0.1
Minimum height and prominence of a P phase annotation peak.
threshold_s
pydantic-field
¶
threshold_s: float = 0.1
Minimum height and prominence of an S phase annotation peak.
search_window_seconds
pydantic-field
¶
search_window_seconds: PositiveFloat = 5.0
Total length of the search window in seconds, centered on the modeled arrival time.
peak_separation_seconds
pydantic-field
¶
peak_separation_seconds: NonNegativeFloat = 0.1
Minimum separation between annotation peaks in seconds.
get_threshold
¶
get_threshold(phase: PhaseName) -> float
Get the peak threshold for a SeisBench phase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase
|
PhaseName
|
SeisBench annotation phase, |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Peak threshold. |
pick_trace
¶
pick_trace(
trace: Trace,
phase: PhaseDescription,
event_time: datetime,
modelled_arrival: datetime,
) -> ObservedArrival | None
Pick the annotation peak closest to the modelled arrival.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace
|
Trace
|
Annotation trace, its channel is the SeisBench phase. |
required |
phase
|
PhaseDescription
|
Phase of the observed arrival. |
required |
event_time
|
datetime
|
Time of the event. |
required |
modelled_arrival
|
datetime
|
Time to search around. |
required |
Returns:
| Type | Description |
|---|---|
ObservedArrival | None
|
ObservedArrival | None: Picked arrival, None if none found. |
add_picks
¶
add_picks(
detections: Sequence[EventDetection],
images: WaveformImages,
) -> None
Pick the observed arrivals of the detections' receivers.
Picks are searched around the modelled arrival of each receiver's phase detection and attached as its observed arrival.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detections
|
Sequence[EventDetection]
|
Detections with modelled arrivals. |
required |
images
|
WaveformImages
|
Images the detections were located from. |
required |
Citations
Woollam, J., Münchmeyer, J., Tilmann, F., Rietbrock, A., Lange, D., Bornstein, T., et al. (2022). SeisBench — A toolbox for machine learning in seismology. Seismological Research Letters, 93(3), 1695–1709. https://doi.org/10.1785/0220210324
Zhu, W., & Beroza, G. C. (2019). PhaseNet: a deep-neural-network-based seismic arrival-time picking method. Geophysical Journal International, 216(1), 261–273. https://doi.org/10.1093/gji/ggy423
Mousavi, S. M., Ellsworth, W. L., Zhu, W., Chuang, L. Y., & Beroza, G. C. (2020). Earthquake transformer — an attentive deep-learning model for simultaneous earthquake detection and phase picking. Nature Communications, 11, 3952. https://doi.org/10.1038/s41467-020-17591-w
STA/LTA¶
A short-term average to long-term average (STA/LTA) characteristic function, adapted from QuakeMigrate. P phases are detected on the vertical component, S phases on the horizontal components.
The centered STA/LTA places the short-term window after the long-term window, so the ratio peaks at the phase onset. The image is the logarithm of the STA/LTA ratio: stacking the images yields the geometric mean of the ratios. The semblance and the detection threshold are in log units, noise is at 0.
{
"image": "StaLta",
"picker": {
"mad_factor": 5.0,
"search_window_seconds": 5.0
},
"sta_seconds": 0.2,
"lta_seconds": 1.0,
"blinding_window": 5.0,
"position": "centred",
"min_onset_value": 0.4,
"signal_transform": "energy",
"phase_map": {
"P": "cake:P",
"S": "cake:S"
},
"weights": {
"P": 1.0,
"S": 1.0
}
}
StaLta
pydantic-model
¶
Bases: ImageFunction
STA/LTA analytical characteristic function.
The image is the natural logarithm of the STA/LTA onset function, clipped at
min_onset_value. Stacking the log onsets yields the logarithm of the
geometric mean of the onsets, following QuakeMigrate. The semblance and the
pick detection values are in log units, noise is at 0.
Fields:
-
image(Literal['StaLta']) -
sta_seconds(PositiveFloat) -
lta_seconds(PositiveFloat) -
blinding_window(PositiveFloat) -
position(StaLtaPosition) -
min_onset_value(float) -
signal_transform(SignalTransform) -
phase_map(dict[PhaseName, str]) -
weights(dict[PhaseName, Annotated[float, Field(strict=True, ge=0.0)]]) -
picker(StaLtaPicker)
Validators:
sta_seconds
pydantic-field
¶
sta_seconds: PositiveFloat = 0.2
Length of the short-term average (STA) window in seconds. A long STA window flattens the peak of the centered STA/LTA at the phase onset.
lta_seconds
pydantic-field
¶
lta_seconds: PositiveFloat = 1.0
Long-term average (LTA) window length in seconds.
blinding_window
pydantic-field
¶
blinding_window: PositiveFloat = 5
Blinding window in which no new detection can be set. Typically the duration of the seismic event.
position
pydantic-field
¶
Position of the STA window. centred places the STA window after the LTA window, the ratio peaks at the phase onset. classic overlaps both windows at their end, the ratio peaks up to sta_seconds after the phase onset.
min_onset_value
pydantic-field
¶
min_onset_value: float = 0.4
Minimum value of the STA/LTA onset function before taking the logarithm. Limits the influence of low onset values, e.g. in the coda of strong events, on the stack.
signal_transform
pydantic-field
¶
Signal transform applied to the waveform before computing the STA/LTA ratio. energy uses the squared amplitude, absolute the absolute amplitude, and envelope the amplitude of the analytic signal (Hilbert envelope).
phase_map
pydantic-field
¶
Phase mapping from STA/LTA P and S images to Qseek travel time phases.
weights
pydantic-field
¶
Weights for each phase.
check_windows
pydantic-validator
¶
check_windows() -> StaLta
Check that the STA window is shorter than the LTA window.
process_traces
async
¶
get_blinding
¶
get_blinding() -> timedelta
Blinding duration for the image function. Added to padded waveforms.
Returns:
| Name | Type | Description |
|---|---|---|
timedelta |
timedelta
|
The blinding duration for the image function. |
get_phases
¶
get_phases() -> tuple[PhaseDescription, ...]
Get the phases provided by the image function.
Returns:
| Type | Description |
|---|---|
tuple[PhaseDescription, ...]
|
tuple[PhaseDescription, ...]: The phases provided by the image function. |
get_subclasses
classmethod
¶
get_subclasses() -> tuple[type[ImageFunction], ...]
Returns a tuple of all the subclasses of ImageFunction.
get_images
async
¶
Calculate the images of a waveform batch.
Images without traces are skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
WaveformBatch
|
Batch of waveforms. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
WaveformImages |
WaveformImages
|
Images of the batch. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no image has traces. |
iter_images
async
¶
iter_images(
batch_iterator: AsyncIterator[WaveformBatch],
) -> AsyncIterator[tuple[WaveformImages, WaveformBatch]]
Iterate over images from batches.
The images are calculated in a background task, ahead of the consumer.
Batches whose images cannot be calculated due to a ValueError are
skipped, other errors are raised to the consumer. The background task is
cancelled when the consumer stops iterating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_iterator
|
AsyncIterator[WaveformBatch]
|
Async iterator over batches. |
required |
Yields:
| Type | Description |
|---|---|
AsyncIterator[tuple[WaveformImages, WaveformBatch]]
|
tuple[WaveformImages, WaveformBatch]: Images and their batch. |
STA/LTA picker¶
StaLtaPicker
pydantic-model
¶
Bases: Picker
Pick phase onsets from STA/LTA characteristic functions.
Triggers are detected on the station's full STA/LTA trace. A trigger turns on
where the ratio exceeds median + mad_factor * MAD of the trace and turns off
when it falls below half of that excess, median + mad_factor / 2 * MAD. The
pick is the peak of the trigger closest to the modeled arrival within the
search window, the centered STA/LTA peaks at the phase onset. Peaks before the
event origin time are rejected.
Fields:
mad_factor
pydantic-field
¶
mad_factor: PositiveFloat = 5.0
Trigger threshold above the median of a station's STA/LTA trace, in multiples of its median absolute deviation (MAD): threshold = median + MAD * mad_factor.
search_window_seconds
pydantic-field
¶
search_window_seconds: PositiveFloat = 5.0
Total length of the search window in seconds, centered on the modeled arrival time.
get_trigger_thresholds
¶
pick_trace
¶
pick_trace(
trace: Trace,
phase: PhaseDescription,
event_time: datetime,
modelled_arrival: datetime,
) -> ObservedArrival | None
Pick the trigger peak closest to the modelled arrival.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace
|
Trace
|
STA/LTA characteristic function trace. |
required |
phase
|
PhaseDescription
|
Phase of the observed arrival. |
required |
event_time
|
datetime
|
Time of the event. |
required |
modelled_arrival
|
datetime
|
Time to search around. |
required |
Returns:
| Type | Description |
|---|---|
ObservedArrival | None
|
ObservedArrival | None: Picked arrival, None if none found. |
add_picks
¶
add_picks(
detections: Sequence[EventDetection],
images: WaveformImages,
) -> None
Pick the observed arrivals of the detections' receivers.
Picks are searched around the modelled arrival of each receiver's phase detection and attached as its observed arrival.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detections
|
Sequence[EventDetection]
|
Detections with modelled arrivals. |
required |
images
|
WaveformImages
|
Images the detections were located from. |
required |
Citation
Winder, T., Bacon, C. A., Smith, J. D., Hudson, T., Greenfield, T., & White, R. S. (2020). QuakeMigrate: a modular, open-source Python package for automatic earthquake detection and location. AGU Fall Meeting 2020.