Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix more network tests #2980

Merged
merged 6 commits into from Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion obspy/clients/fdsn/mass_downloader/utils.py
Expand Up @@ -12,6 +12,7 @@
import fnmatch
import itertools
import os
from http.client import HTTPException
from socket import timeout as socket_timeout
from urllib.error import HTTPError, URLError

Expand All @@ -28,7 +29,8 @@

# Different types of errors that can happen when downloading data via the
# FDSN clients.
ERRORS = (FDSNException, HTTPError, URLError, socket_timeout, ConnectionError)
ERRORS = (ConnectionError, FDSNException, HTTPError, HTTPException, URLError,
socket_timeout, )

# mean earth radius in meter as defined by the International Union of
# Geodesy and Geophysics. Used for the spherical kd-tree.
Expand Down
5 changes: 3 additions & 2 deletions obspy/clients/iris/client.py
Expand Up @@ -480,7 +480,7 @@ def sacpz(self, network, station, location="*", channel="*",
>>> client = Client()
>>> dt = UTCDateTime("2005-01-01")
>>> sacpz = client.sacpz("IU", "ANMO", "00", "BHZ", dt)
>>> print(sacpz.decode()) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
>>> print(sacpz.decode()) # doctest: +SKIP
* **********************************
* NETWORK (KNETWK): IU
* STATION (KSTNM): ANMO
Expand Down Expand Up @@ -509,7 +509,8 @@ def sacpz(self, network, station, location="*", channel="*",
+0.000000e+00 +0.000000e+00
POLES 5 ...
CONSTANT 6.985619e+13
<BLANKLINE> ...
<BLANKLINE>
...
"""
kwargs['network'] = str(network)
kwargs['station'] = str(station)
Expand Down
18 changes: 10 additions & 8 deletions obspy/clients/iris/tests/data/IU.ANMO.00.BHZ.sacpz
Expand Up @@ -7,8 +7,8 @@
* START : 2002-11-19T21:07:00
* END : 2008-06-30T00:00:00
* DESCRIPTION : Albuquerque, New Mexico, USA
* LATITUDE : 34.945980
* LONGITUDE : -106.457130
* LATITUDE : 34.945981
* LONGITUDE : -106.457133
* ELEVATION : 1671.0
* DEPTH : 145.0
* DIP : 0.0
Expand All @@ -19,19 +19,21 @@
* INSTTYPE : Geotech KS-54000 Borehole Seismometer
* INSTGAIN : 1.935000e+03 (M/S)
* COMMENT :
* SENSITIVITY : 8.115970e+08 (M/S)
* A0 : 8.608300e+04
* SENSITIVITY : 8.115480e+08 (M/S)
* A0 : 8.607770e+04
* **********************************
ZEROS 3
+0.000000e+00 +0.000000e+00
+0.000000e+00 +0.000000e+00
+0.000000e+00 +0.000000e+00
POLES 5
-5.943130e+01 +0.000000e+00
-2.271210e+01 +2.710650e+01
-2.271210e+01 -2.710650e+01
-4.800400e-03 +0.000000e+00
-7.319900e-02 +0.000000e+00
CONSTANT 6.986470e+13
-2.271210e+01 -2.710650e+01
-2.271210e+01 +2.710650e+01
-5.943130e+01 +0.000000e+00
CONSTANT 6.985619e+13




29 changes: 15 additions & 14 deletions obspy/clients/iris/tests/test_client.py
Expand Up @@ -44,11 +44,11 @@ def test_sacpz(self):
dt = UTCDateTime("2002-11-01")
result = client.sacpz('UW', 'LON', '', 'BHZ', dt)
self.assertIn(b"* STATION (KSTNM): LON", result)
self.assertIn(b"* LOCATION (KHOLE): ", result)
self.assertIn(b"* LOCATION (KHOLE):", result)
# 3 - empty location code via '--'
result = client.sacpz('UW', 'LON', '--', 'BHZ', dt)
self.assertIn(b"* STATION (KSTNM): LON", result)
self.assertIn(b"* LOCATION (KHOLE): ", result)
self.assertIn(b"* LOCATION (KHOLE):", result)

def test_distaz(self):
"""
Expand Down Expand Up @@ -183,7 +183,7 @@ def test_evalresp(self):
filename=tempfile)
with open(tempfile, 'rt') as fp:
self.assertEqual(fp.readline(),
'1.000000E-05 1.055999E+04 1.792007E+02\n')
'1.000000E-05 1.055934E+04 1.792007E+02\n')
# fap & dis as ASCII file
with NamedTemporaryFile() as tf:
tempfile = tf.name
Expand All @@ -192,7 +192,7 @@ def test_evalresp(self):
filename=tempfile)
with open(tempfile, 'rt') as fp:
self.assertEqual(fp.readline(),
'1.000000E-05 6.635035E-01 2.692007E+02\n')
'1.000000E-05 6.634627E-01 2.692007E+02\n')
# fap & vel as ASCII file
with NamedTemporaryFile() as tf:
tempfile = tf.name
Expand All @@ -201,7 +201,7 @@ def test_evalresp(self):
filename=tempfile)
with open(tempfile, 'rt') as fp:
self.assertEqual(fp.readline(),
'1.000000E-05 1.055999E+04 1.792007E+02\n')
'1.000000E-05 1.055934E+04 1.792007E+02\n')
# fap & acc as ASCII file
with NamedTemporaryFile() as tf:
tempfile = tf.name
Expand All @@ -210,17 +210,17 @@ def test_evalresp(self):
filename=tempfile)
with open(tempfile, 'rt') as fp:
self.assertEqual(fp.readline(),
'1.000000E-05 1.680674E+08 8.920073E+01\n')
'1.000000E-05 1.680571E+08 8.920073E+01\n')
# fap as NumPy ndarray
data = client.evalresp(network="IU", station="ANMO", location="00",
channel="BHZ", time=dt, output='fap')
np.testing.assert_array_equal(
data[0], [1.00000000e-05, 1.05599900e+04, 1.79200700e+02])
data[0], [1.00000000e-05, 1.05593400e+04, 1.79200700e+02])
# cs as NumPy ndarray
data = client.evalresp(network="IU", station="ANMO", location="00",
channel="BHZ", time=dt, output='cs')
np.testing.assert_array_equal(
data[0], [1.00000000e-05, -1.05589600e+04, 1.47305400e+02])
data[0], [1.00000000e-05, -1.05583100e+04, 1.472963e+02])

