saul.spectral.helpers

Contains helper functions and constants for tasks related to spectral estimation and filtering.

saul.spectral.helpers.get_ak_infra_noise()[source]

Returns the Alaska ambient infrasound noise models from Macpherson et al. (2022).

Macpherson, K. A., Coffey, J. R., Witsil, A. J., Fee, D., Holtkamp, S., Dalton, S., McFarlin, H., & West, M. (2022). Ambient infrasound noise, station performance, and their relation to land cover across Alaska. Seismological Research Letters, 93(4), 2239–2258. https://doi.org/10.1785/0220210365

Usage example:

from saul import get_ak_infra_noise
p, hnm, mnm, lnm = get_ak_infra_noise()
Returns:

Period [s], high noise model [dB rel. 1 Pa2 Hz–1], median noise model [dB rel. 1 Pa2 Hz–1], low noise model [dB rel. 1 Pa2 Hz–1]

Return type:

tuple

saul.spectral.helpers.obspy_filter_response(filter_type, sampling_rate, freqs=4096, plot=False, **options)[source]

Calculate the frequency response of an ObsPy filter.

Based on ObsPy 1.4.1.

Parameters:
  • filter_type (str) – Type of filter to use. Note that not all of ObsPy’s filter types are supported; see the match statement in the code

  • sampling_rate (int or float) – Sampling rate of target data

  • freqs (int or array_like) – Passed on as worN argument to scipy.signal.freqz_zpk() — if an array, the response will be computed at these frequencies

  • plot (bool) – Whether to plot the frequency response

  • **options – Necessary keyword arguments that will be passed on to the respective filter function (e.g., freqmin=1, freqmax=5 for filter_type='bandpass')

Returns:

Array of frequencies at which the response was computed [Hz], frequency response [dB]

Return type:

tuple

saul.spectral.helpers.extract_trace_filter_params(tr)[source]

Extract filter parameters from an ObsPy Trace object.

Expects to find a filter operation in the string stored in tr.stats.processing[-1]. Can be combined with obspy_filter_response() to conveniently plot the filter response of the previous filtering operation like so:

tr.filter(...)
_ = obspy_filter_response(plot=True, **extract_trace_filter_params(tr))
Parameters:

tr (Trace) – Input trace

Returns:

Extracted filter parameters

Return type:

dict

Warning

The uses sketchy string processing and eval() to extract the filter parameters! It fails to extract *args in tr.filter(type, *args, **options) — only type and **options are extracted.