GeoNet FDSN webservice with Obspy demo - Event Service

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.

Getting Started - Import Modules


In [1]:
from obspy import UTCDateTime
from obspy.clients.fdsn import Client as FDSN_Client
from obspy import read_inventory

Define GeoNet FDSN client


In [2]:
client = FDSN_Client("GEONET")

Accessing Earthquake Information

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")


10 Event(s) in Catalog:
2016-11-13T14:04:04.751658Z | -42.525, +173.298 | 5.131960364 M  | automatic
2016-11-13T11:08:18.373685Z | -42.616, +173.024 | 5.353569965 ML | manual
2016-11-13T12:37:43.824883Z | -42.432, +173.401 | 5.177874283 M  | manual
2016-11-13T11:30:25.823361Z | -42.529, +173.241 | 5.003968853 M  | manual
2016-11-13T11:16:10.635361Z | -42.758, +172.783 | 5.615649986 M  | manual
2016-11-13T12:25:55.502906Z | -42.705, +172.867 | 5.247682182 M  | manual
2016-11-13T11:09:06.935616Z | -42.612, +172.950 | 5.171948117 M  | manual
2016-11-13T11:02:56.346094Z | -42.693, +173.022 | 7.820379733 Mw(mB) | manual
2016-11-14T00:34:22.558475Z | -42.558, +173.324 | 6.261225536 M  | manual
2016-11-13T22:19:32.961377Z | -42.391, +173.214 | 5.402676232 M  | automatic

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)


1 Event(s) in Catalog:
2016-11-13T11:02:56.346094Z | -42.693, +173.022 | 7.36346279 MLv | manual

In [9]:
ev = cat[0]
print(ev)


Event:	2016-11-13T11:02:56.346094Z | -42.693, +173.022 | 7.36346279 MLv | manual

	            resource_id: ResourceIdentifier(id="smi:nz.org.geonet/2016p858000")
	             event_type: 'earthquake'
	          creation_info: CreationInfo(agency_id='WEL(GNS_Primary)', author='scevent@akeqp01.geonet.org.nz', creation_time=UTCDateTime(2016, 11, 13, 11, 3, 27, 886738))
	    preferred_origin_id: ResourceIdentifier(id="smi:nz.org.geonet/Origin#20161116052725.210418.52361")
	 preferred_magnitude_id: ResourceIdentifier(id="smi:nz.org.geonet/Magnitude#20161116052734.469407.55057")
	                   ---------
	                  picks: 189 Elements
	             amplitudes: 200 Elements
	                origins: 1 Elements
	             magnitudes: 5 Elements
	     station_magnitudes: 200 Elements

Print out a summary of the information for the preferred origin.


In [10]:
origin = ev.origins[0]
print(origin)


Origin
	        resource_id: ResourceIdentifier(id="smi:nz.org.geonet/Origin#20161116052725.210418.52361")
	               time: UTCDateTime(2016, 11, 13, 11, 2, 56, 346094) [confidence_level=89.99999762, uncertainty=0.3114605068]
	          longitude: 173.0221405 [confidence_level=89.99999762, uncertainty=3.42338418]
	           latitude: -42.6925354 [confidence_level=89.99999762, uncertainty=2.342521173]
	              depth: 15114.45332 [confidence_level=89.99999762, uncertainty=3593.426501]
	          method_id: ResourceIdentifier(id="smi:nz.org.geonet/LOCSAT")
	     earth_model_id: ResourceIdentifier(id="smi:nz.org.geonet/iasp91")
	            quality: OriginQuality(associated_phase_count=189, used_phase_count=94, associated_station_count=186, used_station_count=93, depth_phase_count=0, standard_error=1.822964596, azimuthal_gap=54.98503113, minimum_distance=0.2205573916, maximum_distance=7.640860558, median_distance=5.064006805)
	 origin_uncertainty: OriginUncertainty(horizontal_uncertainty=4.148127853, min_horizontal_uncertainty=2.295905102, max_horizontal_uncertainty=4.900735327, azimuth_max_horizontal_uncertainty=117.76848, confidence_ellipsoid=ConfidenceEllipsoid(semi_major_axis_length=5806.280674, semi_minor_axis_length=2176.32321, semi_intermediate_axis_length=5580.753463, major_axis_plunge=39.01032404, major_axis_azimuth=104.0362728, major_axis_rotation=162.7341686), preferred_description='confidence ellipsoid')
	    evaluation_mode: 'manual'
	  evaluation_status: 'confirmed'
	      creation_info: CreationInfo(agency_id='WEL(GNS_Primary)', author='annak@akeqx01.geonet.org.nz', creation_time=UTCDateTime(2016, 11, 16, 5, 27, 25, 210520))
	               ---------
	           arrivals: 189 Elements

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))


