Brian Blaylock
July 20, 2021
HRRR-Alaska Data#
There are different products available on the cloud.
[1]:
from herbie.archive import Herbie
from toolbox.cartopy_tools import common_features, pc
from paint.standard2 import cm_tmp
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
🥳 Herbie loaded your custom templates.
[2]:
H = Herbie("2021-07-19", model="hrrrak", product="sfc")
🏋🏻♂️ Found 2021-Jul-19 00:00 UTC F00 [HRRRAK] [product=sfc] GRIB2 file from aws and index file from aws.
[3]:
ds = H.xarray("TMP:2 m above")
ds
[3]:
<xarray.Dataset> Dimensions: (y: 919, x: 1299) Coordinates: time datetime64[ns] 2021-07-19 step timedelta64[ns] 00:00:00 heightAboveGround float64 2.0 latitude (y, x) float64 41.61 41.63 41.64 ... 76.36 76.35 76.34 longitude (y, x) float64 185.1 185.1 185.2 ... 244.0 244.1 244.2 valid_time datetime64[ns] 2021-07-19 Dimensions without coordinates: y, x Data variables: t2m (y, x) float32 289.3 289.3 289.2 ... 272.3 272.4 272.9 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: /p/cwfs/blaylock/data/hrrrak/20210719/subset_450... searchString: TMP:2 m above
[4]:
ax = common_features("50m", crs=ds.herbie.crs, 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")
/p/home/blaylock/anaconda3/envs/herbie/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py:1797: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later.
result = matplotlib.axes.Axes.pcolormesh(self, *args, **kwargs)
[4]:
Text(0.0, 1.0, 'HRRRAK: 2D surface level fields; 3-km resolution')

[5]:
ds.t2m.attrs
[5]:
{'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': 9999,
'GRIB_name': '2 metre temperature',
'GRIB_parameterName': 'Temperature ',
'GRIB_parameterUnits': 'K',
'GRIB_shortName': '2t',
'GRIB_stepRange': '0',
'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
[6]:
# my own implementation to get cartopy projection
ds.herbie.crs.proj4_params
[6]:
{'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}
[7]:
ds.metpy.parse_cf().metpy_crs.item().to_cartopy().proj4_params
/p/home/blaylock/anaconda3/envs/herbie/lib/python3.9/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'
[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]:
# 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
[9]:
ds.metpy.parse_cf().metpy_crs.item().to_cartopy()
/p/home/blaylock/anaconda3/envs/herbie/lib/python3.9/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'
[9]:
<cartopy.crs.Stereographic object at 0x2ae0aba98850>
[10]:
ds.metpy.parse_cf().metpy_crs.item().to_cartopy().proj4_params
/p/home/blaylock/anaconda3/envs/herbie/lib/python3.9/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]:
{'ellps': 'sphere',
'a': 6371229.0,
'b': 6371229.0,
'proj': 'stere',
'lat_0': 90,
'lon_0': None,
'x_0': 0.0,
'y_0': 0.0}
[11]:
ax = (
common_features(
"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])
/p/home/blaylock/anaconda3/envs/herbie/lib/python3.9/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'
/p/home/blaylock/anaconda3/envs/herbie/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py:1797: MatplotlibDeprecationWarning: shading='flat' when X and Y have the same dimensions as C is deprecated since 3.3. Either specify the corners of the quadrilaterals with X and Y, or pass shading='auto', 'nearest' or 'gouraud', or set rcParams['pcolor.shading']. This will become an error two minor releases later.
result = matplotlib.axes.Axes.pcolormesh(self, *args, **kwargs)

[ ]: