relmt.qc module#

Functions for Quality Control

relmt.qc.clean_by_equation_station_count_gap(p_amplitudes, s_amplitudes, phase_dict, min_equations=1, min_stations=1, max_gap=360.0, two_s_equations=True)[source]#

Remove observations below equation, station, gap thresholds iteratively

Counts the number of ocurrences of each event. Events that occur fewer than min_equations times, are observed on fewer stations than min_stations or have an azimuthal gap larger than max_gap are discarded, togther with the events they are connected to. This procedure is repeated until all remaining events are constrained by at least ‘min_equations` equations, min_stations stations and with a maximum azimuthal gap of max_gap.

Parameters:
  • p_amplitudes (list[P_Amplitude_Ratio]) – List of P amplitude observations

  • S_amplitudes – List of S amplitude observations

  • phase_dict (dict[str, Phase]) – Phase dictionary with take-off azimuths

  • min_equations (int) – Minimum number of occurrences of each event

  • min_stations (int) – Minimum number of stations observing each event

  • max_gap (float) – Maximum allowed azimuthal gap

  • two_s_equations (bool) – Count each S observation twice

  • s_amplitudes (list[S_Amplitude_Ratios])

Returns:

tuple[list[P_Amplitude_Ratio], list[S_Amplitude_Ratios]]Cleaned list of P- and S-amplitude observations

relmt.qc.clean_by_event(amplitudes, exclude_events)[source]#

Remove amplitude readings made for certain events

Parameters:
Returns:

list[P_Amplitude_Ratio | S_Amplitude_Ratios]Cleaned list of amplitude observations

relmt.qc.clean_by_event_distance(amplitudes, event_dict, event_distance)[source]#

Remove amplitude readings of distant event combinations

Event pairs or triplets whose maximum distance is larger than event_distance will be removed.

Parameters:
Returns:

list[P_Amplitude_Ratio | S_Amplitude_Ratios]Cleaned list of amplitude observations

relmt.qc.clean_by_kurtosis(amplitudes, event_list, max_kurtosis)[source]#

Remove amplitude readings until amplitude distribution has max kurtosis

Expected amplitude ratios are calculated from seismic moments, wich are derived from the magnitudes.

For P-waves, we investigate the distribution:

\[\log_{10}( A_{ab} M_0^b / M_0^a )\]

For S-waves:

\[\log_{10}( (B_{abc} M_0^b + B_{acb} M_0^c) / M_0^a )\]

and all equivalent event combinations.

Parameters:
Returns:

listCleaned list of amplitude observations

Raises:

ValueError: – If amplitudes is not all P or S Amplitude Ratios

relmt.qc.clean_by_magnitude_difference(amplitudes, event_dict, magnitude_difference)[source]#

Remove amplitude readings made for certain events

Parameters:
Returns:

list[P_Amplitude_Ratio | S_Amplitude_Ratios]Cleaned list of amplitude observations

relmt.qc.clean_by_misfit(amplitudes, max_misfit)[source]#

Remove amplitude readings with a misfit larger max_misfit

Parameters:
Returns:

list[P_Amplitude_Ratio | S_Amplitude_Ratios]Cleaned list of amplitude observations

relmt.qc.clean_by_shared_path(amplitudes, event_dict, station_dict, min_shared_path)[source]#

Remove amplitude readings of event combinations with small shared path

Event pairs or triplets whose shared path to the station smaller than min_shared_path will be removed. Shared path is

..math::

1 - 2 |r - r'| / |r + r'|

Parameters:
Returns:

list[P_Amplitude_Ratio | S_Amplitude_Ratios]Cleaned list of amplitude observations

relmt.qc.clean_by_station(amplitudes, exclude_stations)[source]#

Remove amplitude readings made on certain stations

Parameters:
Returns:

list[P_Amplitude_Ratio | S_Amplitude_Ratios]Cleaned list of amplitude observations

relmt.qc.clean_by_valid_takeoff_angle(amplitudes, phase_dictionary)[source]#

Remove amplitude readings with invalid corresponding take-off angle

Parameters:
Returns:

list[P_Amplitude_Ratio | S_Amplitude_Ratios]Cleaned list of amplitude observations

relmt.qc.connected_events(reference_mts, p_amplitudes=None, s_amplitudes=None)[source]#

Event connected to the reference MTs

Investigate the paired P- and triplet S-observations for connectivity. Only return those events that are connected to at least one reference MT.

Parameters:
Returns:

dict[int, tuple[int, int]] – * Mapping of event indices of the connected events to number of P- and * S-connections

Raises:
  • ValueError: – If any reference MT has no amplitude observation

  • RuntimeError: – If reference MTs are not connected with each other

relmt.qc.events_phases_above_misfit(amplitudes, misfit, subtract_below=0.0)[source]#

Count the phases that have a misfit larger than the given one

Parameters:
Returns:

  • events – Counter with events as keys and number of bad observations as values

  • phases – Counter with phase names as keys and number of bad observations as values

relmt.qc.expansion_coefficient_norm(arr, phase)[source]#

Normalized expansion coefficient sum for each seismogram in matrix

Decompose seismogram matrix into principal seismograms. Return squared contribution of first (and second) principal seismogram to each original seismogram for P- (S-) waves.

1 (best) indicates principal seismogram(s) fully reconstruct the respective waveform

0 (worst) indicates the respective waveform cannot be represented by the principal seismogram(s)

Parameters:
  • arr (ndarray) – Waveform (events, channels, samples) array or (events, channels*samples) matrix

  • phase (str) – P or S wave type

Returns:

ndarray – * (events,) score per event * Raises * ——- * IndexError – If ‘arr’ has not 2 or 3 dimensions.

relmt.qc.included_events(exclude, station, phase, events_, return_not=False, return_bool=False)[source]#

Return events that are not excluded according to exclude dictionary

Parameters:
  • exclude (Exclude | None) – Dictionary holding exclusion criteria. If None, consider all events included.

  • station (str) – Station code to consider

  • phase (str) – Phase type to consider (P or S)

  • events – Event IDs on that station

  • return_not (bool) – Instead, return events that are excluded

  • return_bool (bool) – Return boolean array (not an index array)

  • events_ (list[int])

Returns:

  • ievs – Indices into events of included (or excluded if return_not=True) events

  • evns – Global event IDs of included (or excluded if return_not=True) events

relmt.qc.index_high_value(values, threshold, return_not=False, return_bool=False)[source]#

Return indices of events with value above threshold

Parameters:
  • values (ndarray) – Vector to investigate

  • threshold (float) – Value above which to return the corresponding index

  • return_not (bool) – Instead, return low values

  • return_bool (bool) – Return boolean index array (not an index array)

Returns:

ndarray – Indices where value is above threshold (or below or equal, if reutrn_not=True)

relmt.qc.index_nonzero_events(array, null_threshold=None, return_not=False, return_bool=False)[source]#

Return indices of events with non-zero and finite data

Parameters:
  • array (ndarray) – Waveform array to investigate

  • null_threshold (float | None) – Consider absolute value at or below as zero.

  • return_not (bool) – Instead, return events with all zero-data

  • return_bool (bool) – Return boolean array (not an index array)

Returns:

ndarray – Indices where array is non-zero (or all-zero if return_not=True)

relmt.qc.reduce_equations(pamps, samps, phd, max_p_equations, max_s_equations, two_s, keep_ev, min_equations, min_stations, max_gap, max_amplitude_misfit, max_s_amplitude_misfit, max_s_sigma1, equation_batches=1)[source]#

Reduce the number of equations based on misfit, redundancy and station coverage

Parameters:
  • pamps (list[P_Amplitude_Ratio]) – List of P-amplitude observations

  • samps (list[S_Amplitude_Ratios]) – List of S-amplitude observations

  • phd (dict[slice(<class ‘str’>, <class ‘relmt.core.Phase’>, None)]) – Phase dictionary with take-off azimuths

  • max_p_equations (int) – Maximum number of P-equations to keep

  • max_s_equations (int) – Maximum number of S-equations to keep

  • two_s (bool) – Count each S observation twice (for the two independent S-wave combinations)

  • keep_ev (list[str]) – List of event IDs to keep, even if they are redundant

  • min_equations (int) – Minimum number of equations requied to keep event

  • min_stations (int) – Minimum number of stations required to keep event

  • max_gap (float) – Maximum allowed azimuthal gap allowed to keep event

  • max_amplitude_misfit (float) – Maximum allowed misfit to keep P-amplitude observations

  • max_s_amplitude_misfit (float) – Maximum allowed misfit to keep S-amplitude observations

  • max_s_sigma1 (float) – Maximum allowed sigma1 to keep S-amplitude observations

  • equation_batches (int) – Reduce equations in batches. Larger number, reduces in smaller batches, which can lead to a more optimal selection of equations, but takes longer.

Returns:

Reduced list of P- and S-amplitude observations