user5618251
user5618251

Reputation: 361

Metpy: hodograph place point at specified wind data?

I am trying to include wind data at specific heights above the ground into the hodograph of the atmospheric soundings. More specifically, I would like the winds at the surface, 1 km, 3 km, 6 km and 9 km to be plotted as a dot. So far, I just achieved separating them in boundaries:

# Make an array of segment boundaries - don't forget units!
boundaries_h = [0, 1000, 3000, 6000, 9000] * units.meter

# Make a list of colors for the segments
colors_h = ['#66B2FF', '#3333FF', '#7F00FF', '#000000']

# Create a hodograph
ax_hod = inset_axes(skew.ax, '37.5%', '36.5%', loc=1)
wmax = np.concatenate((u, v))
wmax = np.max(wmax)
h = Hodograph(ax_hod, component_range=wmax.magnitude+2)
if wmax.magnitude < 20:
    h.add_grid(increment=5)
if wmax.magnitude < 40 and wmax.magnitude > 20:
    h.add_grid(increment=10)
if wmax.magnitude > 40:
    h.add_grid(increment=20)
h.plot_colormapped(u, v, z, intervals=boundaries_h, colors=colors_h)

Basically, I would just like points on the beginning and end of each segment and, with a text specifying the height (sfc, 1 km, 3 km, 6 km, 9 km). How can I do that? By the way, is there also a way to include the labels of the hodograph axis inside circles?

enter image description here

Upvotes: 2

Views: 555

Answers (1)

DopplerShift
DopplerShift

Reputation: 5853

You'll need to manually interpolate to those boundary points unless you already have them. You can plot as matching colored points using scatter--or you can use plot if you don't want them colored. This should work as a supplement to the code above.

import matplotlib.colors as mcolors
import matplotlib.patheffects as mpatheffects
import metpy.interpolate as mpinterpolate

# Interpolate to the boundary heights
u_pts, v_pts = mpinterpolate.interpolate_1d(boundaries_h, z, u, v)

# Generate a colormap/norm to color the points with scatter
cmap = mcolors.ListedColormap(colors_h)
norm = mcolors.BoundaryNorm(boundaries_h.m, cmap.N)
ax_hod.scatter(u_pts, v_pts, c=boundaries_h, cmap=cmap, norm=norm, zorder=10)

# Loop over points and heights to plot text (using a path effect to
# get outlined text that should show up better)
for up, vp, z in zip(u_pts, v_pts, boundaries_h):
    z_str = '{:~.0f}'.format(z.to('km')) if z else 'Sfc'
    ax_hod.text(up, vp, z_str, ha='center', fontsize=12,
                path_effects=[mpatheffects.withStroke(foreground='white', linewidth=2)],
                zorder=12)

# Change tick parameters to put the ticks and labels inside
ax_hod.tick_params(axis='y', direction='in', pad=-20)
ax_hod.tick_params(axis='x', direction='in', pad=-15)

Upvotes: 1

Related Questions