Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/herbie/models/rrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ def template(self):

# Format the domain parameter (default to conus)
domain_map = {"alaska": "ak", "hawaii": "hi", "puerto rico": "pr"}
self.domain = getattr(self, "domain", None) or "conus"
self.domain = domain_map.get(self.domain, self.domain)
if self.product == "natlev":
self.domain = "na"
else:
self.domain = getattr(self, "domain", None) or "conus"
self.domain = domain_map.get(self.domain, self.domain)

# Resolution depends on the domain
resolution = "2p5km" if self.domain in ("hi", "pr") else "3km"
Expand Down
99 changes: 99 additions & 0 deletions tests/test_rrfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"""Tests for RRFS model template URL generation."""

from datetime import datetime, timedelta

import pytest

from herbie import Herbie, config

now = datetime.now()
today = datetime(now.year, now.month, now.day) - timedelta(hours=12)

save_dir = config["default"]["save_dir"] / "Herbie-Tests-Data/"


def test_rrfs_natlev_domain_forced_to_na():
"""natlev product should always use domain='na', regardless of user input."""
H = Herbie(
today,
model="rrfs",
product="natlev",
fxx=0,
save_dir=save_dir,
)
assert H.domain == "na"


def test_rrfs_natlev_overrides_user_domain():
"""Even if user passes domain='conus', natlev should force domain='na'."""
H = Herbie(
today,
model="rrfs",
product="natlev",
domain="conus",
fxx=0,
save_dir=save_dir,
)
assert H.domain == "na"


def test_rrfs_nat_shorthand():
"""The 'nat' shorthand should normalize to 'natlev' and use domain='na'."""
H = Herbie(
today,
model="rrfs",
product="nat",
fxx=0,
save_dir=save_dir,
)
assert H.product == "natlev"
assert H.domain == "na"


def test_rrfs_prslev_defaults_to_conus():
"""prslev product should default domain to 'conus'."""
H = Herbie(
today,
model="rrfs",
product="prslev",
fxx=0,
save_dir=save_dir,
)
assert H.domain == "conus"


@pytest.mark.parametrize(
"domain_in,domain_out",
[
("alaska", "ak"),
("hawaii", "hi"),
("puerto rico", "pr"),
("na", "na"),
("conus", "conus"),
],
)
def test_rrfs_domain_mapping(domain_in, domain_out):
"""Domain long names should be mapped to their abbreviations."""
H = Herbie(
today,
model="rrfs",
product="prslev",
domain=domain_in,
fxx=0,
save_dir=save_dir,
)
assert H.domain == domain_out


def test_rrfs_natlev_file_exists():
"""Verify the natlev URL actually resolves to a file on S3."""
H = Herbie(
today,
model="rrfs",
product="natlev",
fxx=0,
save_dir=save_dir,
overwrite=True,
)
assert H.grib, "RRFS natlev grib2 file not found"
assert H.idx, "RRFS natlev index file not found"
Loading