Quick-view a sweep in polar or cartesian reference systems¶

[1]:

import numpy as np
import matplotlib.pyplot as pl
import warnings

warnings.filterwarnings("ignore")
try:
get_ipython().magic("matplotlib inline")
except:
pl.ion()

/home/runner/micromamba-root/envs/wradlib-notebooks/lib/python3.10/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm


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-notebooks/wradlib-notebooks/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"],))

Shape of polar array: (360, 128)

Some meta data of the DX file:
datetime: datetime.datetime(2008, 6, 2, 17, 35, tzinfo=<UTC>)


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=np.float)
r += (r[1] - r[0]) / 2.0
r *= 1000
az = np.arange(img.shape[0], dtype=np.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=np.float)
r += (r[1] - r[0]) / 2.0
r *= 1000
az = np.arange(img.shape[0], dtype=np.float)
az += (az[1] - az[0]) / 2.0

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)
# ... plot a crosshair over our data...
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=np.float)
r += (r[1] - r[0]) / 2.0
r *= 1000
az = np.arange(img.shape[0], dtype=np.float)
az += (az[1] - az[0]) / 2.0
elev = np.zeros_like(az)
# Now the crosshair ranges must be given in meters
site=site,
ranges=[40000, 80000, 128000],
line=dict(color="white"),
circle={"edgecolor": "white"},
)
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)
site=site,
ranges=[64000, 128000],
line=dict(color="red"),
circle={"edgecolor": "red"},
)
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 0x7feac7bd9930>


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)