relmt.align module#
- relmt.align.complete_paired_s_lag_times(evpairs, dd, cc, dd_res, method='median')[source]#
Pair-wise from triplet-wise lag times from complete set.
Compute pair-wise from the triplet-wise lag times
ddreturned bymccc_align(). Assume all combinations are present, i.e. npair = events * (events-1) * (events-2) / 3- Parameters:
ev_pair –
(npair, 2)event indicesdd (
ndarray) – Corresponding(npair,)pairwise differential arrival timescc (
ndarray) –(events, events, events)Cross correlation matrixdd_res (
ndarray) –(npair,)residuals of the alignmentmethod (
str) –‘median’: take the median of the tripletwise lag times
’residual’ choose the one with the lowest residual
’cc’ choose the one with the highest cross-correlation coefficient
evpairs (
ndarray)
- Returns:
ev_pair (
numpy.ndarray) –(events * (events-1) / 2, 2)event indicesdd_pair (
numpy.ndarray) – Corresponding median differential arrival timescc_pair (
numpy.ndarray) – Corresponding average cross correlation coefficientres_pair (
numpy.ndarray) – Corresponding residuals of the differential arrival times. If ‘method’ is ‘median’, the RMS of all lag times
- relmt.align.incomplete_paired_s_lag_times(evpairs, dd, cc, dd_res, combinations, method='cc')[source]#
Pair-wise from triplet-wise lag times from incomplete set.
Compute pair-wise from the triplet-wise lag times
ddreturned bymccc_align()with a combinations list parsed. Do not attempt to compute implicit combinations- Parameters:
evpairs (
ndarray) –(npair, 2)event indicesdd (
ndarray) – Corresponding pairwise differential arrival timescc (
ndarray) –(events, events, events)Cross correlation matrixdd_res (
ndarray) –(npair,)residuals of the alignmentcombinations (
ndarray) –(npair/2, 3)triplet combinations that form the incomplete observationsmethod (
str) –‘residual’ choose the one with the lowest residual
’cc’ choose the one with the highest cross-correlation coefficient
- Returns:
ev_pair (
numpy.ndarray) –(events * (events-1) / 2, 2)event indicesdd_pair (
numpy.ndarray) – Corresponding median differential arrival timescc_pair (
numpy.ndarray) – Corresponding average cross correlation coefficientres_pair (
numpy.ndarray) – Corresponding residuals of the differential arrival times.
- relmt.align.mccc_align(mtx, phase, sampling_rate, maxshift, ndec=1, combinations=array([], dtype=float64), do_scc=True, verbose=False)[source]#
Compute time shifts that align the seismogram matrix
Applies the multi-channel cross-correlation method (Bostock et al. 2021, BSSA)
- Parameters:
mtx (
ndarray) – Waveform matrix of shape(events, samples), with time aligned along last axisphase (
str) – Seismic phase (‘P’ or ‘S’)sampling_rate (
float) – Sampling rate of the wavefrom matrix (Hertz)maxshift (
float) – Maximum shift to test (seconds)ndec (
int) – Test correlation function at every ndec’th pointcombinations (
ndarray) – Only combine these indices of mtx.(combinations, 2)for P-waves,(combinations, 3)for S-waves. When empty, combine all events.do_scc (
bool) – Compute S-wave correlation coefficients. May be slow. Else, returned cc values are all zeroverbose (
bool) – Print diagnostic output
- Returns:
time_shifts (
numpy.ndarray) – Zero-mean time shifts of shape(events,)that maximize cccc (
numpy.ndarray) – Nominal correlation coefficients between events at optimal time lagdd (
numpy.ndarray) – Pairwise differential arrival timesdd_res (
numpy.ndarray) – Resiudal when computing time lags from pairwise differential arrival timespairs (
numpy.ndarray) – Pairwise event combination indices pointing intomtxof shape(C,2), where C is events * (events-1) / 2 for P waves and events * (events-1) * (events-2)/ 3 for S waves
- Raises:
IndexError: – When mtx contains less than 2 events for P waves, or less than 3 for S waves
ValueError: – When phase is not ‘P’ or ‘S’
- relmt.align.pca_align(mtx, sampling_rate, phase, iterations=50, dphi=0, dtime=0)[source]#
Align waveforms by principal component analysis
Implements method of Bostock et al. (2021, BSSA).
For P-waves, we maximize the first of the singular values \(s\) of \(n\) waveforms:
\[\phi = s_0^2 / n\]For S-waves, we maximize the sum of the first two singular values:
\[\phi = 1 - s_2 / (s_0 + s_1),\]where \(\phi\) ranges from 0 (worst) to 1 (best)
- Parameters:
mtx (
ndarray) – Waveform matrix of shape(events, samples), with time aligned along last axissampling_rate (
float) – Sampling rate of the wavefrom matrix (Hertz)phase (
str) – Which seismic phase to consider (‘P’ or ‘S’)iterations (
int) – Maximum number of iterationsdphi (
float) – Minimum change in objective function to stop iterationdtime (
float) – Smallest maximal time shift to stop iteration
- Returns:
time_shifts (
numpy.ndarray) – Zero-mean time shifts of shape(events,)that maximize phiphi (float) – Value of objective function
- Raises:
IndexError: – When mtx contains less than 2 events for P waves, or less than 3 for S waves
ValueError: – When phase is not ‘P’ or ‘S’
- relmt.align.pca_objective(sigma, phase, ns)[source]#
Principal component alignment objective function
for P phases:
\[\phi = s_0^2 / n\]For S phases:
\[\phi = 1 - s_2 / (s_0 + s_1)\]
- relmt.align.run(wvarr, header, destination, do_mccc=True, do_pca=True, mccc_combinations=array([], dtype=float64), lag_times=[])[source]#
Align waveforms and save results to disk
- Parameters:
wvarr (
ndarray) –(events, channels, samples)waveform arrayheader (
Header) – Dictionary holding the processing parametersdestination (
tuple[str,str,int,str]) – Tuple holding station name, phase type, alignment iteration number and destination root directorydo_mccc (
bool) – Align using multi-channel cross correlation.do_pca (
bool) – Align using principal component analyses. This allows for sub-sample alignment, but impedes to combine cross correlation lag times of two successive runs.mccc_combinations (
ndarray) – When aligning using mccc, only combine these pairs (P-waves) or triplets (S-waves).MCCC lag times to save to file:
”P”: P lag times
”S-median”: median of S lag time triplets
”S-residual”: S lag times with lowest residuals
”S-cc”: S lag times with highest cross-correlation values