MLv = 7.363463 +/- 0.249774
ML = 7.763918 +/- 0.342303
mB = 7.692600 +/- 0.190699
Mw(mB) = 7.820380 +/- 0.400000 - Preferred magnitude
M = 7.762542

List all arrivals used to locate the earthquake.


In [12]:
print(origin.arrivals[0])
print(ev.picks[0])


Arrival
	   resource_id: ResourceIdentifier(id="smi:nz.org.geonet/Pick#20161113123811.075529.40667#Origin#20161116052725.210418.52361")
	       pick_id: ResourceIdentifier(id="smi:nz.org.geonet/Pick#20161113123811.075529.40667")
	         phase: 'P'
	       azimuth: 320.1345688
	      distance: 0.2203543117
	 time_residual: -0.890264
	   time_weight: 1.0
Pick
	     resource_id: ResourceIdentifier(id="smi:nz.org.geonet/Pick#20161113123811.075529.40667")
	            time: UTCDateTime(2016, 11, 13, 11, 3, 0, 419152)
	     waveform_id: WaveformStreamID(network_code='NZ', station_code='HSES', channel_code='BNN', location_code='20')
	      phase_hint: 'P'
	 evaluation_mode: 'manual'
	   creation_info: CreationInfo(agency_id='WEL(GNS_Primary)', author='salichon@akeqx01.geonet.org.nz', creation_time=UTCDateTime(2016, 11, 13, 12, 38, 11, 75905))

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)


