HRRR-Alaska#

This will plot HRRR-Alaska data. There are additional β€œproducts” available than are shown here.

[1]:
from herbie import Herbie
from toolbox import EasyMap, pc
from paint.standard2 import cm_tmp

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
[2]:
H = Herbie(
    "2021-07-19",
    model="hrrrak",
    product="sfc",
    fxx=6,
)
βœ… Found β”Š model=hrrrak β”Š product=sfc β”Š 2021-Jul-19 00:00 UTC F06 β”Š GRIB2 @ aws β”Š IDX @ aws
[3]:
# Show additional products
H.PRODUCTS
[3]:
{'prs': '3D pressure level fields; 3-km resolution',
 'sfc': '2D surface level fields; 3-km resolution',
 'nat': 'Native level fields; 3-km resolution',
 'subh': 'Subhourly grids; 3-km resolution'}
[4]:
ds = H.xarray("TMP:2 m above")
ds
[4]:
<xarray.Dataset>
Dimensions:              (y: 919, x: 1299)
Coordinates:
    time                 datetime64[ns] 2021-07-19
    step                 timedelta64[ns] 06:00:00
    heightAboveGround    float64 2.0
    latitude             (y, x) float64 ...
    longitude            (y, x) float64 ...
    valid_time           datetime64[ns] ...
Dimensions without coordinates: y, x
Data variables:
    t2m                  (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:                   hrrrak
    product:                 sfc
    description:             High-Resolution Rapid Refresh - Alaska
    remote_grib:             https://noaa-hrrr-bdp-pds.s3.amazonaws.com/hrrr....
    local_grib:              C:\Users\blaylock\data\hrrrak\20210719\subset_6e...
    search:            TMP:2 m above
[5]:
ax = EasyMap("50m", crs=ds.herbie.crs, figsize=[10, 8]).STATES().ax

p = ax.pcolormesh(
    ds.longitude,
    ds.latitude,
    ds.t2m,
    transform=pc,
    **cm_tmp(units="K").cmap_kwargs,
)
plt.colorbar(
    p,
    ax=ax,
    orientation="horizontal",
    pad=0.05,
    **cm_tmp(units="K").cbar_kwargs,
)

ax.set_title(ds.t2m.GRIB_name, loc="right")
ax.set_title(f"{ds.model.upper()}: {H.product_description}", loc="left")
[5]:
Text(0.0, 1.0, 'HRRRAK: 2D surface level fields; 3-km resolution')
../../../_images/user_guide_tutorial_model_notebooks_hrrrak_5_1.png
[6]:
ds.t2m.attrs
[6]:
{'GRIB_paramId': 167,
 'GRIB_dataType': 'fc',
 'GRIB_numberOfPoints': 1193781,
 'GRIB_typeOfLevel': 'heightAboveGround',
 'GRIB_stepUnits': 1,
 'GRIB_stepType': 'instant',
 'GRIB_gridType': 'polar_stereographic',
 'GRIB_NV': 0,
 'GRIB_cfName': 'air_temperature',
 'GRIB_cfVarName': 't2m',
 'GRIB_gridDefinitionDescription': 'Polar stereographic can be south or north',
 'GRIB_missingValue': 3.4028234663852886e+38,
 'GRIB_name': '2 metre temperature',
 'GRIB_parameterName': 'Temperature',
 'GRIB_parameterUnits': 'K',
 'GRIB_shortName': '2t',
 'GRIB_stepRange': '6',
 'GRIB_units': 'K',
 'long_name': '2 metre temperature',
 'units': 'K',
 'standard_name': 'air_temperature',
 'grid_mapping': 'gribfile_projection'}

Below is tying to use metpy to parse the CF grid_namming

[7]:
# my own implementation to get cartopy projection
ds.herbie.crs.proj4_params
[7]:
{'ellps': 'sphere',
 'a': 6371229.0,
 'b': 6371229.0,
 'proj': 'stere',
 'lat_0': 90,
 'lon_0': 225.0,
 'x_0': 0.0,
 'y_0': 0.0,
 'lat_ts': 60.0}
[8]:
ds.metpy.parse_cf().metpy_crs.item().to_cartopy().proj4_params
c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\metpy\xarray.py:355: UserWarning: More than one time coordinate present for variable "gribfile_projection".
  warnings.warn('More than one ' + axis + ' coordinate present for variable'
[8]:
{'ellps': 'sphere',
 'a': 6371229.0,
 'b': 6371229.0,
 'proj': 'stere',
 'lat_0': 90,
 'lon_0': 225.0,
 'x_0': 0.0,
 'y_0': 0.0,
 'lat_ts': 60.0}
[9]:
# What if I don't specify anything?
ds.gribfile_projection.attrs["straight_vertical_longitude_from_pole"] = None
ds.gribfile_projection.attrs["standard_parallel"] = None
ds.gribfile_projection.attrs["latitude_of_projection_origin"] = 90
[10]:
ds.metpy.parse_cf().metpy_crs.item().to_cartopy()
c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\metpy\xarray.py:355: UserWarning: More than one time coordinate present for variable "gribfile_projection".
  warnings.warn('More than one ' + axis + ' coordinate present for variable'
[10]:
2022-12-10T14:32:50.787705 image/svg+xml Matplotlib v3.6.2, https://matplotlib.org/
<cartopy.crs.Stereographic object at 0x00000221260D2D70>
[11]:
ds.metpy.parse_cf().metpy_crs.item().to_cartopy().proj4_params
c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\metpy\xarray.py:355: UserWarning: More than one time coordinate present for variable "gribfile_projection".
  warnings.warn('More than one ' + axis + ' coordinate present for variable'
[11]:
{'ellps': 'sphere',
 'a': 6371229.0,
 'b': 6371229.0,
 'proj': 'stere',
 'lat_0': 90,
 'lon_0': None,
 'x_0': 0.0,
 'y_0': 0.0}
[12]:
ax = (
    EasyMap(
        "50m", crs=ds.metpy.parse_cf().metpy_crs.item().to_cartopy(), figsize=[8, 8]
    )
    .STATES()
    .ax
)
p = ax.pcolormesh(
    ds.longitude, ds.latitude, ds.t2m, transform=pc, **cm_tmp(units="K").cmap_kwargs
)
plt.colorbar(
    p, ax=ax, orientation="horizontal", pad=0.05, **cm_tmp(units="K").cbar_kwargs
)

ax.set_title(ds.t2m.GRIB_name, loc="right")
ax.set_title(f"{ds.model.upper()}: {H.product_description}", loc="left")
gl = ax.gridlines(draw_labels=True)

from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter, LatitudeLocator
import matplotlib.ticker as mticker

gl.ylocator = mticker.FixedLocator([60])
gl.xlocator = mticker.FixedLocator([-180, -135, 180])
c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\metpy\xarray.py:355: UserWarning: More than one time coordinate present for variable "gribfile_projection".
  warnings.warn('More than one ' + axis + ' coordinate present for variable'
../../../_images/user_guide_tutorial_model_notebooks_hrrrak_13_1.png
[ ]: