Skip to content

Commit 4d4d8ea

Browse files
committed
Fix RRFS natlev domain default to 'na' and add RRFS template tests
1 parent 773b410 commit 4d4d8ea

2 files changed

Lines changed: 104 additions & 2 deletions

File tree

src/herbie/models/rrfs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ def template(self):
3838

3939
# Format the domain parameter (default to conus)
4040
domain_map = {"alaska": "ak", "hawaii": "hi", "puerto rico": "pr"}
41-
self.domain = getattr(self, "domain", None) or "conus"
42-
self.domain = domain_map.get(self.domain, self.domain)
41+
if self.product == "natlev":
42+
self.domain = "na"
43+
else:
44+
self.domain = getattr(self, "domain", None) or "conus"
45+
self.domain = domain_map.get(self.domain, self.domain)
4346

4447
# Resolution depends on the domain
4548
resolution = "2p5km" if self.domain in ("hi", "pr") else "3km"

tests/test_rrfs.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"""Tests for RRFS model template URL generation."""
2+
3+
from datetime import datetime, timedelta
4+
5+
import pytest
6+
7+
from herbie import Herbie, config
8+
9+
now = datetime.now()
10+
today = datetime(now.year, now.month, now.day) - timedelta(hours=12)
11+
12+
save_dir = config["default"]["save_dir"] / "Herbie-Tests-Data/"
13+
14+
15+
def test_rrfs_natlev_domain_forced_to_na():
16+
"""natlev product should always use domain='na', regardless of user input."""
17+
H = Herbie(
18+
today,
19+
model="rrfs",
20+
product="natlev",
21+
fxx=0,
22+
save_dir=save_dir,
23+
)
24+
assert H.domain == "na"
25+
26+
27+
def test_rrfs_natlev_overrides_user_domain():
28+
"""Even if user passes domain='conus', natlev should force domain='na'."""
29+
H = Herbie(
30+
today,
31+
model="rrfs",
32+
product="natlev",
33+
domain="conus",
34+
fxx=0,
35+
save_dir=save_dir,
36+
)
37+
assert H.domain == "na"
38+
39+
40+
def test_rrfs_nat_shorthand():
41+
"""The 'nat' shorthand should normalize to 'natlev' and use domain='na'."""
42+
H = Herbie(
43+
today,
44+
model="rrfs",
45+
product="nat",
46+
fxx=0,
47+
save_dir=save_dir,
48+
)
49+
assert H.product == "natlev"
50+
assert H.domain == "na"
51+
52+
53+
def test_rrfs_prslev_defaults_to_conus():
54+
"""prslev product should default domain to 'conus'."""
55+
H = Herbie(
56+
today,
57+
model="rrfs",
58+
product="prslev",
59+
fxx=0,
60+
save_dir=save_dir,
61+
)
62+
assert H.domain == "conus"
63+
64+
65+
@pytest.mark.parametrize(
66+
"domain_in,domain_out",
67+
[
68+
("alaska", "ak"),
69+
("hawaii", "hi"),
70+
("puerto rico", "pr"),
71+
("na", "na"),
72+
("conus", "conus"),
73+
],
74+
)
75+
def test_rrfs_domain_mapping(domain_in, domain_out):
76+
"""Domain long names should be mapped to their abbreviations."""
77+
H = Herbie(
78+
today,
79+
model="rrfs",
80+
product="prslev",
81+
domain=domain_in,
82+
fxx=0,
83+
save_dir=save_dir,
84+
)
85+
assert H.domain == domain_out
86+
87+
88+
def test_rrfs_natlev_file_exists():
89+
"""Verify the natlev URL actually resolves to a file on S3."""
90+
H = Herbie(
91+
today,
92+
model="rrfs",
93+
product="natlev",
94+
fxx=0,
95+
save_dir=save_dir,
96+
overwrite=True,
97+
)
98+
assert H.grib, "RRFS natlev grib2 file not found"
99+
assert H.idx, "RRFS natlev index file not found"

0 commit comments

Comments
 (0)