2016-11-13T11:03:00.419152Z HSES 0.2203543117 P -0.890264
2016-11-13T11:03:03.661544Z CECS 0.2215131366 P 2.330498
2016-11-13T11:03:04.626728Z GVZ 0.274985135 P 2.411037
2016-11-13T11:03:05.188344Z WAKC 0.3566833863 P 1.525498
2016-11-13T11:03:06.155570Z KHZ 0.4705592521 P 0.417539
2016-11-13T11:03:09.408392Z AMCZ 0.5548961874 P 2.125621
2016-11-13T11:03:07.638393Z LTZ 0.5588204424 P 0.253331
2016-11-13T11:03:07.700013Z MOLS 0.6289876698 P -0.968559
2016-11-13T11:03:09.930874Z ASHS 0.6601385157 P 0.672006
2016-11-13T11:03:09.696868Z SJFS 0.716382775 P -0.649927
2016-11-13T11:03:11.693722Z KPOC 0.7323739701 P 1.077948
2016-11-13T11:03:12.660948Z SMHS 0.7599150871 P 1.509141
2016-11-13T11:03:12.052532Z OHSS 0.7971165011 P 0.215487
2016-11-13T11:03:12.801353Z NNBS 0.8330405857 P 0.314693
2016-11-13T11:03:12.785751Z MPSS 0.8531910465 P -0.046148
2016-11-13T11:03:13.004158Z DALS 0.8581281208 P 0.089051
2016-11-13T11:03:12.988558Z SACS 0.8664775651 P -0.070406
2016-11-13T11:03:13.563322Z STAS 0.8669197273 P 0.497581
2016-11-13T11:03:13.525456Z HHSS 0.9199735504 P -0.445274
2016-11-13T11:03:14.751405Z HUNS 0.9259477939 P 0.680762
2016-11-13T11:03:13.023198Z THZ 0.9340822023 P -1.184325
2016-11-13T11:03:14.813361Z OXZ 0.9584892308 P 0.159378
2016-11-13T11:03:14.096188Z RDCS 1.029032804 P -1.772476
2016-11-13T11:03:16.208382Z OKCZ 1.031074393 P 0.351306
2016-11-13T11:03:15.678398Z MQZ 1.048513991 P -0.480021
2016-11-13T11:03:32.682688Z MQZ 1.048513991 S 2.063296
2016-11-13T11:03:17.693129Z INZ 1.159989466 P -0.353515
2016-11-13T11:03:18.048388Z BSWZ 1.164270388 P -0.017894
2016-11-13T11:04:04.038394Z WATZ 4.48255132 P 0.374367
2016-11-13T11:04:02.968388Z ARHZ 4.555322735 P -1.750663
2016-11-13T11:04:03.353127Z NMHZ 4.593566012 P -1.880129
2016-11-13T11:04:07.118392Z WHTZ 4.60018565 P 1.832881
2016-11-13T11:04:04.048392Z MRHZ 4.636222848 P -1.75075
2016-11-13T11:04:11.368391Z POIZ 4.659697051 P 5.263987
2016-11-13T11:04:11.658391Z THQ2 4.677982505 P 5.297726
2016-11-13T11:04:10.468391Z ARAZ 4.694428876 P 3.884372
2016-11-13T11:04:06.538392Z SYZ 4.733693963 P -0.632041
2016-11-13T11:04:07.368392Z TLZ 4.763372525 P -0.138923
2016-11-13T11:04:06.608390Z MTHZ 4.806288451 P -1.541351
2016-11-13T11:04:06.698402Z WHHZ 4.816871884 P -1.616553
2016-11-13T11:04:07.038388Z ALRZ 4.837754935 P -1.519531
2016-11-13T11:04:06.433130Z WHZ 4.839242842 P -2.237686
2016-11-13T11:04:06.678390Z RAHZ 4.869376797 P -2.348056
2016-11-13T11:04:10.078388Z GRRZ 4.935687007 P 0.187887
2016-11-13T11:04:10.758392Z HRRZ 4.964305637 P 0.468579
2016-11-13T11:04:11.288391Z HSRZ 5.018998521 P 0.250539
2016-11-13T11:04:09.843152Z DCZ 5.043634112 P -1.67152
2016-11-13T11:04:10.193053Z RTZ 5.062340218 P -1.471911
2016-11-13T11:04:10.468397Z KNZ 5.08285016 P -1.514004
2016-11-13T11:04:10.138393Z MUGZ 5.085235628 P -1.830306
2016-11-13T11:04:11.378391Z RRRZ 5.098106214 P -0.755212
2016-11-13T11:04:15.738388Z HLRZ 5.111302223 P 3.430811
2016-11-13T11:04:10.508390Z MHGZ 5.11244782 P -1.892735
2016-11-13T11:04:13.528386Z UTU 5.119709141 P 1.112
2016-11-13T11:04:14.138394Z NGRZ 5.184129761 P 0.839169
2016-11-13T11:04:13.808393Z TARZ 5.184344555 P 0.493152
2016-11-13T11:04:14.708396Z OMRZ 5.24683766 P 0.542219
2016-11-13T11:04:19.868394Z MKRZ 5.254246147 P 5.596707
2016-11-13T11:04:14.778393Z KARZ 5.277128608 P 0.202127
2016-11-13T11:04:14.918399Z TOZ 5.309985204 P -0.08235
2016-11-13T11:04:15.488395Z KMRZ 5.333403637 P 0.152048
2016-11-13T11:04:19.338391Z LIRZ 5.342608051 P 3.858984
2016-11-13T11:04:13.378391Z RAGZ 5.359544995 P -2.380605
2016-11-13T11:04:16.308393Z EDRZ 5.387954622 P 0.192506
2016-11-13T11:04:13.568399Z URZ 5.413912676 P -2.920318
2016-11-13T11:04:15.738394Z APZ 5.466244266 P -1.526483
2016-11-13T11:04:18.778393Z MARZ 5.467896548 P 1.569812
2016-11-13T11:04:17.598391Z TGRZ 5.54465192 P -0.645315
2016-11-13T11:04:16.838394Z OPRZ 5.545902566 P -1.434131
2016-11-13T11:04:20.328390Z WHRZ 5.698334151 P -0.050931
2016-11-13T11:04:18.998381Z PYZ 5.704340173 P -1.592519
2016-11-13T11:04:20.058388Z CNGZ 5.761368662 P -1.246882
2016-11-13T11:04:22.298393Z AWAZ 5.764202962 P 1.091145
2016-11-13T11:04:22.287396Z MKAZ 5.823787929 P 0.251993
2016-11-13T11:04:24.618393Z WTAZ 5.881755408 P 1.800809
2016-11-13T11:04:20.187619Z TWGZ 5.882888541 P -2.769235
2016-11-13T11:04:20.828392Z RUGZ 5.909145714 P -2.472276
2016-11-13T11:04:24.238391Z ETAZ 5.922248823 P 0.858694
2016-11-13T11:04:24.228392Z MYRZ 5.946517804 P 0.478096
2016-11-13T11:04:25.618389Z EPAZ 5.965247577 P 1.65306
2016-11-13T11:04:26.688393Z HBAZ 5.987734956 P 2.41506
2016-11-13T11:04:26.188395Z RVAZ 6.042053902 P 1.173253
2016-11-13T11:04:26.233129Z WIZ 6.068155267 P 0.777875
2016-11-13T11:04:26.788394Z MBAZ 6.096397302 P 1.02223
2016-11-13T11:04:23.208392Z PUZ 6.101134188 P -2.751831
2016-11-13T11:04:23.518402Z HAZ 6.127859238 P -2.782843
2016-11-13T11:04:23.979997Z PKGZ 6.176714947 P -3.005581
2016-11-13T11:04:28.928392Z ABAZ 6.24927077 P 1.068295
2016-11-13T11:04:27.958393Z KUZ 6.29820074 P -0.594019
2016-11-13T11:04:29.728393Z MXZ 6.527414021 P -2.070386
2016-11-13T11:04:34.018388Z GRZ 6.710236166 P -0.172106
2016-11-13T11:04:38.958393Z WCZ 6.830733982 P 3.138666
2016-11-13T11:04:46.508399Z OUZ 7.486108874 P 1.718945
2016-11-13T11:04:46.418385Z CTZ 7.617394075 P -0.603462