<jupyter_start><jupyter_text>GeoNet FDSN webservice with Obspy demo - GeoNet FDSN Clients In this tutorial we will look at how to get both near real-time and archiv waveform data. By the end of this notebook you will will be be able to get both data sets and output something like the text below1 Trace(s) in Stream:NZ.WEL.10.HHZ | 2018-11-18T01:20:32.853131Z - 2018-11-21T01:20:35.453131Z | 100.0 Hz, 25920261 samples GeoNet operates two FDNS wave servers- An archive server holds verified data starting 7 days after collection- A near real-time servers holds unverified data for the last 8 daysThere are a few different ways this could be done.   Import Modules and Define Clients<jupyter_code>from obspy.core import UTCDateTime
from obspy.clients.fdsn import Client

arc_client  = 'http://service.geonet.org.nz'
# or arc_client = "GEONET"
nrt_client = 'http://service-nrt.geonet.org.nz'<jupyter_output><empty_output><jupyter_text>Option 1: By trialYou will need to specify the correct wave server to get the data you want. If you try to get data from one server and that raises an exception (because the data you requested are not available) repeat the request with the other server.<jupyter_code>t = UTCDateTime('2017-10-04')

#first try to get data from archive server
try:
    client = Client(arc_client)
    st = client.get_waveforms('NZ', 'KRVZ', '10', 'EHZ', t, t + 300)
    print('arc client successful')
#if this raises an exception, try the near real-time server
except:
    client = Client(nrt_client)
    st = client.get_waveforms('NZ', 'KRVZ', '10', 'EHZ', t, t + 300)
    print('nrt client successful')
print(st)<jupyter_output>arc client successful
1 Trace(s) in Stream:
NZ.KRVZ.10.EHZ | 2017-10-03T23:59:59.283134Z - 2017-10-04T00:05:03.523134Z | 100.0 Hz, 30425 samples<jupyter_text>Option 2: Use the time range to select clientUse the time range to select a client, if the time range requires both clients then use Option 3.<jupyter_code>starttime = UTCDateTime.now()-518400 #6 days ago
endtime = starttime+300

days7 = UTCDateTime.now()-604800 #7 days ago
days8 = UTCDateTime.now()-691200 #8 days ago

if endtime < days7:
    client = Client(arc_client)
    print("Client is archive client")
elif starttime > days8:
    client = Client(nrt_client)
    print("Client is near real-time client")
else:
    print("Time range requires both clients")
    
st = client.get_waveforms('NZ', 'WEL', '10', 'HHZ', starttime, endtime)
print(st)<jupyter_output>Client is near real-time client
1 Trace(s) in Stream:
NZ.WEL.10.HHZ | 2018-11-21T01:20:32.283128Z - 2018-11-21T01:25:33.283128Z | 100.0 Hz, 30101 samples<jupyter_text>Option 3: Request from both clients and mergeThis is useful if the time window for the data request spans both time periods.First, request data from both clients<jupyter_code>#Define time period
t1 = UTCDateTime.now()-777600 #9 days ago
t2 = UTCDateTime.now()-518400 #6 days ago

#nrt client
try:
    client = Client(nrt_client)
    stnrt = client.get_waveforms('NZ', 'WEL', '10', 'HHZ', t1, t2)
    print('nrt client successful')
except:
    print('nrt client not successful')

#arc client
try:
    client = Client(arc_client)
    starc = client.get_waveforms('NZ', 'WEL', '10', 'HHZ', t1, t2)
    print('arc client successful')
except:
    print('arc client not successful')
print(stnrt,starc)<jupyter_output>nrt client successful
arc client successful
(<obspy.core.stream.Stream object at 0x0000000007DCD4A8>, <obspy.core.stream.Stream object at 0x000000000C619470>)<jupyter_text>Now merge waveforms into a single stream object.<jupyter_code>st = stnrt
st += starc
st.merge(fill_value = 'interpolate')
print(st)<jupyter_output>1 Trace(s) in Stream:
NZ.WEL.10.HHZ | 2018-11-18T01:20:32.853131Z - 2018-11-21T01:20:35.453131Z | 100.0 Hz, 25920261 samples
{'fraction_non_alphanumeric': 0.10398522037476907, 'fraction_numerical': 0.08471892319873317, 'mean_word_length': 4.768645357686453, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '188246', 'license': 'Apache-2.0', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1303, 'n_words': 428, 'path': 'Seismic_Data/Python/GeoNet_FDSN_demo_clients.ipynb', 'repo_name': 'megankortink/data-tutorials', 'size': '3789'}