-
Notifications
You must be signed in to change notification settings - Fork 33
/
test_ndbc_sos.py
106 lines (89 loc) · 4.68 KB
/
test_ndbc_sos.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
from __future__ import absolute_import, division, print_function
import csv
import io
import unittest
from datetime import datetime
from owslib.swe.sensor.sml import SensorML
from six import string_types
from pyoos.collectors.ndbc.ndbc_sos import NdbcSos
class NdbcSosTest(unittest.TestCase):
def setUp(self):
self.c = NdbcSos()
def test_ndbc_server_id(self):
assert (
self.c.server.identification.title
== "National Data Buoy Center SOS"
)
assert self.c.server.identification.service == "OGC:SOS"
assert self.c.server.identification.version == "1.0.0"
assert (
self.c.server.identification.abstract
== "National Data Buoy Center SOS"
)
assert self.c.server.identification.fees == "NONE"
assert self.c.server.identification.accessconstraints == "NONE"
def test_ndbc_describe_sensor(self):
self.c.features = ["41012"]
response = self.c.metadata(
output_format='text/xml;subtype="sensorML/1.0.1"'
)
assert isinstance(response, list)
assert isinstance(response[0], SensorML)
def test_raw_ndbc_get_observation(self):
self.c.start_time = datetime.strptime("2012-10-01", "%Y-%m-%d")
self.c.end_time = datetime.strptime("2012-10-02", "%Y-%m-%d")
self.c.features = ["41012"]
self.c.variables = ["air_pressure_at_sea_level"]
response = self.c.raw(responseFormat="text/csv").decode()
assert isinstance(response, string_types)
"""
station_id,sensor_id,"latitude (degree)","longitude (degree)",date_time,"depth (m)","air_pressure_at_sea_level (hPa)" # noqa
urn:ioos:station:wmo:41012,urn:ioos:sensor:wmo:41012::baro1,30.04,-80.55,2012-10-01T00:50:00Z,0.00,1009.8
"""
data = list(csv.DictReader(io.StringIO(response)))
assert data[0]["station_id"] == "urn:ioos:station:wmo:41012"
assert data[0]["sensor_id"] == "urn:ioos:sensor:wmo:41012::baro1"
assert data[0]["date_time"] == "2012-10-01T00:50:00Z"
assert data[0]["depth (m)"] == "0.00"
assert data[0]["air_pressure_at_sea_level (hPa)"] == "1009.8"
def test_raw_ndbc_get_observation_all_stations(self):
self.c.start_time = datetime.strptime("2012-10-01", "%Y-%m-%d")
self.c.end_time = datetime.strptime("2012-10-02", "%Y-%m-%d")
# TODO: This should not return all stations in the future. We should make multiple requests.
self.c.features = ["32st0", "41012"] # Triggers network-all
self.c.variables = ["air_pressure_at_sea_level"]
response = self.c.raw(responseFormat="text/csv").decode()
assert isinstance(response, string_types)
data = list(csv.DictReader(io.StringIO(response)))
stations = list({x["station_id"] for x in data})
# 264 stations measured air_pressure that day
assert len(stations) == 264
"""
station_id,sensor_id,"latitude (degree)","longitude (degree)",date_time,"depth (m)","air_pressure_at_sea_level (hPa)" # noqa
urn:ioos:station:wmo:32st0,urn:ioos:sensor:wmo:32st0::baro1,-19.713,-85.585,2012-10-01T00:00:00Z,,1019.0
"""
assert data[0]["station_id"] == "urn:ioos:station:wmo:32st0"
assert data[0]["sensor_id"] == "urn:ioos:sensor:wmo:32st0::baro1"
assert data[0]["date_time"] == "2012-10-01T00:00:00Z"
assert data[0]["depth (m)"] == "-2.44"
assert data[0]["air_pressure_at_sea_level (hPa)"] == "1019.0"
def test_raw_ndbc_get_observation_no_stations(self):
self.c.start_time = datetime.strptime("2012-10-01", "%Y-%m-%d")
self.c.end_time = datetime.strptime("2012-10-02", "%Y-%m-%d")
self.c.features = [] # Triggers network-all
self.c.variables = ["air_pressure_at_sea_level"]
response = self.c.raw(responseFormat="text/csv").decode()
assert isinstance(response, string_types)
data = list(csv.DictReader(io.StringIO(response)))
stations = list({x["station_id"] for x in data})
# 264 stations measured air_pressure that day
assert len(stations) == 264
"""
station_id,sensor_id,"latitude (degree)","longitude (degree)",date_time,"depth (m)","air_pressure_at_sea_level (hPa)" # noqa
urn:ioos:station:wmo:32st0,urn:ioos:sensor:wmo:32st0::baro1,-19.713,-85.585,2012-10-01T00:00:00Z,,1019.0
"""
assert data[0]["station_id"] == "urn:ioos:station:wmo:32st0"
assert data[0]["sensor_id"] == "urn:ioos:sensor:wmo:32st0::baro1"
assert data[0]["date_time"] == "2012-10-01T00:00:00Z"
assert data[0]["depth (m)"] == "-2.44"
assert data[0]["air_pressure_at_sea_level (hPa)"] == "1019.0"