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.26k stars 415 forks source link

Implement XAV and YAV (zonal/meridional mean) equivalents #2123

Open sgdecker opened 3 years ago

sgdecker commented 3 years ago

The GEMPAK Conversion Guide recommends numpy.mean(a, axis=1) as equivalent to XAV, but the NumPy (or xarray) version removes the dimension across which the mean is computed, so you can't plot it on a map without doing extra work. This is a request to have functions that do that work.

To be specific, for a suitably defined DataArray ht500, this generates a plot:

cp = ContourPlot()
cp.data = ht500
cp.time = plot_time
cp.contours = list(range(0, 700, 6))
cp.linecolor = 'green'
cp.linestyle = 'solid'
cp.clabels = True
cp.plot_units = 'dam'

panel = MapPanel()
panel.area = [-180, -40, 10, 75]
panel.projection = 'lcc'
panel.layers = ['states', 'coastline', 'borders']
panel.title = f'500-mb Heights at {plot_time}'
panel.plots = [cp]

pc = PanelContainer()
pc.size = (15, 15)
pc.panels = [panel]
pc.show()

but this does not:

zonal_mean = ht500.mean(dim='lon', keep_attrs=True)

cp = ContourPlot()
cp.data = zonal_mean
cp.time = plot_time
cp.contours = list(range(0, 700, 6))
cp.linecolor = 'green'
cp.linestyle = 'solid'
cp.clabels = True
cp.plot_units = 'dam'

panel = MapPanel()
panel.area = [-180, -40, 10, 75]
panel.projection = 'lcc'
panel.layers = ['states', 'coastline', 'borders']
panel.title = f'500-mb Heights at {plot_time}'
panel.plots = [cp]

pc = PanelContainer()
pc.size = (15, 15)
pc.panels = [panel]
pc.show()

I am suggesting we add a function that can generate a zonal or meridional mean that can be plotted w/o extra work on the user's part. Or, if there is a variation of mean that does what I am looking for that I haven't discovered yet, the suggestion would be to modify the GEMPAK Comparison Guide accordingly.

dopplershift commented 3 years ago

How do you calculate a zonal/meridional mean that's still plot-able in a 2D plan view? What does that even look like? At best you'd be smearing something across one dimension, which doesn't seem...useful. I'd love to see a concrete use of this from GEMPAK to see what we can do.

sgdecker commented 3 years ago

Here's a quick example showing what GEMPAK produces using XAV. At this time, we can see the mean jet position is north of the CONUS, but south of most of Alaska. It would be harder to determine that without the map.

zonalmean

sgdecker commented 3 years ago

For a more in-depth example, see Fig. 2.24 in Lackmann's textbook.

dopplershift commented 3 years ago

cough That would require me to have said textbook 😉 I'm an OU grad, there is only "Book of Howie Bluestein". 😆

Since broadcasting should work without copying data in calculation contexts, we could consider adding support in the declarative framework to do what you're looking for when receiving 1D data.

sgdecker commented 3 years ago

Ha! Well, in any case, adding support would be great. I've personally never used YAV myself, but I figure if XAV can be done, the other would be almost free.