Quick-view a sweep in polar or cartesian reference systems#
[1]:
import numpy as np
import matplotlib.pyplot as pl
import wradlib
import warnings
warnings.filterwarnings("ignore")
try:
get_ipython().run_line_magic("matplotlib inline")
except:
pl.ion()
Read a polar data set from the German Weather Service#
[2]:
filename = wradlib.util.get_wradlib_data_file(
"dx/raa00-dx_10908-0806021735-fbg---bin.gz"
)
print(filename)
/home/runner/work/wradlib/wradlib/wradlib-data/dx/raa00-dx_10908-0806021735-fbg---bin.gz
[3]:
img, meta = wradlib.io.read_dx(filename)
Inspect the data set a little
[4]:
print("Shape of polar array: %r\n" % (img.shape,))
print("Some meta data of the DX file:")
print("\tdatetime: %r" % (meta["datetime"],))
print("\tRadar ID: %s" % (meta["radarid"],))
Shape of polar array: (360, 128)
Some meta data of the DX file:
datetime: datetime.datetime(2008, 6, 2, 17, 35, tzinfo=<UTC>)
Radar ID: 10908
Simple ways to plot this dataset#
The simplest plot#
[5]:
ax, pm = wradlib.vis.plot_ppi(img)
txt = pl.title("Simple PPI")

Simple plot with x,y-offset#
[6]:
ax, pm = wradlib.vis.plot_ppi(img, site=(10, 45, 0))
txt = pl.title("Simple PPI with offset")

Plot with azimuth/ranges and in curvelinear grid#
[7]:
r = np.arange(img.shape[1], dtype=float)
r += (r[1] - r[0]) / 2.0
r *= 1000
az = np.arange(img.shape[0], dtype=float)
az += (az[1] - az[0]) / 2.0
fig = pl.figure(figsize=(16, 8))
ax1, pm = wradlib.vis.plot_ppi(img, r=r, az=az, ax=121, fig=fig)
ax2, pm = wradlib.vis.plot_ppi(img, r=r, az=az, proj="cg", ax=122, fig=fig)
t = ax1.set_title("Simple Plot with r/az", y=1)
t = ax2.set_title("Simple Plot in cg grid", y=1.05)

Simple plot with applied range factor ‘rf’#
[8]:
ax, pm = wradlib.vis.plot_ppi(img, r=r, az=az, rf=1e3)
txt = pl.title("Simple PPI with range factor")

Simple plot in projected coordinate system#
[9]:
r = np.arange(img.shape[1], dtype=float)
r += (r[1] - r[0]) / 2.0
r *= 1000
az = np.arange(img.shape[0], dtype=float)
az += (az[1] - az[0]) / 2.0
epsg = wradlib.georef.epsg_to_osr(31466)
fig = pl.figure(figsize=(10, 10))
ax, pm = wradlib.vis.plot_ppi(img, r=r, az=az, site=(10, 45, 0), proj=epsg, fig=fig)
txt = pl.title("Simple PPI in Gauss-Krüger zone 2")

Simple plot in WGS 84 coordinates#
[10]:
proj = wradlib.georef.get_default_projection()
ax, pm = wradlib.vis.plot_ppi(img, r=r, az=az, site=(10, 45, 0), proj=proj)
txt = pl.title("Simple PPI in WGS84 coordinates")

Plotting just one sector#
For this purpose, we need to give the ranges and azimuths explicitly…
[11]:
r = np.arange(40, 81)
az = np.arange(200, 251)
ax, pm = wradlib.vis.plot_ppi(img[200:251, 40:81], r, az)
txt = pl.title("Sector PPI")

Adding a crosshair to the PPI#
[12]:
# We introduce a site offset...
site = (10.0, 45.0, 0)
wradlib.vis.plot_ppi(img, site=site)
# ... plot a crosshair over our data...
wradlib.vis.plot_ppi_crosshair(
site=site,
ranges=[50, 100, 128],
angles=[0, 90, 180, 270],
line=dict(color="white"),
circle={"edgecolor": "white"},
)
pl.title("Offset and Custom Crosshair")
pl.axis("tight")
pl.gca().set_aspect("equal")

Placing the polar data in a projected Cartesian reference system#
Using the proj
keyword we tell the function to: - interpret the site coordinates as longitude/latitude - reproject the coordinates to the given projection (here: dwd-radolan composite coordinate system)
[13]:
site = (10.0, 45.0, 0)
r = np.arange(img.shape[1], dtype=float)
r += (r[1] - r[0]) / 2.0
r *= 1000
az = np.arange(img.shape[0], dtype=float)
az += (az[1] - az[0]) / 2.0
elev = np.zeros_like(az)
proj_rad = wradlib.georef.create_osr("dwd-radolan")
wradlib.vis.plot_ppi(img, r=r, az=az, site=site, proj=proj_rad)
# Now the crosshair ranges must be given in meters
wradlib.vis.plot_ppi_crosshair(
site=site,
ranges=[40000, 80000, 128000],
line=dict(color="white"),
circle={"edgecolor": "white"},
proj=proj_rad,
)
pl.title("Georeferenced/Projected PPI")
pl.axis("tight")
pl.gca().set_aspect("equal")

Some side effects of georeferencing#
Transplanting the radar virtually moves it away from the central meridian of the projection (which is 10 degrees east). Due north now does not point straight upwards on the map.
The crosshair shows this: for the case that the lines should actually become curved, they are implemented as a piecewise linear curve with 10 vertices. The same is true for the range circles, but with more vertices, of course.
[14]:
site = (45.0, 7.0, 0.0)
ax, pm = wradlib.vis.plot_ppi(img, r=r, az=az, site=site, proj=proj_rad)
ax = wradlib.vis.plot_ppi_crosshair(
site=site,
ranges=[64000, 128000],
line=dict(color="red"),
circle={"edgecolor": "red"},
proj=proj_rad,
)
txt = pl.title("Projection Side Effects")

Simple Plot on Mercator-Map using cartopy#
[15]:
import cartopy.crs as ccrs
map_proj = ccrs.Mercator(central_longitude=site[1])
[16]:
site = (7, 45, 0.0)
fig = pl.figure(figsize=(10, 10))
ax, pm = wradlib.vis.plot_ppi(img, r=r, az=az, site=site, proj=map_proj, fig=fig)
ax.gridlines(draw_labels=True)
[16]:
<cartopy.mpl.gridliner.Gridliner at 0x7fdfa294aa50>

More decorations and annotations#
You can annotate these plots by using standard matplotlib methods.
[17]:
ax, pm = wradlib.vis.plot_ppi(img)
ylabel = ax.set_xlabel("easting [km]")
ylabel = ax.set_ylabel("northing [km]")
title = ax.set_title("PPI manipulations/colorbar")
# you can now also zoom - either programmatically or interactively
xlim = ax.set_xlim(-80, -20)
ylim = ax.set_ylim(-80, 0)
# as the function returns the axes- and 'mappable'-objects colorbar needs, adding a colorbar is easy
cb = pl.colorbar(pm, ax=ax)
