πŸ—ΊοΈ Brian’s Maps#

Notice: Carpenter Workshop must be installed.

This notebook demonstrates how to plot GRIB2 data retrieved from Herbie on a map using my custom Carpenter Workshop tools.This is not meant to replace an other Cartopy tutorials, so if you are unfamilar with Cartopy, I suggest you first refer to the Project Pythia Cartopy tutorial.

[1]:
import matplotlib.pyplot as plt
import numpy as np

from herbie import Herbie
from toolbox import EasyMap, pc, ccrs

Download some HRRR data. Let’s look at composite reflectivity

[2]:
ds = Herbie("2022-12-10 12:00").xarray("REFC:entire")
βœ… Found β”Š model=hrrr β”Š product=sfc β”Š 2022-Dec-10 12:00 UTC F00 β”Š GRIB2 @ aws β”Š IDX @ aws

What does the data look like when we plot it?

[3]:
ds.refc.plot()
[3]:
<matplotlib.collections.QuadMesh at 0x19d6cda2470>
../../../_images/user_guide_tutorial_bonus_notebooks_demo_map_5_1.png

Fun fact: this reflectivity field uses -10 as the missing value. Lets just replace any negative number with nan. (Can anyone tell me why there are reflectivities less than zero?)

[4]:
ds["refc"] = ds.refc.where(ds.refc > 0)  # sets all negative values to nan
[5]:
ds.refc.plot()
[5]:
<matplotlib.collections.QuadMesh at 0x19d6f412fe0>
../../../_images/user_guide_tutorial_bonus_notebooks_demo_map_8_1.png

Applying the mask sure makes the reflectivity data look better.

Ok, but we really want to see this data on a map. Let’s use the Cartopy Workshop EasyMap().

[6]:
ax = EasyMap().ax
../../../_images/user_guide_tutorial_bonus_notebooks_demo_map_10_0.png

Notice that it gives us a Platte Carree map of the world. We can use this to plot our HRRR data onto

[7]:
ax = EasyMap().ax
ds.refc.plot(
    x="longitude",
    y="latitude",
    ax=ax,
    transform=pc,
    cbar_kwargs={"shrink": 0.5, "orientation": "horizontal", "pad": 0.01},
)
[7]:
<cartopy.mpl.geocollection.GeoQuadMesh at 0x19d00211150>
../../../_images/user_guide_tutorial_bonus_notebooks_demo_map_12_1.png

We can add other features, like states and a border around the HRRR domain

[8]:
ax = EasyMap().STATES().OCEAN().LAND().DOMAIN(ds).ax
ds.refc.plot(
    x="longitude",
    y="latitude",
    ax=ax,
    transform=pc,
    cbar_kwargs={"shrink": 0.5, "orientation": "horizontal", "pad": 0.01},
)
[8]:
<cartopy.mpl.geocollection.GeoQuadMesh at 0x19d00262080>
../../../_images/user_guide_tutorial_bonus_notebooks_demo_map_14_1.png

Dark mode even looks cool.

[9]:
ax = EasyMap(dark=True).STATES().OCEAN().LAND().DOMAIN(ds).ax
ds.refc.plot(
    x="longitude",
    y="latitude",
    ax=ax,
    transform=pc,
    cbar_kwargs={"shrink": 0.5, "orientation": "horizontal", "pad": 0.01},
)
[9]:
<cartopy.mpl.geocollection.GeoQuadMesh at 0x19d003fbdc0>
../../../_images/user_guide_tutorial_bonus_notebooks_demo_map_16_1.png

To plot on different map projects, we need to know what coordinate system the model uses. Herbie has a custom xarray accessor that uses Metpy and Pygrib to parse the projection informtion.

[10]:
crs = ds.herbie.crs

ax = EasyMap("50m", crs=crs).STATES().OCEAN().LAND().DOMAIN(ds).ax
ds.refc.plot(
    x="longitude",
    y="latitude",
    ax=ax,
    transform=pc,
    cbar_kwargs={"shrink": 0.5, "orientation": "horizontal", "pad": 0.01},
)

ax.adjust_extent();  # make the map extent slightly larger
../../../_images/user_guide_tutorial_bonus_notebooks_demo_map_18_0.png

Now lets zoom on a specific region and show a Stamen map background

[11]:
crs = ds.herbie.crs

ax = EasyMap("50m", crs=crs, dpi=150).STATES().STAMEN(zoom=6).ax
ds.refc.plot(
    x="longitude",
    y="latitude",
    ax=ax,
    transform=pc,
    cmap="gist_ncar",
    vmin=-10,
    vmax=50,
    cbar_kwargs={"shrink": 0.5, "orientation": "horizontal", "pad": 0.01},
)

ax.set_extent([-120, -105, 35, 45], crs=pc)
../../../_images/user_guide_tutorial_bonus_notebooks_demo_map_20_0.png