Skip to content

Commit

Permalink
Radar: Verify HDF5 responses instead of returning invalid data
Browse files Browse the repository at this point in the history
Along the lines, improve the radar tests again.
  • Loading branch information
amotl committed Apr 6, 2021
1 parent 9ec696e commit a01789c
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 168 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ docs/_build/
dist/
tmp/
geckodriver.log
troubleshooting
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Development
- Add capability to export data to Zarr format
- Add Wetterdienst UI. Thanks, @meteoDaniel!
- Add MAC ARM64 supoort with dependency restrictions
- Radar: Verify HDF5 responses instead of returning invalid data

0.16.1 (31.03.2021)
*******************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
=====
About
=====
Example for DWD RADOLAN Composite RX using wetterdienst and wradlib.
Example for DWD RADOLAN Composite RW using wetterdienst and wradlib.
See also:
- https://docs.wradlib.org/en/stable/notebooks/radolan/radolan_showcase.html.
Expand All @@ -24,6 +24,7 @@
"""
import logging
import os

import matplotlib.pyplot as pl
import numpy as np
Expand Down Expand Up @@ -88,29 +89,30 @@ def radar_info(data: np.ndarray, attributes: dict):
print(f"- {key}: {value}")


def radar_rx_example():
def radar_rw_example():

log.info("Acquiring radar RX composite data")
log.info("Acquiring radar RW composite data")
radolan = DwdRadarValues(
parameter=DwdRadarParameter.RX_REFLECTIVITY,
parameter=DwdRadarParameter.RW_REFLECTIVITY,
start_date=DwdRadarDate.LATEST,
)

for item in radolan.collect_data():
for item in radolan.query():

# Decode data using wradlib.
log.info("Parsing radar RX composite data for %s", item.timestamp)
log.info("Parsing radar RW composite data for %s", item.timestamp)
data, attributes = wrl.io.read_radolan_composite(item.data)

radar_info(data, attributes)

# Plot and display data.
plot(data, attributes)
pl.show()
if "PYTEST_CURRENT_TEST" not in os.environ:
pl.show()


def main():
radar_rx_example()
radar_rw_example()


if __name__ == "__main__":
Expand Down
6 changes: 4 additions & 2 deletions example/radar/radar_radolan_cdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- Daily: https://docs.wradlib.org/en/stable/notebooks/radolan/radolan_showcase.html#RADOLAN-SF-Product # noqa
"""
import logging
import os

import matplotlib.pyplot as pl
import numpy as np
Expand Down Expand Up @@ -140,7 +141,7 @@ def radolan_grid_example():
end_date="2020-09-04T12:00:00",
)

for item in radolan.collect_data():
for item in radolan.query():

# Decode data using wradlib.
log.info("Parsing RADOLAN_CDC composite data for %s", item.timestamp)
Expand All @@ -151,7 +152,8 @@ def radolan_grid_example():

# Plot and display data.
plot(data, attributes, label)
pl.show()
if "PYTEST_CURRENT_TEST" not in os.environ:
pl.show()


