1

Trying to plot HRRR data using MetPy imported through Herbie and inserted into XArray. I am plotting the geopotential height at 700mb with a ContourPlot on a MapPanel. Below, I have inserted the code and the XArray with the data. The output is just a blank map with some of the contour labels it seems over Kansas.

Is something missing?

Thanks!

from herbie import Herbie

from datetime import datetime, timedelta

import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import metpy.calc as mpcalc
import metpy.plots as metplot
from metpy.units import units
from metpy.io import metar

from toolbox.cartopy_tools import common_features, pc

H = Herbie(
  '2015-06-17 12:00',
  model='hrrr',
  product='sfc',
  fxx=0
)

h = H.xarray(':700 mb:')

print(h)

cntr2 = metplot.ContourPlot()
cntr2.data = h
cntr2.field = 'gh'
cntr2.contours = list(range(0, 5000, 100))
cntr2.linecolor = 'black'
cntr2.linestyle = 'solid'
cntr2.clabels = True

panel = metplot.MapPanel()
panel.area = [-125, -74, 20, 55]
panel.projection = 'lcc'
panel.layers = ['states', 'coastline', 'borders']
panel.plots = [cntr2]

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

Here's the XArray:

<xarray.Dataset>
Dimensions:              (y: 1059, x: 1799)
Coordinates:
    time                 datetime64[ns] 2015-06-17T12:00:00
    step                 timedelta64[ns] 00:00:00
    isobaricInhPa        float64 700.0
    latitude             (y, x) float64 21.14 21.14 21.15 ... 47.86 47.85 47.84
    longitude            (y, x) float64 237.3 237.3 237.3 ... 299.0 299.0 299.1
    valid_time           datetime64[ns] 2015-06-17T12:00:00
Dimensions without coordinates: y, x
Data variables:
    t                    (y, x) float32 ...
    u                    (y, x) float32 ...
    v                    (y, x) float32 ...
    gh                   (y, x) float32 ...
    dpt                  (y, x) float32 ...
    gribfile_projection  object None
Attributes:
    GRIB_edition:            2
    GRIB_centre:             kwbc
    GRIB_centreDescription:  US National Weather Service - NCEP
    GRIB_subCentre:          0
    Conventions:             CF-1.7
    institution:             US National Weather Service - NCEP
    model:                   hrrr
    product:                 sfc
    description:             High-Resolution Rapid Refresh - CONUS
    remote_grib:             /User/data/hrrr/20150617/hrrr.t12z.wrf...
    local_grib:              /User/data/hrrr/20150617/subset_5dff6e...
    searchString:            :700 mb:
radarscan
  • 11
  • 1

1 Answers1

0

The problem here is that herbie sets the grid_mapping appropriately for each of the variables for a Lambert Conformal projection, but does not include any coordinate information (i.e. x/y values appropriate for that projection). Apparently (suboptimally), MetPy proceeds to try to use the lat/lon values (since they're the only horizontal coordinates it can find) with that projection.

The workaround is to get MetPy to add some appropriate x/y coordinates, which can be done after parsing the metadata as:

h = h.metpy.parse_cf().metpy.assign_y_x()

Once I add that before the plotting commands, I get the appropriate plot: Corrected contour plot

DopplerShift
  • 5,472
  • 1
  • 21
  • 20