Magnitude
Magnitude estimation methods.
mag module
Magnitude calculation utilities for local magnitude (Ml) and moment magnitude (Mw) estimation.
This module provides tools for:
Selecting waveform streams according to channel/location preferences.
Calculating local magnitude (Ml).
Calculating moment magnitude (Mw).
Managing waveform retrieval and response selection.
The implementation is based partially on:
- author:
Emmanuel Castillo
- copyright:
Lion Krischer (2012)
- license:
Original concepts adapted from ObsPy-based implementations.
Example
>>> from obspy.core.event import read_events
>>> catalog = read_events("catalog.xml")
>>> magnitude = Magnitude(providers, catalog, "./output")
- class SeisMonitor.monitor.magnitude.mag.Magnitude(providers, catalog, out_dir)[source]
Bases:
objectMagnitude calculator for seismic events.
- Parameters:
providers (list) – List of waveform providers.
catalog (str or obspy.Catalog) – Catalog object or path to QuakeML file.
out_dir (str) – Output directory for generated magnitude files.
- get_Ml(mag_type='RSNC', trimmedtime=50, padding=20, waterlevel=10, zone=None, out_format='QUAKEML')[source]
Calculate local magnitude (Ml) for all events.
- Parameters:
mag_type (str, optional) – Magnitude relationship type.
trimmedtime (float, optional) – Signal trimming window in seconds.
padding (float, optional) – Waveform retrieval padding.
waterlevel (float, optional) – Water level for response correction.
zone (str, optional) – Regional magnitude zone.
out_format (str, optional) – Output catalog format.
- Returns:
Updated catalog with Ml magnitudes.
- Return type:
obspy.Catalog
- get_Mw(physparams, procparams, out_format='QUAKEML')[source]
Calculate moment magnitude (Mw).
- Parameters:
physparams (MwPhysicalMagParams) – Physical Mw parameters.
procparams (MwProcessingMagParams) – Signal processing parameters.
out_format (str, optional) – Output format.
- Returns:
Updated catalog with Mw magnitudes.
- Return type:
obspy.Catalog
- class SeisMonitor.monitor.magnitude.mag.MwPhysicalMagParams(vp=4800, vsp_factor=1.73, density=2650.0, waterlevel=10, p_radiation_pattern=0.52, s_radiation_pattern=0.63)[source]
Bases:
objectPhysical parameters used during Mw calculation.
- Parameters:
vp (float, optional) – P-wave velocity in m/s.
vsp_factor (float, optional) – Vp/Vs ratio.
density (float, optional) – Density in kg/m³.
waterlevel (float, optional) – Water level for deconvolution stabilization.
p_radiation_pattern (float, optional) – Radiation pattern coefficient for P waves.
s_radiation_pattern (float, optional) – Radiation pattern coefficient for S waves.
- class SeisMonitor.monitor.magnitude.mag.MwProcessingMagParams(time_before_pick=5, time_after_pick=30, padding=40, only_proc_p_pick=False, only_proc_s_pick=False)[source]
Bases:
object
- SeisMonitor.monitor.magnitude.mag.get_st_according2preference(st, location_list, channel_list)[source]
Select a preferred stream according to location and channel priorities.
The function filters streams first by location preference and then by channel preference.
- Parameters:
st (obspy.Stream) – Input waveform stream.
location_list (list of str) – Preferred locations ordered by priority.
channel_list (list of str) – Preferred channel codes ordered by priority.
- Returns:
Filtered stream according to preferences.
- Return type:
obspy.Stream or None
Example
>>> new_st = get_st_according2preference( ... st, ... ["00", "20"], ... ["HH", "BH"] ... )
utils module
Utilities for seismic magnitude estimation and ObsPy event object creation.
This module provides helper functions for:
Retrieving poles and zeros (PAZ) from ObsPy responses.
Computing local magnitudes (Ml).
Processing waveforms for magnitude estimation.
Fitting seismic source spectra.
Creating ObsPy magnitude and amplitude objects.
- author:
Emmanuel Castillo
- SeisMonitor.monitor.magnitude.utils.Mw_st_processing(st, response, waterlevel, datetime)[source]
Remove instrument response for moment magnitude estimation.
- Parameters:
stream – ObsPy Stream object.
response – ObsPy response object.
water_level – Water level used during deconvolution.
datetime – Datetime associated with traces.
- Returns:
Processed ObsPy Stream or
Noneif failed.
- SeisMonitor.monitor.magnitude.utils.calculate_source_spectrum(frequencies, omega_0, corner_frequency, Q, traveltime)[source]
After Abercrombie (1995) and Boatwright (1980).
Abercrombie, R. E. (1995). Earthquake locations using single-station deep borehole recordings: Implications for microseismicity on the San Andreas fault in southern California. Journal of Geophysical Research, 100, 24003–24013.
Boatwright, J. (1980). A spectral theory for circular seismic sources, simple estimates of source dimension, dynamic stress drop, and radiated energy. Bulletin of the Seismological Society of America, 70(1).
- The used formula is:
Omega(f) = (Omege(0) * e^(-pi * f * T / Q)) / (1 + (f/f_c)^4) ^ 0.5
- Parameters:
frequencies – Input array to perform the calculation on.
omega_0 – Low frequency amplitude in [meter x second].
corner_frequency – Corner frequency in [Hz].
Q – Quality factor.
traveltime – Traveltime in [s].
- SeisMonitor.monitor.magnitude.utils.fit_spectrum(spectrum, frequencies, traveltime, initial_omega_0, initial_f_c, quality_factor=500)[source]
Fit a theoretical source spectrum to a measured source spectrum.
Uses a Levenburg-Marquardt algorithm.
- Parameters:
spectrum – The measured source spectrum.
frequencies – The corresponding frequencies.
initial_omega_0 – Initial guess for Omega_0.
initial_f_c – Initial guess for the corner frequency.
- Para traveltime:
Event traveltime in [s].
- Returns:
Best fits and standard deviations. (Omega_0, f_c, Omega_0_std, f_c_std) Returns None, if the fit failed.
- SeisMonitor.monitor.magnitude.utils.get_M0_magnitude_by_pick(st, picktime, traveltime, phasehint, physparams, procparams)[source]
Estimate seismic moment (M0) from waveform picks.
The function computes multitaper spectra for each component, fits a theoretical source spectrum, and estimates seismic moment.
- Parameters:
stream – ObsPy Stream object containing three-component data.
pick_time – Pick time associated with the phase.
travel_time (float) – Seismic travel time in seconds.
phase_hint (str) – Seismic phase identifier (e.g.
"P"or"S").physical_parameters – Object containing physical properties such as:
vp,vs,density,p_radiation_pattern,s_radiation_pattern.processing_parameters – Object containing processing configuration such as:
time_before_pickandtime_after_pick.
- Returns:
Tuple containing:
Seismic moment (M0)
List of estimated corner frequencies
Returns
(None, None)if estimation fails.- Return type:
Tuple[Optional[float], Optional[List[float]]]
- SeisMonitor.monitor.magnitude.utils.get_Ml(ampl, epi_dist, mag_type, zone=None)[source]
Compute local magnitude (Ml).
Supports predefined empirical relationships or custom functions.
- Parameters:
amplitude (float) – Peak amplitude.
epicentral_distance (float) – Epicentral distance in kilometers.
magnitude_type (Union[str, Callable]) – Magnitude model name or callable.
zone (Optional[int]) – Regional zone identifier.
- Returns:
Computed local magnitude.
- Return type:
float
- SeisMonitor.monitor.magnitude.utils.get_Ml_magparams_by_station(st, response, ev_params, trimmedtime=50, waterlevel=10)[source]
Compute local magnitude (Ml).
Supports predefined empirical relationships or custom functions.
- Parameters:
amplitude (float) – Peak amplitude.
epicentral_distance (float) – Epicentral distance in kilometers.
magnitude_type (Union[str, Callable]) – Magnitude model name or callable.
zone (Optional[int]) – Regional zone identifier.
- Returns:
Computed local magnitude.
- Return type:
float
- SeisMonitor.monitor.magnitude.utils.get_paz_from_response(seed_id, response, datetime=None)[source]
Retrieve poles and zeros (PAZ) from a response object.
Supports both ObsPy
ParserandInventoryresponse types.- Parameters:
seed_id (str) – Full SEED identifier.
response (Union[Parser, Inventory]) – ObsPy response object.
datetime (Optional[UTCDateTime]) – Datetime associated with waveform trace.
- Returns:
Dictionary containing PAZ information or
Noneif unavailable.- Return type:
Optional[Dict]
Example
>>> paz = get_paz_from_response("IU.ANMO..BHZ", inventory)
- SeisMonitor.monitor.magnitude.utils.write_amplitude_values(value, amp_type='A', category='duration', unit='m/s', method_id='https://docs.obspy.org/tutorial/advanced_exercise/advanced_exercise_solution_3b.html', time_window=obspy.core.event.base.TimeWindow, pick_id=obspy.core.event.resourceid.ResourceIdentifier, waveform_id=obspy.core.event.base.WaveformStreamID, magnitude_hint='M', evaluation_mode='automatic', evaluation_status='preliminary', agency=None)[source]
Create an ObsPy Amplitude object.
- Parameters:
value (float) – Measured amplitude value.
- Returns:
ObsPy Amplitude object.
- Return type:
Amplitude
- SeisMonitor.monitor.magnitude.utils.write_magnitude_values(value, uncertainty, station_count, mag_type, evaluation_mode='automatic', evaluation_status='preliminary', method_id=obspy.core.event.resourceid.ResourceIdentifier, agency=None, origin_id=obspy.core.event.resourceid.ResourceIdentifier, comments=None)[source]
Create an ObsPy Magnitude object.
- Parameters:
value (float) – Magnitude value.
uncertainty (float) – Magnitude uncertainty.
station_count (int) – Number of stations used.
magnitude_type (str) – Magnitude type (e.g.
"Mw","Ml").comments (Optional[str]) – Optional comments associated with the magnitude.
- Returns:
ObsPy Magnitude object.
- Return type:
- SeisMonitor.monitor.magnitude.utils.write_magsta_values(value, uncertainty, mag_type, origin_id=obspy.core.event.resourceid.ResourceIdentifier, amplitude_id=obspy.core.event.resourceid.ResourceIdentifier, method_id=obspy.core.event.resourceid.ResourceIdentifier, waveform_id=obspy.core.event.base.WaveformStreamID, agency=None)[source]
Create an ObsPy StationMagnitude object.
- Parameters:
value (float) – Station magnitude value.
uncertainty (float) – Magnitude uncertainty.
magnitude_type (str) – Magnitude type (e.g.
"Ml").
- Returns:
ObsPy StationMagnitude object.
- Return type:
StationMagnitude