Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add natural levels for HRRR #163

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Set zarr chunks for lead time to size 1 in examples.
- Updated HRRR tp to be hourly accumulated (Grib index 090)
- Updated HRRR Lexicon to support natural levels

### Deprecated

Expand Down
12 changes: 10 additions & 2 deletions earth2studio/data/hrrr.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,21 @@ def fetch_dataarray(
# Convert from Earth2Studio variable ID to HRRR id and modifier
sfc_vars = {}
prs_vars = {}
hybrid_vars = {}
for var in variable:
try:
hrrr_str, modifier = HRRRLexicon[var]
hrrr_name = hrrr_str.split("::")

if hrrr_name[0] == "sfc":
sfc_vars[var] = (f":{hrrr_name[1]}", modifier)
else:
elif hrrr_name[0] == "prs":
prs_vars[var] = (f":{hrrr_name[1]}", modifier)
elif hrrr_name[0] == "nat":
hybrid_vars[var] = (f":{hrrr_name[1]}", modifier)
else:
raise ValueError(f"HRRR name {hrrr_name[0]} not found.")

except KeyError: # noqa: PERF203
raise KeyError(f"variable id {var} not found in HRRR lexicon")

Expand All @@ -89,7 +95,9 @@ def fetch_dataarray(

data_arrays = {}
# Process surface and then pressure fields
for product, var_dict in zip(["sfc", "prs"], [sfc_vars, prs_vars]):
for product, var_dict in zip(
["sfc", "prs", "nat"], [sfc_vars, prs_vars, hybrid_vars]
):
fh = FastHerbie(
time,
model="hrrr",
Expand Down
13 changes: 12 additions & 1 deletion earth2studio/lexicon/hrrr.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,25 @@ def build_vocab() -> dict[str, str]:
975,
1000,
]

prs_names = ["UGRD", "VGRD", "HGT", "TMP", "RH", "SPFH"]
e2s_id = ["u", "v", "z", "t", "r", "q"]
prs_variables = {}
for (id, variable) in zip(e2s_id, prs_names):
for level in prs_levels:
prs_variables[f"{id}{level:d}"] = f"prs::{variable}:{level} mb"

return {**sfc_variables, **prs_variables}
hybrid_levels = list(range(51))
hybrid_names = ["UGRD", "VGRD", "HGT", "TMP", "SPFH", "PRES"]
e2s_hybrid_id = ["u_hl", "v_hl", "z_hl", "t_hl", "q_hl", "p_hl"]
hybrid_variables = {}
for (id, variable) in zip(e2s_hybrid_id, hybrid_names):
for level in hybrid_levels:
hybrid_variables[
f"{id}{level:d}"
] = f"nat::{variable}:{level} hybrid level"

return {**sfc_variables, **prs_variables, **hybrid_variables}

VOCAB = build_vocab()

Expand Down
4 changes: 2 additions & 2 deletions test/data/test_hrrr.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
],
],
)
@pytest.mark.parametrize("variable", ["t2m", ["u10m", "u100"]])
@pytest.mark.parametrize("variable", ["t2m", ["u10m", "u100"], ["u_hl1"]])
def test_hrrr_fetch(time, variable):

ds = HRRR(cache=False)
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_hrrr_fx_fetch(time, lead_time):
np.array([np.datetime64("2024-01-01T00:00")]),
],
)
@pytest.mark.parametrize("variable", [["t2m", "sp"]])
@pytest.mark.parametrize("variable", [["t2m", "sp", "t_hl10"]])
@pytest.mark.parametrize("cache", [True, False])
def test_hrrr_cache(time, variable, cache):

Expand Down
8 changes: 7 additions & 1 deletion test/lexicon/test_hrrr_lexicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@


@pytest.mark.parametrize(
"variable", [["t2m"], ["u10m", "v200"], ["u80m", "z500", "q700"]]
"variable",
[
["t2m"],
["u10m", "v200"],
["u80m", "z500", "q700"],
["u_hl1", "v_hl4", "t_hl20", "p_hl30"],
],
)
@pytest.mark.parametrize("device", ["cpu", "cuda:0"])
def test_run_deterministic(variable, device):
Expand Down