Skip to content

Commit

Permalink
addresses blaylockbk#135
Browse files Browse the repository at this point in the history
  • Loading branch information
blaylockbk committed Jan 6, 2023
1 parent 4c504b7 commit ed2fc11
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion herbie/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,15 +1044,18 @@ def xarray(

# Here I'm looping over each dataset in the list returned by cfgrib
for ds in Hxr:
# ----------------
# Add some details
# ----------------
# Note: all attributes should still work with the `ds.to_netcdf()` method.
ds.attrs["model"] = self.model
ds.attrs["product"] = self.product
ds.attrs["description"] = self.DESCRIPTION
ds.attrs["remote_grib"] = self.grib
ds.attrs["local_grib"] = local_file
ds.attrs["local_grib"] = str(local_file)
ds.attrs["searchString"] = searchString

# ----------------------
# Attach CF grid mapping
# ----------------------
# http://cfconventions.org/Data/cf-conventions/cf-conventions-1.8/cf-conventions.html#appendix-grid-mappings
Expand Down
16 changes: 12 additions & 4 deletions tests/test_hrrr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
"""
from datetime import datetime, timedelta

from herbie import Herbie

from herbie import Herbie, Path
import os

now = datetime.now()
today = datetime(now.year, now.month, now.day, now.hour) - timedelta(hours=6)
yesterday = today - timedelta(days=1)
today_str = today.strftime("%Y-%m-%d %H:%M")
yesterday_str = yesterday.strftime("%Y-%m-%d %H:%M")
save_dir = "$TMPDIR/Herbie-Tests/"

save_dir = Path("$TMPDIR/Herbie-Tests/").expand()

def test_hrrr_aws1():
# Test HRRR with datetime.datetime date
Expand All @@ -31,6 +29,16 @@ def test_hrrr_aws1():
H.xarray("TMP:2 m", remove_grib=False)
assert H.get_localFilePath("TMP:2 m").exists()

def test_hrrr_to_netcdf():
"""Check that a xarray Dataset can be written to a NetCDF file."""
H = Herbie(
'2022-01-01 06:00',
model="hrrr",
product="sfc",
save_dir=save_dir,
)
ds = H.xarray("TMP:2 m", remove_grib=False)
ds.to_netcdf(save_dir/"test_hrrr_to_netcdf.nc")

def test_hrrr_aws2():

Expand Down

0 comments on commit ed2fc11

Please sign in to comment.