Unidata / MetPy

MetPy is a collection of tools in Python for reading, visualizing and performing calculations with weather data.
https://unidata.github.io/MetPy/
BSD 3-Clause "New" or "Revised" License
1.24k stars 413 forks source link

Hodograph plot enhancement with vectors between two points at two levels #1340

Open winash12 opened 4 years ago

winash12 commented 4 years ago

I am looking to create hodographs in which vectors are shown connecting two points between two levels as shown in this image - https://ibb.co/GHVXDjY

Also I am not sure it is possible but I also want to include dots after every level. To distinguish where one level ends and another one begins.

For a comprehensive view of vectors and hodographs please feel free to view this document - https://www.weather.gov/media/lmk/soo/Hodographs_Wind-Shear.pdf

aschueth commented 4 years ago

So you were thinking something along the lines of:

import numpy as np
import matplotlib.pyplot as plt
from metpy.units import units
from metpy.plots import Hodograph

zarray=np.array([0,0.5,1,2,3,4,5,6,7,8,9])*units.km
uarray=np.array([-12,-14,-7,-2,2,10,15,21,24,27,31])*units.knots
varray=np.array([-5,5,12,15,15,14,11,12,16,23,30])*units.knots

fig = plt.figure(figsize=(8, 8),facecolor='white')
ax = plt.subplot()
h = Hodograph(ax, component_range=50.)

h.add_grid(increment=10)

for i in range(len(zarray)-1):
    plt.arrow(uarray[i].m, varray[i].m,(uarray[1:]-uarray[:-1])[i].m,(varray[1:]-varray[:-1])[i].m,width=0.5,head_width=2,facecolor='r',edgecolor=None,length_includes_head=True)
for i,z in enumerate(zarray):
    plt.scatter(uarray[i],varray[i], s=50, color='k')

which displays image

But have it as a keyword argument in the hodograph plotting code, where you could specify vector and instead of the lines it would draw an arrow between each point?

winash12 commented 4 years ago

@aschueth Wonderful !!!

I was able to generate a similar plot for my station. https://imgur.com/a/lIV7tcc

The only issue is that the distance between two levels is extremely cramped and one can hardly see the direction of wind between two levels. Other than that looks great.

dopplershift commented 4 years ago

I'm not sure I like having this as a keyword argument on Hodograph.plot, since right now we just forward extra kwargs onto Axes.plot. What about having a new method plot_arrows?

aschueth commented 4 years ago

That is one downside of this method, it will be pretty cramped with hodographs with little shear and/or high vertical resolution. To avoid it you can slice it with a larger stride like [::2].

Is this a large enough use case to add a new method? I can see it's value pedagogically when teaching hododgraphs, but not much beyond that? I could be mistaken though