β Latest Data#
Herbie can help you find the latest model data available with HerbieLatest
and HerbieWait
. These are simple helper functions that loops until Herbie finds data.
[2]:
from herbie import HerbieLatest, HerbieWait
HerbieLatest
#
Herbie can find the latest model grid available. It does this by checking the for data in the most recent time, and then steps back in time a model cycle and checks for that. By default, if data is not found in four attempts, it will return an error.
[3]:
H = HerbieLatest(model="hrrr", fxx=6)
H
β
Found β model=hrrr β product=sfc β 2024-Jan-19 19:00 UTC F06 β GRIB2 @ aws β IDX @ aws
[3]:
ββHerbie HRRR model sfc product initialized 2024-Jan-19 19:00 UTC F06 β source=aws
[4]:
H = HerbieLatest(model="gfs")
H
β
Found β model=gfs β product=pgrb2.0p25 β 2024-Jan-19 18:00 UTC F00 β GRIB2 @ aws β IDX @ aws
[4]:
ββHerbie GFS model pgrb2.0p25 product initialized 2024-Jan-19 18:00 UTC F00 β source=aws
[5]:
# This will error because there will never been
# a lead time of 100 hours.
H = HerbieLatest(model="hrrr", fxx=100)
π Did not find β model=hrrr β product=sfc β 2024-Jan-19 19:00 UTC F100
π Did not find β model=hrrr β product=sfc β 2024-Jan-19 18:00 UTC F100
π Did not find β model=hrrr β product=sfc β 2024-Jan-19 17:00 UTC F100
π Did not find β model=hrrr β product=sfc β 2024-Jan-19 16:00 UTC F100
---------------------------------------------------------------------------
TimeoutError Traceback (most recent call last)
Cell In[5], line 3
1 # This will error because there will never been
2 # a lead time of 100 hours.
----> 3 H = HerbieLatest(model="hrrr", fxx=100)
File ~/GITHUB/Herbie/herbie/latest.py:53, in HerbieLatest(model, priority, periods, **kwargs)
50 if H.grib:
51 return H
---> 53 raise TimeoutError(f"Herbie did not find data for the latest time: {H}")
TimeoutError: Herbie did not find data for the latest time: βHERBIEβ HRRR:sfc
HerbieWait
#
I donβt have the patience to actually try this, but if you want to wait for data to become available, Herbie will use a while loop to wait for data.
In this example, Iβve changed the default wait time and interval just to demonstrate. (The error in this is expected, but if you wait long enough it should work.)
[ ]:
H = HerbieWait(wait_for="10s", check_interval="1s", fxx=39)
π Did not find β model=hrrr β product=sfc β 2024-Jan-19 19:00 UTC F39
π Did not find β model=hrrr β product=sfc β 2024-Jan-19 19:00 UTC F39
π Did not find β model=hrrr β product=sfc β 2024-Jan-19 19:00 UTC F39
π Did not find β model=hrrr β product=sfc β 2024-Jan-19 19:00 UTC F39
π Did not find β model=hrrr β product=sfc β 2024-Jan-19 19:00 UTC F39
---------------------------------------------------------------------------
TimeoutError Traceback (most recent call last)
Cell In[5], line 1
----> 1 HerbieWait(wait_for="10s", check_interval="1s", fxx=39)
File ~/GITHUB/Herbie/herbie/latest.py:107, in HerbieWait(model, priority, wait_for, check_interval, **kwargs)
104 if (pd.Timestamp("now") - timer) >= pd.Timedelta(wait_for):
105 break
--> 107 raise TimeoutError(f"Herbie did not find data in time: {H}")
TimeoutError: Herbie did not find data in time: βHERBIEβ HRRR:sfc