This demo introduces some simple code that requests data using GeoNet's FDSN webservices and the obspy module in python. This notebook uses Python 3.
In [1]:
from obspy import UTCDateTime
from obspy.clients.fdsn import Client as FDSN_Client
from obspy import read_inventory
In [2]:
client = FDSN_Client("GEONET")
Use the event service to access earthquake parameters from the catalogue.
This example requests the Kaikoura earthquake and aftershocks for 24 hours following the event, within a 0.5 degree radius of the epicenter. It then prints a list and plots the locations on a map
In [3]:
starttime = "2016-11-13 11:00:00.000"
endtime = "2016-11-14 11:00:00.000"
cat = client.get_events(starttime=starttime, endtime=endtime,latitude=-42.693,longitude=173.022,maxradius=0.5,minmagnitude=5)
print(cat)
_=cat.plot(projection="local")
Single events can be requested using their PublicID, which is available from the GeoNet website. This example will demonstrate how to get additional information about the Kaikoura Earthquake.
In [4]:
cat = client.get_events(eventid="2016p858000")
print(cat)
In [9]:
ev = cat[0]
print(ev)
Print out a summary of the information for the preferred origin.
In [10]:
origin = ev.origins[0]
print(origin)
List all available magnitudes and their associated uncertainties
In [11]:
for m in range(len(ev.magnitudes)):
if 'uncertainty' in ev.magnitudes[m].mag_errors and ev.magnitudes[m].mag_errors['uncertainty'] != None and ev.magnitudes[m].resource_id == ev.preferred_magnitude_id:
print('%s = %f +/- %f - Preferred magnitude' % (ev.magnitudes[m].magnitude_type, ev.magnitudes[m].mag, ev.magnitudes[m].mag_errors['uncertainty']))
elif 'uncertainty' in ev.magnitudes[m].mag_errors and ev.magnitudes[m].mag_errors['uncertainty'] != None:
print('%s = %f +/- %f' % (ev.magnitudes[m].magnitude_type, ev.magnitudes[m].mag, ev.magnitudes[m].mag_errors['uncertainty']))
else:
print('%s = %f' % (ev.magnitudes[m].magnitude_type, ev.magnitudes[m].mag))
List all arrivals used to locate the earthquake.
In [12]:
print(origin.arrivals[0])
print(ev.picks[0])
In [13]:
for p in range(len(ev.picks)):
for a in range(len(origin.arrivals)):
if ev.picks[p].resource_id == origin.arrivals[a].pick_id:
if origin.arrivals[a].time_weight > 0:
print(ev.picks[p].time, ev.picks[p].waveform_id['station_code'], origin.arrivals[a].distance, origin.arrivals[a].phase, origin.arrivals[a].time_residual)