-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
radar_scan_volume.py
126 lines (94 loc) · 2.97 KB
/
radar_scan_volume.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
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2021, earthobservations developers.
# Distributed under the MIT License. See LICENSE for more info.
"""
=====
About
=====
Example for DWD radar sites data in OPERA HDF5 (ODIM_H5) format using wetterdienst and wradlib. # noqa
Derived from https://gist.github.com/kmuehlbauer/ac990569e6ad38a49412fc74a2035c37.
See also:
- https://docs.wradlib.org/en/stable/notebooks/fileio/wradlib_radar_formats.html#OPERA-HDF5-(ODIM_H5) # noqa
This program will request the most recent complete SWEEP_VOL data
for Essen and plot the outcome with matplotlib.
=====
Setup
=====
::
brew install gdal
pip install wradlib
"""
import logging
import os
from itertools import chain
import matplotlib.pyplot as plt
import wradlib as wrl
from wetterdienst.provider.dwd.radar import (
DwdRadarDataFormat,
DwdRadarDataSubset,
DwdRadarDate,
DwdRadarParameter,
DwdRadarSite,
DwdRadarValues,
)
logging.basicConfig(level=logging.INFO)
log = logging.getLogger()
def plot(data: wrl.io.XRadVolume):
"""
Convenience function for plotting radar data.
"""
# Get first sweep in volume.
swp0 = data[0].data
# Georeference Data.
swp0 = swp0.pipe(wrl.georef.georeference_dataset)
# Plot and display data using cartopy.
fig = plt.figure(figsize=(20, 8))
ax1 = fig.add_subplot(121, aspect="equal")
swp0.DBZH[0].plot(x="x", y="y", ax=ax1)
ax2 = fig.add_subplot(122, aspect="equal")
swp0.VRADH[0].plot(x="x", y="y", ax=ax2)
def radar_info(data: dict):
"""
Display data from radar request.
"""
print(data)
return
print("Keys:", data.keys())
log.info("Data")
for key, value in data.items():
print(f"- {key}: {value}")
def radar_scan_volume():
request_velocity = DwdRadarValues(
parameter=DwdRadarParameter.SWEEP_VOL_VELOCITY_H,
start_date=DwdRadarDate.MOST_RECENT,
site=DwdRadarSite.ESS,
fmt=DwdRadarDataFormat.HDF5,
subset=DwdRadarDataSubset.POLARIMETRIC,
)
request_reflectivity = DwdRadarValues(
parameter=DwdRadarParameter.SWEEP_VOL_REFLECTIVITY_H,
start_date=DwdRadarDate.MOST_RECENT,
site=DwdRadarSite.ESS,
fmt=DwdRadarDataFormat.HDF5,
subset=DwdRadarDataSubset.POLARIMETRIC,
)
log.info(f"Acquiring radar SWEEP_VOL data for {DwdRadarSite.ESS} at " f"{request_velocity.start_date}")
# Submit requests.
results = chain(request_velocity.query(), request_reflectivity.query())
# Collect list of buffers.
files = list(map(lambda item: item.data, results))
# Sanity checks.
if not files:
log.warning("No radar files found for the given constraints")
# Decode data using wradlib.
data = wrl.io.open_odim(files)
# Output debug information.
radar_info(data)
# Plot and display data.
plot(data)
if "PYTEST_CURRENT_TEST" not in os.environ:
plt.show()
def main():
radar_scan_volume()
if __name__ == "__main__":
main()