FastHerbie#
Often, data from several GRIB2 files is needed (range of datetimes and/or forecast lead time). FastHerbie()
use multithreading to help you efficiently create multiple Herbie objects. Then you can download many files using multiprocessing. When you open the data with xarray, it will concatenate the DataSets for a range of model runs and forecast lead times.
In this example, we will get the F00-F02 forecasts for each of the runs initialized between 00z-02z on January 1, 2022 (a total of 9 Herbie objects).
[1]:
from herbie import FastHerbie
import pandas as pd
[7]:
# Create a range of dates
DATES = pd.date_range(
start="2022-03-01 00:00",
periods=3,
freq="1H",
)
# Create a range of forecast lead times
fxx = range(0, 3)
[8]:
# Make FastHerbie Object.
FH = FastHerbie(DATES, model="hrrr", fxx=fxx)
FH
[8]:
<herbie.fast.FastHerbie at 0x1302b71fd60>
At itβs core, FastHerbie
uses multithreading to make a list of Herbie objects. The list of Herbie objects is stored in the objects
property.
[9]:
FH.objects
[9]:
[ββHerbie HRRR model sfc product initialized 2022-Mar-01 00:00 UTC F00 β source=aws,
ββHerbie HRRR model sfc product initialized 2022-Mar-01 00:00 UTC F01 β source=aws,
ββHerbie HRRR model sfc product initialized 2022-Mar-01 00:00 UTC F02 β source=aws,
ββHerbie HRRR model sfc product initialized 2022-Mar-01 01:00 UTC F00 β source=aws,
ββHerbie HRRR model sfc product initialized 2022-Mar-01 01:00 UTC F01 β source=aws,
ββHerbie HRRR model sfc product initialized 2022-Mar-01 01:00 UTC F02 β source=aws,
ββHerbie HRRR model sfc product initialized 2022-Mar-01 02:00 UTC F00 β source=aws,
ββHerbie HRRR model sfc product initialized 2022-Mar-01 02:00 UTC F01 β source=aws,
ββHerbie HRRR model sfc product initialized 2022-Mar-01 02:00 UTC F02 β source=aws]
You can download those Herbie objects as full files or subsets.
[7]:
# Download full file
FH.download()
[ ]:
# Download subset
FH.download("TMP:2 m")
You can also read the data with xarray
[11]:
ds = FH.xarray("TMP:2 m", remove_grib=False)
ds
π¨π»βπ Created directory: [C:\Users\blaylock\data\hrrr\20220301]
[11]:
<xarray.Dataset> Dimensions: (time: 3, step: 3, y: 1059, x: 1799) Coordinates: * time (time) datetime64[ns] 2022-03-01 ... 2022-03-01T02:0... * step (step) timedelta64[ns] 00:00:00 01:00:00 02:00:00 heightAboveGround float64 2.0 latitude (y, x) float64 21.14 21.15 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 (step, time) datetime64[ns] 2022-03-01 ... 2022-03-0... Dimensions without coordinates: y, x Data variables: t2m (step, time, y, x) float32 292.7 292.7 ... 263.4 263.4 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 searchString: TMP:2 m