Skip to content

Commit 600a3b8

Browse files
committed
Add demo for retrieving data from BOM/WDO
BOM/WDO means: - Australian Bureau of Meteorology (BOM) - Water Data Online (WDO) It will use `kiwis-pie`, a Python library for querying a WISKI system using KiWIS.
1 parent 246c125 commit 600a3b8

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

wetterdienst/provider/bom/__init__.py

Whitespace-only changes.

wetterdienst/provider/bom/wdo.py

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
"""
2+
About
3+
=====
4+
5+
Demo for querying Australian Bureau of Meteorology's Water Data Online (WDO) service.
6+
7+
It uses `kiwis-pie`, a Python library for querying a WISKI system using the KiWIS
8+
(KISTERS Web Interoperability Solution) interface.
9+
10+
11+
Setup
12+
=====
13+
::
14+
15+
pip install kiwis-pie
16+
17+
18+
Synopsis
19+
========
20+
::
21+
22+
python -m wetterdienst.provider.bom.wdo
23+
24+
25+
References
26+
==========
27+
28+
- http://www.bom.gov.au/waterdata/
29+
- http://www.bom.gov.au/waterdata/services
30+
- https://github.com/amacd31/kiwis_pie
31+
- https://www.kisters.com.au/wiski-modules.html
32+
- https://kiwis.kisters.de/KiWIS/
33+
34+
"""
35+
from datetime import date
36+
from pprint import pprint
37+
38+
from kiwis_pie import KIWIS
39+
40+
41+
class BomWdoAccess:
42+
def __init__(self):
43+
# Introduction.
44+
print_header("About")
45+
print(__doc__)
46+
self.kiwis = KIWIS("http://www.bom.gov.au/waterdata/services")
47+
48+
def display_index(self):
49+
50+
# Retrieve list of sites.
51+
print_header("List of all sites")
52+
sites = self.kiwis.get_site_list()
53+
print(sites)
54+
print()
55+
56+
# Retrieve list of stations.
57+
print_header("List of all stations")
58+
stations = self.kiwis.get_station_list()
59+
print(stations)
60+
print()
61+
62+
# Retrieve list of parameters.
63+
print_header("List of all parameters")
64+
parameters = self.kiwis.get_parameter_list()
65+
print(parameters)
66+
print()
67+
68+
# Retrieve list of parameter types.
69+
print_header("List of all parameter types")
70+
parameter_types = self.kiwis.get_parameter_type_list()
71+
print(parameter_types)
72+
print()
73+
74+
def display_details(
75+
self, station_name, timeseries_name, parameter_type, date_from, date_to
76+
):
77+
78+
# Get station information by station name.
79+
station = self.kiwis.get_station_list(station_name=station_name)
80+
81+
# Display station information.
82+
print_header(f'Station information for "{station_name}"')
83+
pprint(station.to_dict(orient="list"))
84+
print()
85+
86+
# Resolve station name to station identifier.
87+
station_id = station.station_id.values[0]
88+
89+
# Retrieve list of timeseries.
90+
print_header(f'List of all timeseries for station "{station_name}"')
91+
timeseries = self.kiwis.get_timeseries_list(station_id=station_id)
92+
print(timeseries)
93+
print()
94+
95+
# Get ready.
96+
print_header(
97+
f'One month worth of "{parameter_type}" data from "{station_name}"'
98+
)
99+
print()
100+
101+
# Resolve timeseries name to timeseries identifier for specific station.
102+
timeseries_id = self.kiwis.get_timeseries_list(
103+
station_id=station_id,
104+
ts_name=timeseries_name,
105+
parametertype_name=parameter_type,
106+
).ts_id.values[0]
107+
108+
# Acquire values.
109+
data = self.kiwis.get_timeseries_values(
110+
ts_id=timeseries_id, to=date_to, **{"from": date_from}
111+
)
112+
113+
# Display dataset information.
114+
print_header("Dataset information")
115+
print(f"Station name: {station_name}")
116+
print(f"Station ID: {station_id}")
117+
print(f"Timeseries name: {timeseries_name}")
118+
print(f"Timeseries ID: {timeseries_id}")
119+
print(f"Parameter Type: {parameter_type}")
120+
print()
121+
122+
# Display data.
123+
print_header("Data")
124+
print(data)
125+
print()
126+
127+
# Optionally use the `keep_tz` option to return in local timezone instead of UTC.
128+
# k.get_timeseries_values(ts_id=ts_id, to=date(2016, 1, 31), **{"from": date(2016, 1, 1)}, keep_tz=True) # noqa: E501
129+
130+
131+
def print_header(label):
132+
length = max(len(label), 42)
133+
print("-" * length)
134+
print(label.center(length))
135+
print("-" * length)
136+
137+
138+
def main():
139+
bom = BomWdoAccess()
140+
141+
# Acquire and display list of available sites, stations, parameters
142+
# and parameter types.
143+
bom.display_index()
144+
145+
# Acquire and display 31 days worth of "daily water course discharge"
146+
# data for "Cotter River at Gingera" from the "daily mean streamflow (Q)"
147+
# timeseries.
148+
bom.display_details(
149+
station_name="Cotter R. at Gingera",
150+
timeseries_name="DMQaQc.Merged.DailyMean.24HR",
151+
parameter_type="Water Course Discharge",
152+
date_from=date(2016, 1, 1),
153+
date_to=date(2016, 1, 31),
154+
)
155+
156+
157+
if __name__ == "__main__":
158+
"""
159+
Synopsis::
160+
161+
python -m wetterdienst.provider.bom.wdo
162+
"""
163+
main()

0 commit comments

Comments
 (0)