relmt.utils module#
- relmt.utils.approx_time_lookup(time1, time2, include_at=inf)[source]#
Create lookup table for time1 approximately matching time2
All events in time1s must be present in time2, i.e.
len(time1) <= len(time2).- Parameters:
time1 (
list[str] |list[float]) – Times either as date_string understood bydatetime.datetime.fromisoformat(), or as float in arbitrary unitstime2 (
list[str] |list[float]) – Times either as date_string understood bydatetime.datetime.fromisoformat(), or as float in arbitrary unitsinclude_at (
float) – Maximum time difference (seconds) to consider a match.
- Returns:
dict– Lookup table time1 -> time2- Raises:
LookupError: – When time1 is longer than time2
- relmt.utils.cartesian_distance(x1, y1, z1, x2, y2, z2)[source]#
Cartesian distance between points (x1, y1, z1) and (x2, y2, z2)
- relmt.utils.ccorf3_all(gmat, batch_size=200000)[source]#
Triplet-wise S-wave correlations of seismogram matrix Generalized and optimized ccorf3 for all column triples.
- Parameters:
- Returns:
cc_all ((C(event,3), 3) float64) –
(events, events, events)S-wave cross correlation coefficient per event triplet
- relmt.utils.collect_takeoff(phase_dict, event_index, stations=None)[source]#
Take-off azimuth and plunge angles for an event
- Parameters:
- Returns:
azimuths (np.ndarray) – Take-off azimuths (degree)
plunges (np.ndarray) – Take-off plunges (degree)
stas (np.ndarray) – Corrsponding station names
phases (np.ndarray) – Corresponding phase types
- relmt.utils.common_event_phase_lowpass(passbands, quantile)[source]#
Find common lowpass frequency across events for each station and phase
- relmt.utils.concat_components(arr)[source]#
Rearange waveform array so that components are concatenated
- relmt.utils.corner_frequency(magnitude, phase, stress_drop, vs)[source]#
Return a rought estimate of the corner frequency based on (Madariaga, 1976):
\[f_c = (16/7 \sigma k_s^3 v_S^3 / M_0 )^{1/3}\]
- relmt.utils.element_redundancy(pairs, ignore=None)[source]#
Count of the number of contributing elements per pair
- relmt.utils.event_indices(amps)[source]#
Index arrays of unique event numbers
For each event, find the constituting pair or triplet wise amplitude observations
- Parameters:
amps (
list[P_Amplitude_Ratio] |list[S_Amplitude_Ratios]) – List of amplitude observations, either P or S- Returns:
dict[int,ndarray] – Mapping from event number to observation indices
- relmt.utils.fftw_data_window(minimum_time, sampling_rate, components)[source]#
Set ‘data_window’ based on sampling rate and number of components
- Parameters:
- Returns:
float– Length of single-channel time window. The concated components will be fftw optimized
- relmt.utils.fisher_average(ccarr, axis=-1)[source]#
Average cross correlation coefficients applying Fisher z-transform
- relmt.utils.interpolate_phase_dict(phase_dict, event_dict, station_dict, obs_min=1)[source]#
Interpolate phase arrivals, ray azimuth and plunge
Arrival time is interpolated via an average velocity along the ray path.
Ray plunge is interpolated linearly between neighboring points in depth
Azimuth is calculated assuming a horizontally straight ray.
- relmt.utils.mt_clusters(mt_dict, method='kagan', distance_matrix=None, max_distance=30, min_ev=1, link_method='average')[source]#
Cluster moment tensors
- Parameters:
method (
str) – Method to compare two events. Choices are: - ‘ccp’ Correlation coefficient of the P radiation - ‘ccs’ Correlation coefficient of the S radiation - ‘scalar’ Normaized scalar product of the tenors - ‘kagan’ Kagan angle of the DC componentsdistance_matrix (
ndarray|None) – Ignore ‘method’, but give a pre-computed distance matrix. Can Accalerate the process in finding max_dist and ev_min. Second return argument from a previous run is suited. Seescipy.spacial.distance.pdist()for format.max_distance (
float) – maximum distance for pairs to include in a clustermin_ev (
int) – Minimum number of events per cluster. Unclustered events will receive 0 label.link_method (
str) – Method of linking events passed on toscipy.cluster.hirearchy.linkage()
- Returns:
labels – Labels of the event clusters, where 0 is the label for unclustered events
distance_matrix – Compressed pairwise distance matrix
representative – The representative element for each label
- relmt.utils.next_fftw_size(samples, devisor=3, odd=True)[source]#
The next integer for which FFTW is optimized
- relmt.utils.pair_redundancy(triplets, ignore=None)[source]#
Count of the number of contributing pairs per triplet
- relmt.utils.pc_index(mtx, phase)[source]#
Return principal component sorting of seismogram matrix
For P-phases, sort by zero-th left hand singular vector For S-phases, sort angle in the plane spanned by the zero-th and first left hand singular vectors
- relmt.utils.phase_dict_azimuth(phase_dict, event_dict, station_dict, overwrite=False)[source]#
Fill phase dictionary with azimuth using trigonometry
- relmt.utils.phase_dict_hash_plunge(phase_dict, event_dict, station_dict, vmodel, overwrite=False, strict=False, nquerry=100, nray=1000, station_depth=True)[source]#
Fill phase dictionary with plunge values from HASH.
Uses the python implementation of the HASH ray-tracer (Skoumal, Hardebeck & Shearer, 2024; Hardebeck & Shearer, 2002) by courtesey of USGS.
- Parameters:
vmodel (
ndarray) –(layers, 3)array of depth (m), P- and S-wave velocities (m/s)overwrite (
bool) – Overwrite existing plunge values (False: only replace NaN values)strict (
bool) – Raise KeyError when an event or station is missing. If False, check phase_dict for missing events and stations.nquerry (
int) – Number of distance and depth querry points for plunge lookup tablenray – Number of trail rays (should be larger than nquerry)
station_depth (
bool) – If True, consider station depth by cropping velocity model above to the depth of the station. Produces NaN plunges for events above the station. False places all stations at the shallowest depth of the velocity model, consistent with SKHASH behavior.
- Returns:
dict[str,Phase] – New phase dictionary containing computed plunges
- relmt.utils.reshape_ccvec(ccvec, ns, combinations=None)[source]#
Reshape 1D vector of cc coefficeints c_ijk to
(n, n, n)3D matrix
- relmt.utils.select_events(arr, select, events)[source]#
Return waveforms of specific evetn numbers
- arr:
(events, ...)or waveform array or matrix- select:
List of event numbers to select
- events:
List of event numbers in the array
- relmt.utils.signed_log_inverse(y)[source]#
Inverse of the signed log transform: sign(x) log(1 + | x |)
- relmt.utils.source_duration(magnitude)[source]#
Approximate duration of an earthquake with given magnitude
\[t = 3^{M-5}\]
- relmt.utils.station_gap(station_dict, event_dict)[source]#
Azimuthal gap from center of event clud that would remain if station was removed