⌚ 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