/
test_channel.py
143 lines (131 loc) · 5.32 KB
/
test_channel.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Test suite for the channel handling.
:copyright:
Lion Krischer (krischer@geophysik.uni-muenchen.de), 2013
:license:
GNU Lesser General Public License, Version 3
(https://www.gnu.org/copyleft/lesser.html)
"""
import pytest
from matplotlib import rcParams
from obspy import read_inventory
from obspy.core.inventory import Channel, Equipment
from obspy.core.util.testing import WarningsCapture
@pytest.mark.usefixtures('ignore_numpy_errors')
class TestChannel:
"""
Tests the for :class:`~obspy.core.inventory.channel.Channel` class.
"""
def test_response_plot(self, image_path):
"""
Tests the response plot.
"""
cha = read_inventory()[0][0][0]
with WarningsCapture():
rcParams['savefig.dpi'] = 72
cha.plot(0.005, outfile=image_path)
def test_channel_str(self):
"""
Tests the __str__ method of the channel object.
"""
c = Channel(code="BHE", location_code="10", latitude=1, longitude=2,
elevation=3, depth=4, azimuth=5, dip=6)
assert str(c) == (
"Channel 'BHE', Location '10' \n"
"\tTime range: -- - --\n"
"\tLatitude: 1.0000, Longitude: 2.0000, Elevation: 3.0 m, "
"Local Depth: 4.0 m\n"
"\tAzimuth: 5.00 degrees from north, clockwise\n"
"\tDip: 6.00 degrees down from horizontal\n")
# Adding channel types.
c.types = ["A", "B"]
assert str(c) == (
"Channel 'BHE', Location '10' \n"
"\tTime range: -- - --\n"
"\tLatitude: 1.0000, Longitude: 2.0000, Elevation: 3.0 m, "
"Local Depth: 4.0 m\n"
"\tAzimuth: 5.00 degrees from north, clockwise\n"
"\tDip: 6.00 degrees down from horizontal\n"
"\tChannel types: A, B\n")
# Adding channel types.
c.sample_rate = 10.0
assert str(c) == (
"Channel 'BHE', Location '10' \n"
"\tTime range: -- - --\n"
"\tLatitude: 1.0000, Longitude: 2.0000, Elevation: 3.0 m, "
"Local Depth: 4.0 m\n"
"\tAzimuth: 5.00 degrees from north, clockwise\n"
"\tDip: 6.00 degrees down from horizontal\n"
"\tChannel types: A, B\n"
"\tSampling Rate: 10.00 Hz\n")
# "Adding" response
c.response = True
assert str(c) == (
"Channel 'BHE', Location '10' \n"
"\tTime range: -- - --\n"
"\tLatitude: 1.0000, Longitude: 2.0000, Elevation: 3.0 m, "
"Local Depth: 4.0 m\n"
"\tAzimuth: 5.00 degrees from north, clockwise\n"
"\tDip: 6.00 degrees down from horizontal\n"
"\tChannel types: A, B\n"
"\tSampling Rate: 10.00 Hz\n"
"\tResponse information available"
)
# Adding an empty sensor.
c.sensor = Equipment(type=None)
assert str(c) == (
"Channel 'BHE', Location '10' \n"
"\tTime range: -- - --\n"
"\tLatitude: 1.0000, Longitude: 2.0000, Elevation: 3.0 m, "
"Local Depth: 4.0 m\n"
"\tAzimuth: 5.00 degrees from north, clockwise\n"
"\tDip: 6.00 degrees down from horizontal\n"
"\tChannel types: A, B\n"
"\tSampling Rate: 10.00 Hz\n"
"\tSensor (Description): None (None)\n"
"\tResponse information available"
)
# Adding a sensor with only a type.
c.sensor = Equipment(type="random")
assert str(c) == (
"Channel 'BHE', Location '10' \n"
"\tTime range: -- - --\n"
"\tLatitude: 1.0000, Longitude: 2.0000, Elevation: 3.0 m, "
"Local Depth: 4.0 m\n"
"\tAzimuth: 5.00 degrees from north, clockwise\n"
"\tDip: 6.00 degrees down from horizontal\n"
"\tChannel types: A, B\n"
"\tSampling Rate: 10.00 Hz\n"
"\tSensor (Description): random (None)\n"
"\tResponse information available"
)
# Adding a sensor with only a description
c.sensor = Equipment(description="some description")
assert str(c) == (
"Channel 'BHE', Location '10' \n"
"\tTime range: -- - --\n"
"\tLatitude: 1.0000, Longitude: 2.0000, Elevation: 3.0 m, "
"Local Depth: 4.0 m\n"
"\tAzimuth: 5.00 degrees from north, clockwise\n"
"\tDip: 6.00 degrees down from horizontal\n"
"\tChannel types: A, B\n"
"\tSampling Rate: 10.00 Hz\n"
"\tSensor (Description): None (some description)\n"
"\tResponse information available"
)
# Adding a sensor with type and description
c.sensor = Equipment(type="random", description="some description")
assert str(c) == (
"Channel 'BHE', Location '10' \n"
"\tTime range: -- - --\n"
"\tLatitude: 1.0000, Longitude: 2.0000, Elevation: 3.0 m, "
"Local Depth: 4.0 m\n"
"\tAzimuth: 5.00 degrees from north, clockwise\n"
"\tDip: 6.00 degrees down from horizontal\n"
"\tChannel types: A, B\n"
"\tSampling Rate: 10.00 Hz\n"
"\tSensor (Description): random (some description)\n"
"\tResponse information available"
)