-
I thought this was supposed to work, but subtleties with units often get me. In the code below, I can get a plot if I only include the 500-mb heights (which includes a unit conversion), but no dice when I try wind barbs (also with a unit conversion). from datetime import datetime
import xarray as xr
from metpy.io import GempakGrid
from metpy.units import units
from metpy.plots.declarative import ContourPlot, BarbPlot, MapPanel, PanelContainer
gem_file_name = '/ldmdata/gempak/model/nam/22092112_nam211.gem'
gem_file = GempakGrid(gem_file_name)
plot_time = datetime(2022, 9, 21, 12)
ht500 = gem_file.gdxarray(parameter='HGHT', date_time=plot_time, level=500)[0]
ht500 = ht500 * units('m')
u500 = gem_file.gdxarray(parameter='UREL', date_time=plot_time, level=500)[0]
v500 = gem_file.gdxarray(parameter='VREL', date_time=plot_time, level=500)[0]
u500 = u500 * units('m/s')
v500 = v500 * units('m/s')
wind = xr.merge([u500, v500])
print(wind)
print(wind['urel'])
print(wind['vrel'])
barbs = BarbPlot()
barbs.data = wind
barbs.time = plot_time
barbs.field = ['urel', 'vrel']
barbs.earth_relative = False
barbs.skip = (3, 3)
barbs.plot_units = 'knot'
cp = ContourPlot()
cp.data = ht500
cp.time = plot_time
cp.contours = list(range(460, 700, 6))
cp.linecolor = 'green'
cp.linestyle = 'solid'
cp.clabels = True
cp.plot_units = 'dam'
panel = MapPanel()
panel.area = [-120, -74, 22, 55]
panel.projection = 'lcc'
panel.layers = ['states', 'coastline', 'borders']
panel.title = f'500-mb Heights and Winds at {plot_time}'
panel.plots = [barbs, cp]
pc = PanelContainer()
pc.size = (12, 9)
pc.panels = [panel]
pc.show() The output:
This is with MetPy 1.3.1 and xarray 2022.6.0 |
Beta Was this translation helpful? Give feedback.
Answered by
sgdecker
Sep 21, 2022
Replies: 1 comment
-
Ahh, I knew I'd seen this before: #2118 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sgdecker
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ahh, I knew I'd seen this before: #2118
That has the workaround.