⌚ 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.

[17]:
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#

If you want to wait for model data to become available in real time, 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.)

[13]:
import pandas as pd
[14]:
run = pd.Timestamp("now", tz="utc").floor('1h').replace(tzinfo=None)
H = HerbieWait(run=run, model="rap", product="awp130pgrb", wait_for="10s", check_interval="1s", fxx=0)
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
---------------------------------------------------------------------------
TimeoutError                              Traceback (most recent call last)
Cell In[14], line 2
      1 run = pd.Timestamp("now", tz="utc").floor('1h').replace(tzinfo=None)
----> 2 H = HerbieWait(run=run, model="rap", product="awp130pgrb", wait_for="10s", check_interval="1s", fxx=0)

File ~/mapwall_dev/herbie-dev/herbie/latest.py:110, in HerbieWait(run, model, priority, wait_for, check_interval, **kwargs)
    108     # Error out if timeout is exceeded
    109     if (pd.Timestamp("now") - timer) >= pd.Timedelta(wait_for):
--> 110         raise TimeoutError(f"Herbie did not find data in time: {H}")
    112 return Herbie(run, model=model, priority=priority, **kwargs)

TimeoutError: Herbie did not find data in time: β•‘HERBIEβ•  RAP:awp130pgrb

Here’s an example that takes a while to run, demonstrating that it works!

[15]:
H = HerbieWait(run=run, model="rap", product="awp130pgrb", wait_for="2h", check_interval="120s", fxx=0)
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
πŸ’” Did not find β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00
βœ… Found β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00 β”Š GRIB2 @ nomads β”Š IDX @ nomads
βœ… Found β”Š model=rap β”Š product=awp130pgrb β”Š 2024-May-21 17:00 UTC F00 β”Š GRIB2 @ nomads β”Š IDX @ nomads
[16]:
H
[16]:
β–Œβ–ŒHerbie RAP model awp130pgrb product initialized 2024-May-21 17:00 UTC F00 β”Š source=nomads
[ ]: