relmt.signal module#

relmt.signal.cc_coef(x, y)[source]#

Calculate the correlation coefficient between two equal-length vectors:

\[\sum_i(x_i y_i) (\sum_i x_i^2 \sum_i y_i^2)^{-1/2}\]
Parameters:
  • x (ndarray) – Input vectors of same length (samples,)

  • y (ndarray) – Input vectors of same length (samples,)

Returns:

floatCorrelation coefficient between x and y.

Note

The correlation coefficient is a measure of linear association between two variables.

relmt.signal.choose_passband(highpasses, lowpasses, min_dynamic_range=1)[source]#

Return the highest highpass and the lowest lowpass filter band

Parameters:
  • highpasses (list[float]) – List of highpass and lowpass filter corner candidates

  • lowpasses (list[float]) – List of highpass and lowpass filter corner candidates

  • min_dynamic_range (float) – Minimum ratio (dB) between lowpass and highpass. If resulting filter bandwidth is lower, and a positive value is given, return None. If a negative value is given, interpret the absolute value and relax the highpass filter corner.

Returns:

highpass, lowpass – Filter corners (Hz), None if filter band is below the positive min_dynamic_range or any of highpasses or lowpasses is not finite.

relmt.signal.correlation_averages(mat, phase, set_autocorrelation=True)[source]#

Correlation coefficients between event pairs or triplets

For each pair (if phase is ‘P’) of triplet (if phase is ‘S’) of waveforms, compute the reconstruction correlation coefficient. Consolidate by also computing the average values.

Note

Consolidated (averaged) correlation coefficients are of absolute values and hence positive

Parameters:
  • mat (ndarray) – Waveform matrix of shape (events, samples)

  • phase (str) – ‘P’ for pairwise correlation, ‘S’ for triplet-wise correlation

  • set_autocorrelation – Set correlations with two matching indices to unity in ccijk and ccij

Returns:

  • ccijk – Correlation coefficients between event triplets of shape (events, events, events). NaN if phase is ‘P’

  • ccij – Correlation coefficients between event pairs if phase is ‘P’. Averaged correlation over k if phase is ‘S’. Shape (events, events).

  • cci – Average absolute correlation coefficient of all pairs or triplets of shape (events,)

  • cc – Average absolute correlation coefficient of the matrix

relmt.signal.cosine_taper(arr, taper_length, sampling_rate, phase_start=None, phase_end=None)[source]#

Taper time series along last axis.

Parameters:
  • arr (ndarray) – (..., N) seismogram section, with time aligned along last axis

  • taper_length (float) – Combined length of taper that is applied at both ends beyond the phase window. (seconds)

  • sampling_rate (float) – Sampling rate of the seismic waveform (Hertz)

  • phase_start (float | None) – Start of the phase window before the arrival time pick (negative seconds before pick).

  • phase_end (float | None) – End of the phase window after the arrival time pick (seconds after pick).

Returns:

ndarrayTapered seismogram section

Raises:

ValueError: – If taper falls outside array dimensions

relmt.signal.dB(ratio)[source]#

Ratio expressed in decibel

Parameters:

ratio (float | ndarray)

Return type:

float | ndarray

relmt.signal.demean(arr)[source]#

Remove mean value along last dimension from array

Parameters:

arr (ndarray)

Return type:

ndarray

relmt.signal.demean_filter_window(arr, sampling_rate, phase_start, phase_end, taper_length, highpass=None, lowpass=None, zerophase=True)[source]#

Demean, filter and taper waveform array

Parameters:
  • arr (ndarray) – Waveform array to process

  • sampling_rate (float) – Sampling rate of the seismic waveform (Hertz)

  • phase_start (float) – Start of the phase window before the arrival time pick (negative seconds before pick).

  • phase_end (float) – End of the phase window after the arrival time pick (seconds after pick).

  • taper_length (float) – Combined length of taper that is applied at both ends beyond the phase window. (seconds)

  • highpass (float | None) – Common high-pass filter corner of the waveform (Hertz)

  • lowpass (float | None) – Common low-pass filter corner of the waveform (Hertz)

  • zerophase (bool) – Apply filter a second time reversed, so that resulting signal has no phase shift

Returns:

ndarrayFiltered, windowed and tapered waveform array

relmt.signal.destep(wvf_array)[source]#

Remove step between first and last sample value along last dimension from array.

Parameters:

wvf_array (ndarray)

Return type:

ndarray

relmt.signal.differentiate(arr, sampling_rate)[source]#

Differentiate a seismogram section in Fourier space

Parameters:
  • arr (ndarray) – (..., samples) Seismogram section, with time aligned along last axis

  • sampling_rate (float) – Sampling rate (Hertz)

Returns:

ndarrayDifferentiated seismogram section

relmt.signal.filter(wvf, sampling_rate, highpass=None, lowpass=None, order=2, zerophase=False, typ='bessel')[source]#

Filter the waveform array or matrix along last dimension. Highpass, lowpass, or bandpass is applied when high, low, or both frequency corners are given.

Parameters:
  • wvf (ndarray) – Waveform array or matrix

  • sampling_rate (float) – Sampling rate (Hertz)

  • highpass (float | None) – Highpass and lowpass filter corners (Hz)

  • lowpass (float | None) – Highpass and lowpass filter corners (Hz)

  • order (int) – Order of the filter

  • zerophase (bool) – Use scipy.filtfilt instead of lfilt to get a zerophase filter

  • typ (str) – “bessel” or “butter” for Bessel or Butterworth filter

Returns:

ndarrayFiltered waveforms

Raises:
  • ValueError: – If neither highpass, nor lowpass are given

  • ValueError: – If given unknown filter type

relmt.signal.fraction(db)[source]#

Ratio in decibel expressed as fraction

Parameters:

db (float | ndarray)

Return type:

float | ndarray

relmt.signal.indices_inside_taper(sampling_rate, taper_length, phase_start, phase_end, data_window)[source]#

First and last indices of trace that are not zeroed through tapering

Parameters:
  • sampling_rate (float) – Sampling rate of the seismic waveform (Hertz)

  • taper_length (float) – Combined length of taper that is applied at both ends beyond the phase window. (seconds)

  • phase_start (float) – Start of the phase window before the arrival time pick (negative seconds before pick).

  • phase_end (float) – End of the phase window after the arrival time pick (seconds after pick).

  • data_window (float) – Time window symmetric about the phase pick (i.e. pick is near the central sample) (seconds)

Returns:

tuple[int, int]First and last index inside the taper

relmt.signal.indices_noise(sampling_rate, phase_start, phase_end, data_window)[source]#

Return first and last indices of the pre-singal noise window. Attempt equal length.

Returns:

tuple[int, int]First and last index inside the noise window

Parameters:
relmt.signal.indices_signal(sampling_rate, phase_start, phase_end, data_window)[source]#

Return first and last indices of the phase signal

Parameters:
  • sampling_rate (float) – Sampling rate of the seismic waveform (Hertz)

  • phase_start (float) – Start of the phase window before the arrival time pick (negative seconds before pick).

  • phase_end (float) – End of the phase window after the arrival time pick (seconds after pick).

  • data_window (float) – Time window symmetric about the phase pick (i.e. pick is near the central sample) (seconds)

Returns:

tuple[int, int]First and last index inside the phase window

relmt.signal.integrate(arr, sampling_rate)[source]#

Integrate a seismogram section in Fourier space

Parameters:
  • arr (ndarray) – (..., samples) Seismogram section, with time aligned along last axis

  • sampling_rate (float) – Sampling rate (Hertz)

Returns:

ndarrayIntegrated seismogram section

relmt.signal.make_wavelet(n, p, typ='sin', we=inf, ds=0.0, de=0.0)[source]#

Make a wavelet

Parameters:
  • n (int) – length of wavelet (samples)

  • p (float) – period length of the signal (samples)

  • typ (str) – Return a sine (‘sin’), cosine (‘cos’), or rectangle (‘rec’) function

  • we (float) – 1-sigma width of the gaussian envelope (samples)

  • ds (float) – shift of signal to the right (samples)

  • de (float) – shift of envelope to the right (samples)

Returns:

ndarrayThe wavelet

relmt.signal.norm_power(array, axis=-1)[source]#

Normalize input array by power

\[A / \sqrt \sum A^2\]
Parameters:
  • array (ndarray) – to normalize

  • axis (int) – of the array along which to operate

Returns:

ndarrayNormalized array

relmt.signal.phase_passbands(arr, hdr, evd, exclude=None, auto_highpass_periods=1.0, auto_lowpass_method=None, fixed_lowpass=None, auto_lowpass_stressdrop_range=[1000000.0, 1000000.0], auto_lowpass_vs=4000, auto_bandpass_snr_target=None)[source]#

Compute the bandpass filter corners for a waveform array.

This function computes the bandpass filter corners for each event in the waveform array. The following logic is applied:

The lowpass corner should be the corner frequency of the phase spectrum. We estimate it as:

  • 1/source duration of the event magnitude when lowpass_method is ‘duration’.

  • Based on the corner frequency pertaining to a stressdrop (Pa) within lowpass_stressdrop_range when lowpass_method is ‘corner’:

  • If the upper bound is smaller or equal the lower bound (i.e. no range is given), estimate the corner frequency using utils.corner_frequency() with an S-wave velocity of 4 km/s.

  • If a range is given, we convert it to a corner frequency range as above and search the apparent corner frequency as the maximum of the phase velocity spectrum within this range using extra.apparent_corner_frequency()

The default highpass corner is chosen as 1/phase length.

When bandpass_snr_target is given, we determine the frequency band in the signal and noise spectra for which the signal-to-noise ratio is larger than bandpass_snr_target (dB), compare with the above estimates, and return the highest highpass and the lowest lowpass corner.

Parameters:
  • arr (ndarray) – The waveform array with shape (events, channels, samples).

  • hdr (Header) – The header containing metadata about the waveform array, including phase phase start and end times, sampling rate, included events.

  • evd (dict[int, Event]) – The seismic event catalog.

  • exclude (Exclude | None) – An optional exclude object with observations to be excluded from the computation. If None, all observatinos are included.

  • auto_highpass_periods (float) – Set the default highpass filter corner to allow not fewer than this many signal periods within the respective phase window: highpass = auto_highpass_periods / (phase_end - phase_start).

  • auto_lowpass_method (str | None) – Method to determine the lowpass corner frequency. Options are: ‘duration’, ‘corner’, ‘fixed’

  • fixed_lowpass (float | None) – The fixed lowpass corner frequency, when auto_lowpass_method is ‘fixed’. Ignored otherwise.

  • auto_lowpass_stressdrop_range (tuple[float, float]) – Tuple of lower and upper bound of stress drop (Pa) to consider when auto_lowpass_method is ‘corner’. Ignored otherwise.

  • auto_lowpass_vs (float) – Near source S-wave velocity (m/s) used to constrain spectral corner frequency estimate when auto_lowpass_method is ‘corner’. Ignored otherwise.

  • auto_bandpass_snr_target (float | None) – Minimum signal-to-noise ratio (dB) to consider when optimizing the bandpass filter corners. If None, no optimization is applied and the default corners are returned.

Returns:

dict[str, list[float]] – * Dictionary mapping phaseIDs (event ID, station, phase) to filter corners * [highpass, lowpass].

Raises:

ValueError: – If an unknown lowpass method is specified.

relmt.signal.rotate_nez_rtz(nez, backazimuth)[source]#

Rotate seismogram array from N-E-Z into R-T-Z system

Parameters:
Return type:

ndarray

relmt.signal.shift(mtx, dt, sampling_rate)[source]#

Shift a seismogram section in Fourier space

Parameters:
  • mtx (ndarray) – Seismogram section of shape (events, samples)

  • dt (ndarray) – Time shifts positive to the right per seismogram (seconds)

  • sampling_rate (float) – Sampling rate (Hertz)

Returns:

ndarray(events, samples) shifted seismogram section

relmt.signal.shift_3d(wvf_array, dt, sampling_rate)[source]#

Shift a waveform matrix in Fourier space

TODO: Tests indicate this is superseed by shift

Parameters:
  • wvf_array (ndarray) – Waveform array, with time aligned along last axis

  • dt (ndarray) – Time shifts positive to the right per seismogram (seconds)

  • sampling_rate (float) – Sampling rate (Hertz)

Returns:

out ((E, C, S) array:) – Shifted seismogram section

relmt.signal.signal_noise_ratio(arr, sampling_rate, phase_start, phase_end, taper_length, highpass=None, lowpass=None)[source]#

Calculate combined signal to noise ratio of all components in arr

Parameters:
  • arr (ndarray) – (..., samples) Seismogram section, with time aligned along last axis

  • sampling_rate (float) – Sampling rate of the seismic waveform (Hertz)

  • phase_start (float) – Start of the phase window before the arrival time pick (negative seconds before pick).

  • phase_end (float) – End of the phase window after the arrival time pick (seconds after pick).

  • taper_length (float) – Combined length of taper that is applied at both ends beyond the phase window. (seconds)

  • highpass (float | None) – Common high-pass filter corner of the waveform (Hertz)

  • lowpass (float | None) – Common low-pass filter corner of the waveform (Hertz)

Returns:

float | ndarraySignal noise ratio in dB

relmt.signal.subset_filter_align(arr, indices, hpas, lpas, phase, sampling_rate, phase_start, phase_end, taper_length)[source]#

Choose seismogram subset and align within filterband

Parameters:
  • arr (ndarray) – (events, channels, samples) 3-D seismogram array

  • indices (list[int]) – Event indices to select from arr

  • hpas (float) – Highpass, …

  • lpas (float) – Lowpass filter corners

  • phase (str) – Seismic phase type to consider (‘P’ or ‘S’)

  • sampling_rate (float) – Sampling rate of the seismic waveform (Hertz)

  • phase_start (float) – Start of the phase window before the arrival time pick (negative seconds before pick).

  • phase_end (float) – End of the phase window after the arrival time pick (seconds after pick).

  • taper_length (float) – Combined length of taper that is applied at both ends beyond the phase window. (seconds)

Returns:

ndarray(events, samples * channels) 2-D seismogram matrix

relmt.signal.zero_events(wvf_array, event_indices)[source]#

Set seismograms of event_indices to zero

Parameters:
Return type:

ndarray