/
test_client.py
96 lines (87 loc) · 3.6 KB
/
test_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# -*- coding: utf-8 -*-
"""
The obspy.neic.client test suite.
"""
from obspy.core.utcdatetime import UTCDateTime
from obspy.neic import Client
import unittest
class ClientTestCase(unittest.TestCase):
"""
Test cases for obspy.neic.client.Client.
"""
def test_getWaveform(self):
"""
Tests getWaveform method. Tests against getWaveformNSCL method.
"""
client = Client(host="137.227.224.97", port=2061)
# now - 5 hours
t = UTCDateTime() - 5 * 60 * 60
duration = 1.0
st = client.getWaveformNSCL("IUANMO BH.00", t, duration)
# try a series of requests, compare against getWaveformNSCL
args = [["IU", "ANMO", "00", "BH."],
["??", "ANMO", "0?", "BH[Z21]"],
["IU", "ANM.*", "00", "B??"],
["IU", "ANMO", "0*", "BH."],
]
for args_ in args:
st2 = client.getWaveform(*args_, starttime=t, endtime=t + duration)
self.assertTrue(st == st2)
def test_getWaveformNSCL(self):
"""
Tests getWaveformNSCL method.
"""
client = Client(host="137.227.224.97", port=2061)
# now - 5 hours
t = UTCDateTime() - 5 * 60 * 60
duration_long = 3600.0
duration = 1.0
components = ["1", "2", "Z"]
# try one longer request to see if fetching multiple blocks works
st = client.getWaveformNSCL("IUANMO BH.00", t, duration_long)
# merge to avoid failing tests simply due to gaps
st.merge()
st.sort()
self.assertTrue(len(st) == 3)
for tr, component in zip(st, components):
stats = tr.stats
self.assertTrue(stats.station == "ANMO")
self.assertTrue(stats.network == "IU")
self.assertTrue(stats.location == "00")
self.assertTrue(stats.channel == "BH" + component)
self.assertTrue(stats.endtime - stats.starttime == duration_long)
# if the following fails this is likely due to a change at the
# requested station and simply has to be adapted
self.assertTrue(stats.sampling_rate == 20.0)
self.assertTrue(len(tr) == 72001)
# now use shorter piece, this is faster and less error prone (gaps etc)
st = client.getWaveformNSCL("IUANMO BH.00", t, duration)
st.sort()
# test returned stream
self.assertTrue(len(st) == 3)
for tr, component in zip(st, components):
stats = tr.stats
self.assertTrue(stats.station == "ANMO")
self.assertTrue(stats.network == "IU")
self.assertTrue(stats.location == "00")
self.assertTrue(stats.channel == "BH" + component)
self.assertTrue(stats.endtime - stats.starttime == duration)
# if the following fails this is likely due to a change at the
# requested station and simply has to be adapted
self.assertTrue(stats.sampling_rate == 20.0)
self.assertTrue(len(tr) == 21)
# try a series of regex patterns that should return the same data
st = client.getWaveformNSCL("IUANMO BH", t, duration)
patterns = ["IUANMO BH...",
"IUANMO BH.*",
"IUANMO BH[Z12].*",
"IUANMO BH[Z12]..",
"IUANMO B.*",
"..ANMO B.*"]
for pattern in patterns:
st2 = client.getWaveformNSCL(pattern, t, duration)
self.assertTrue(st == st2)
def suite():
return unittest.makeSuite(ClientTestCase, 'test')
if __name__ == '__main__':
unittest.main(defaultTest='suite')