β 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
[ ]: