β Herbie Latest#
A little helper to get the most recent model data. (Not super efficient, but it works).
WARNING: This is deprecated in favor of
HerbieLatest
[1]:
from herbie import Herbie, Herbie_latest, FastHerbie
import pandas as pd
[2]:
%%time
H = Herbie_latest()
H
Could not find 1/6 GRIB files.
CPU times: user 1.04 s, sys: 274 ms, total: 1.31 s
Wall time: 5.62 s
[2]:
ββHerbie HRRR model sfc product initialized 2024-Jan-19 04:00 UTC F00 β source=aws
[5]:
H = Herbie_latest(model="gfs", n=6, freq="6H", fxx=[6])
H
[5]:
ββHerbie GFS model pgrb2.0p25 product initialized 2022-Dec-10 18:00 UTC F06 β source=aws
Latest with a loop#
[ ]:
from herbie import Herbie
import pandas as pd
# Create a list of dates to try
dates = pd.date_range(
pd.Timestamp.utcnow().floor("1h").tz_localize(None), periods=6, freq="-1H"
)
# Find first existing Herbie object
for i in dates:
H = Herbie(i, model="hrrr", priority=["aws", "nomads"])
if H.grib:
break
[16]:
print(dates)
DatetimeIndex(['2024-01-19 05:00:00', '2024-01-19 04:00:00',
'2024-01-19 03:00:00', '2024-01-19 02:00:00',
'2024-01-19 01:00:00', '2024-01-19 00:00:00'],
dtype='datetime64[ns]', freq='-1H')
[17]:
import pandas as pd
# Create a list of dates to try
dates = pd.date_range(
pd.Timestamp.utcnow().floor("1h").tz_localize(None), periods=6, freq="-1H"
)
dates
[17]:
DatetimeIndex(['2024-01-19 05:00:00', '2024-01-19 04:00:00',
'2024-01-19 03:00:00', '2024-01-19 02:00:00',
'2024-01-19 01:00:00', '2024-01-19 00:00:00'],
dtype='datetime64[ns]', freq='-1H')
[19]:
%%time
for i in dates:
H = Herbie(i, model="hrrr", priority=["aws", "nomads"])
if H.grib:
break
π Did not find β model=hrrr β product=sfc β 2024-Jan-19 05:00 UTC F00
β
Found β model=hrrr β product=sfc β 2024-Jan-19 04:00 UTC F00 β GRIB2 @ aws β IDX @ aws
CPU times: user 159 ms, sys: 24 ms, total: 182 ms
Wall time: 2.09 s
[10]:
H
[10]:
ββHerbie HRRR model sfc product initialized 2024-Jan-19 04:00 UTC F00 β source=aws
Most recent GFS (loop)#
[22]:
%%time
from herbie import Herbie
import pandas as pd
# Create a list of dates to try. GFS runs every 6 hours
dates = pd.date_range(
pd.Timestamp.utcnow().floor("6h").tz_localize(None), periods=4, freq="-6H"
)
print(dates)
# Find first existing Herbie object
for i in dates:
H = Herbie(i, model="gfs", priority=["aws", "nomads"])
if H.grib:
break
DatetimeIndex(['2024-01-19 00:00:00', '2024-01-18 18:00:00',
'2024-01-18 12:00:00', '2024-01-18 06:00:00'],
dtype='datetime64[ns]', freq='-6H')
β
Found β model=gfs β product=pgrb2.0p25 β 2024-Jan-19 00:00 UTC F00 β GRIB2 @ aws β IDX @ aws
CPU times: user 97 ms, sys: 12.3 ms, total: 109 ms
Wall time: 848 ms
[25]:
%%time
from herbie import Herbie
import pandas as pd
# Create a list of dates to try. GFS runs every 6 hours
dates = pd.date_range(
pd.Timestamp.utcnow().floor("1h").tz_localize(None), periods=12, freq="-1H"
)
print(dates)
# Find first existing Herbie object
for i in dates:
H = Herbie(i, model="gfs", priority=["aws", "nomads"])
if H.grib:
break
DatetimeIndex(['2024-01-19 05:00:00', '2024-01-19 04:00:00',
'2024-01-19 03:00:00', '2024-01-19 02:00:00',
'2024-01-19 01:00:00', '2024-01-19 00:00:00',
'2024-01-18 23:00:00', '2024-01-18 22:00:00',
'2024-01-18 21:00:00', '2024-01-18 20:00:00',
'2024-01-18 19:00:00', '2024-01-18 18:00:00'],
dtype='datetime64[ns]', freq='-1H')
π Did not find β model=gfs β product=pgrb2.0p25 β 2024-Jan-19 05:00 UTC F00
π Did not find β model=gfs β product=pgrb2.0p25 β 2024-Jan-19 04:00 UTC F00
π Did not find β model=gfs β product=pgrb2.0p25 β 2024-Jan-19 03:00 UTC F00
π Did not find β model=gfs β product=pgrb2.0p25 β 2024-Jan-19 02:00 UTC F00
π Did not find β model=gfs β product=pgrb2.0p25 β 2024-Jan-19 01:00 UTC F00
β
Found β model=gfs β product=pgrb2.0p25 β 2024-Jan-19 00:00 UTC F00 β GRIB2 @ aws β IDX @ aws
CPU times: user 638 ms, sys: 54.9 ms, total: 693 ms
Wall time: 7.6 s
Wait for specific time#
[28]:
import time
time.sleep(5)
[34]:
import time
now = pd.Timestamp.utcnow().floor("1h").tz_localize(None)
attempts = 0
H = Herbie(now, model="hrrr", priority=["aws", "nomads"])
while H.grib is None:
# Try to find file again
H = Herbie(now, model="hrrr", priority=["aws", "nomads"])
# Wait 5 seconds
time.sleep(5)
attempts += 1
print(f"{attempts=}")
β
Found β model=hrrr β product=sfc β 2024-Jan-19 05:00 UTC F00 β GRIB2 @ aws β IDX @ aws