Earthquake catalog

Pyrocko provides access to some online earthquake catalogs via the pyrocko.client.catalog module.

QuakeML import

This example shows how to read QuakeML <https://quake.ethz.ch/quakeml/docs/REC?action=AttachFile&do=get&target=QuakeML-BED-20130214b.pdf> event catalogs using QuakeML_load_xml(). The function get_pyrocko_events() is used to obtain events in pyrocko format. If a moment tensor is provided as [Mrr, Mtt, Mpp, Mrt, Mrp, Mtp], this is converted to [mnn, mee, mdd, mne, mnd, med]. The strike, dip and rake values appearing in the pyrocko event are calculated from the moment tensor.

from pyrocko import model
from pyrocko.io import quakeml
from pyrocko.example import get_example_data


# small catalog containing two events (data from ingv):
catalog = get_example_data('example-catalog.xml')

# read quakeml events
qml = quakeml.QuakeML.load_xml(filename=catalog)

# get pyrocko events
events = qml.get_pyrocko_events()

for event in events:
    print(event)

# save events as pyrocko catalog:
model.event.dump_events(events, filename='test_pyrocko.pf')

Creating QuakeML from scratch

from pyrocko.io import quakeml as q
from pyrocko.util import str_to_time as stt


table = [
    # name     time                        lat  lon   depth    mag
    ('ev0001', stt('2021-09-29 01:02:03'), 55., 120., 11000.,  5.5),
    ('ev0002', stt('2021-09-29 04:05:06'), 57., 122., 9000.,  4.0),
    ('ev0003', stt('2021-09-29 07:08:09'), 56., 121., 1200.,  4.1)]


qml = q.QuakeML(
    event_parameters=q.EventParameters(
        public_id='quakeml:test/eventParameters/test',
        event_list=[
            q.Event(
                preferred_origin_id='quakeml:test/origin/%s' % name,
                preferred_magnitude_id='quakeml:test/magnitude/%s' % name,
                public_id='quakeml:test/event/%s' % name,
                origin_list=[
                    q.Origin(
                        public_id='quakeml:test/origin/%s' % name,
                        time=q.TimeQuantity(value=time),
                        longitude=q.RealQuantity(value=lon),
                        latitude=q.RealQuantity(value=lat),
                        depth=q.RealQuantity(value=depth),
                    ),
                ],
                magnitude_list=[
                    q.Magnitude(
                        public_id='quakeml:test/magnitude/%s' % name,
                        origin_id='quakeml:test/origin/%s' % name,
                        mag=q.RealQuantity(value=magnitude),
                    )
                ],
            )
            for (name, time, lat, lon, depth, magnitude) in table
        ]
    )
)

print(qml.dump_xml())

Searching the GlobalCMT catalog

This example demonstrates how to query the GlobalCMT [1] database for events which occurred in 2011 in northern Chile.

from pyrocko import util, model
from pyrocko.client import catalog

tmin = util.str_to_time('2011-01-01 00:00:00')  # beginning time of query
tmax = util.str_to_time('2011-12-31 23:59:59')

# create an instance of the global CMT catalog
global_cmt_catalog = catalog.GlobalCMT()

# query the catalog
events = global_cmt_catalog.get_events(
    time_range=(tmin, tmax),
    magmin=2.,
    latmin=-35.,
    latmax=-20.,
    lonmin=-76.,
    lonmax=-65.)

print('Downloaded %s events' % len(events))
print('The last one is:')
print(events[-1])

# dump events to catalog
model.dump_events(events, 'northern_chile_events.txt')

Download catalog_search_globalcmt.py

We expect to see the following output:

Downloaded 53 events
The last one is
--- !pf.Event
lat: -28.03
lon: -71.55
time: 2011-12-07 22:23:14.250000
name: 201112072223A
depth: 22800.0
magnitude: 6.106838394015895
region: NEAR COAST OF NORTHERN C
catalog: gCMT
moment_tensor: !pf.MomentTensor
  mnn: 1.16e+17
  mee: -1.24e+18
  mdd: 1.1200000000000001e+18
  mne: 1.29e+17
  mnd: 1.61e+17
  med: 1.0900000000000001e+18
  strike1: 16.540029329929244
  dip1: 24.774772153067424
  rake1: 109.14904335232158
  strike2: 175.61123518070136
  dip2: 66.6800337700307
  rake2: 81.39111828783355
  moment: 1.622772319211786e+18
  magnitude: 6.106838394015895
duration: 5.4

Search for an event in Geofon catalog

Search for an event name only in the Geofon catalog [2] using Geofon(), with a given magnitude range and timeframe.

from pyrocko import util
from pyrocko.client import catalog

tmin = util.ctimegm('2010-01-12 21:50:00')
tmax = util.ctimegm('2010-01-13 03:17:00')  # ending time of query
mag = 6.                                    # minimum magntiude (open end)

# download event information from GEOFON web page

geofon = catalog.Geofon()
event_names = geofon.get_event_names(
    time_range=(tmin, tmax),
    magmin=mag)

for event_name in event_names:
    event = geofon.get_event(event_name)
    print(event)

Download catalog_search_geofon.py

We expect to see the following output (in YAML format):

--- !pf.Event
lat: 18.37
lon: -72.55
time: 2010-01-12 21:53:11
name: gfz2010avtm
depth: 17000.0
magnitude: 7.2
region: Haiti Region
catalog: GEOFON

Footnotes