def test_resp(self):
"""
Expand All @@ -234,14 +234,15 @@ def test_resp(self):
t2 = UTCDateTime("2008-001T00:00:00")
result = client.resp("IU", "ANMO", "00", "BHZ", t1, t2)
self.assertIn(b'B050F03 Station: ANMO', result)
# Exception: No response data available
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe choose a different response so that we can still test this part of the code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still two requests left...

The site from which examples were taken still mentions this query. Maybe we can use this one.

# 2 - empty location code
result = client.resp("UW", "LON", "", "EHZ")
self.assertIn(b'B050F03 Station: LON', result)
self.assertIn(b'B052F03 Location: ??', result)
# result = client.resp("UW", "LON", "", "EHZ")
# self.assertIn(b'B050F03 Station: LON', result)
# self.assertIn(b'B052F03 Location: ??', result)
# 3 - empty location code via '--'
result = client.resp("UW", "LON", "--", "EHZ")
self.assertIn(b'B050F03 Station: LON', result)
self.assertIn(b'B052F03 Location: ??', result)
# result = client.resp("UW", "LON", "--", "EHZ")
# self.assertIn(b'B050F03 Station: LON', result)
# self.assertIn(b'B052F03 Location: ??', result)
# 4
dt = UTCDateTime("2010-02-27T06:30:00.000")
result = client.resp("IU", "ANMO", "*", "*", dt)
Expand Down
24 changes: 9 additions & 15 deletions obspy/clients/seedlink/tests/test_basic_client.py
Expand Up @@ -20,21 +20,15 @@ def setUp(self):
def test_get_waveform(self):
def _test_offset_from_realtime(offset):
t = UTCDateTime() - offset
for request in [["G", "FDFM", "00", "LHN", t, t + 20],
["G", "CLF", "00", "BHZ", t, t + 10]]:
st = self.client.get_waveforms(*request)
self.assertGreater(len(st), 0)
for tr in st:
self.assertEqual(tr.id, ".".join(request[:4]))
self.assertTrue(any([len(tr) > 0 for tr in st]))
st.merge(1)
self.assertTrue(abs(tr.stats.starttime - request[4]) < 1)
self.assertTrue(abs(tr.stats.endtime - request[5]) < 1)
for tr in st:
self.assertEqual(tr.stats.network, request[0])
self.assertEqual(tr.stats.station, request[1])
self.assertEqual(tr.stats.location, request[2])
self.assertEqual(tr.stats.channel, request[3])
request = ["G", "FDFM", "00", "LHN", t, t + 20]
st = self.client.get_waveforms(*request)
self.assertGreater(len(st), 0)
for tr in st:
self.assertEqual(tr.id, ".".join(request[:4]))
self.assertTrue(any([len(tr) > 0 for tr in st]))
st.merge(1)
self.assertTrue(abs(tr.stats.starttime - request[4]) < 1)
self.assertTrue(abs(tr.stats.endtime - request[5]) < 1)

# getting a result depends on two things.. how long backwards the ring
# buffer stores data and how close to realtime the data is available,
Expand Down