def main():
Expand Down
6 changes: 4 additions & 2 deletions example/radar/radar_radolan_rw.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- Daily: https://docs.wradlib.org/en/stable/notebooks/radolan/radolan_showcase.html#RADOLAN-SF-Product # noqa
"""
import logging
import os

import matplotlib.pyplot as pl
import numpy as np
Expand Down Expand Up @@ -135,7 +136,7 @@ def radolan_rw_example():
start_date=DwdRadarDate.LATEST,
)

for item in radolan.collect_data():
for item in radolan.query():

# Decode data using wradlib.
log.info("Parsing RADOLAN RW composite data for %s", item.timestamp)
Expand All @@ -146,7 +147,8 @@ def radolan_rw_example():

# Plot and display data.
plot(data, attributes, label)
pl.show()
if "PYTEST_CURRENT_TEST" not in os.environ:
pl.show()


def main():
Expand Down
19 changes: 7 additions & 12 deletions example/radar/radar_scan_precip.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- 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_PCP data
for Boostedt and plot the outcome with matplotlib.
for Essen and plot the outcome with matplotlib.
=====
Expand Down Expand Up @@ -82,27 +82,25 @@ def radar_scan_precip():
request_velocity = DwdRadarValues(
parameter=DwdRadarParameter.SWEEP_PCP_VELOCITY_H,
start_date=DwdRadarDate.MOST_RECENT,
site=DwdRadarSite.BOO,
site=DwdRadarSite.ESS,
fmt=DwdRadarDataFormat.HDF5,
subset=DwdRadarDataSubset.POLARIMETRIC,
)
request_reflectivity = DwdRadarValues(
parameter=DwdRadarParameter.SWEEP_PCP_REFLECTIVITY_H,
start_date=DwdRadarDate.MOST_RECENT,
site=DwdRadarSite.BOO,
site=DwdRadarSite.ESS,
fmt=DwdRadarDataFormat.HDF5,
subset=DwdRadarDataSubset.POLARIMETRIC,
)

log.info(
f"Acquiring radar SWEEP_PCP data for {DwdRadarSite.BOO} at "
f"Acquiring radar SWEEP_PCP data for {DwdRadarSite.ESS} at "
f"{request_velocity.start_date}"
)

# Submit requests.
results = chain(
request_velocity.collect_data(), request_reflectivity.collect_data()
)
results = chain(request_velocity.query(), request_reflectivity.query())

# Collect list of buffers.
files = list(map(lambda item: item.data, results))
Expand All @@ -115,11 +113,8 @@ def radar_scan_precip():

# Plot and display data.
plot(data)
pl.show()

# Remove temporary files.
for tmpfile in files:
os.unlink(tmpfile)
if "PYTEST_CURRENT_TEST" not in os.environ:
pl.show()


def main():
Expand Down
23 changes: 11 additions & 12 deletions example/radar/radar_scan_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- 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 Boostedt and plot the outcome with matplotlib.
for Essen and plot the outcome with matplotlib.
=====
Expand Down Expand Up @@ -82,31 +82,33 @@ def radar_scan_volume():
request_velocity = DwdRadarValues(
parameter=DwdRadarParameter.SWEEP_VOL_VELOCITY_H,
start_date=DwdRadarDate.MOST_RECENT,
site=DwdRadarSite.BOO,
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.BOO,
site=DwdRadarSite.ESS,
fmt=DwdRadarDataFormat.HDF5,
subset=DwdRadarDataSubset.POLARIMETRIC,
)

log.info(
f"Acquiring radar SWEEP_VOL data for {DwdRadarSite.BOO} at "
f"Acquiring radar SWEEP_VOL data for {DwdRadarSite.ESS} at "
f"{request_velocity.start_date}"
)

# Submit requests.
results = chain(
request_velocity.collect_data(), request_reflectivity.collect_data()
)
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)

Expand All @@ -115,11 +117,8 @@ def radar_scan_volume():

# Plot and display data.
plot(data)
pl.show()

# Remove temporary files.
for tmpfile in files:
os.unlink(tmpfile)
if "PYTEST_CURRENT_TEST" not in os.environ:
pl.show()


def main():
Expand Down
6 changes: 4 additions & 2 deletions example/radar/radar_site_dx.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"""
import logging
import os

import matplotlib.pyplot as pl
import numpy as np
Expand Down Expand Up @@ -74,7 +75,7 @@ def radar_dx_example():
site=DwdRadarSite.BOO,
)

for item in request.collect_data():
for item in request.query():

# Decode data using wradlib.
log.info(f"Parsing radar data for {request.site} at '{item.timestamp}'")
Expand All @@ -85,7 +86,8 @@ def radar_dx_example():

# Plot and display data.
plot(data)
pl.show()
if "PYTEST_CURRENT_TEST" not in os.environ:
pl.show()


def main():
Expand Down
6 changes: 4 additions & 2 deletions example/radar/radar_sweep_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"""
import logging
import os

import matplotlib.pyplot as pl
import numpy as np
Expand Down Expand Up @@ -73,7 +74,7 @@ def radar_hdf5_example():
subset=DwdRadarDataSubset.SIMPLE,
)

for item in request.collect_data():
for item in request.query():

# Decode data using wradlib.
log.info(f"Parsing radar data for {request.site} at '{item.timestamp}'")
Expand All @@ -84,7 +85,8 @@ def radar_hdf5_example():

# Plot and display data.
plot(data)
pl.show()
if "PYTEST_CURRENT_TEST" not in os.environ:
pl.show()


def main():
Expand Down

0 comments on commit a01789c

Please sign in to comment.