Skip to content

Commit

Permalink
fix var name
Browse files Browse the repository at this point in the history
  • Loading branch information
dfulu committed Feb 27, 2025
1 parent f1f3e4f commit 742618e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 41 deletions.
74 changes: 34 additions & 40 deletions src/pvnet_app/data/nwp.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,46 +257,40 @@ def extend_to_shetlands(self, ds: xr.Dataset) -> xr.Dataset:
def rename_variables(self, ds):
"""Rename the ECMWF variables to match the training data"""

if ("HRES-IFS_uk" in ds.data_vars) or ("hres-ifs_uk" in ds.data_vars):
logger.info("Renaming the ECMWF variables")
ds = ds.rename(
{
"HRES-IFS_uk": "ECMWF_UK",
"hres-ifs_uk": "ECMWF_UK",
}
)

# rename variable names in the variable coordinate
# This is a renaming from ECMWF variables to what we use in the ML Model
# This change happened in the new nwp-consumer>=1.0.0
# Ideally we won't need this step in the future
variable_coords = ds.variable.values
rename = {
"cloud_cover_high": "hcc",
"cloud_cover_low": "lcc",
"cloud_cover_medium": "mcc",
"cloud_cover_total": "tcc",
"snow_depth_gl": "sde",
"direct_shortwave_radiation_flux_gl": "sr",
"downward_longwave_radiation_flux_gl": "dlwrf",
"downward_shortwave_radiation_flux_gl": "dswrf",
"downward_ultraviolet_radiation_flux_gl": "duvrs",
"temperature_sl": "t2m",
"total_precipitation_rate_gl": "prate",
"visibility_sl": "vis",
"wind_u_component_100m": "u100",
"wind_u_component_10m": "u10",
"wind_u_component_200m": "u200",
"wind_v_component_100m": "v100",
"wind_v_component_10m": "v10",
"wind_v_component_200m": "v200"
}

for k, v in rename.items():
variable_coords[variable_coords == k] = v

# assign the new variable names
ds = ds.assign_coords(variable=variable_coords)
logger.info("Renaming the ECMWF variables")
ds = ds.rename({"hres-ifs_uk": "ECMWF_UK"})

# rename variable names in the variable coordinate
# This is a renaming from ECMWF variables to what we use in the ML Model
# This change happened in the new nwp-consumer>=1.0.0
# Ideally we won't need this step in the future
variable_coords = ds.variable.values
rename = {
"cloud_cover_high": "hcc",
"cloud_cover_low": "lcc",
"cloud_cover_medium": "mcc",
"cloud_cover_total": "tcc",
"snow_depth_gl": "sde",
"direct_shortwave_radiation_flux_gl": "sr",
"downward_longwave_radiation_flux_gl": "dlwrf",
"downward_shortwave_radiation_flux_gl": "dswrf",
"downward_ultraviolet_radiation_flux_gl": "duvrs",
"temperature_sl": "t2m",
"total_precipitation_rate_gl": "prate",
"visibility_sl": "vis",
"wind_u_component_100m": "u100",
"wind_u_component_10m": "u10",
"wind_u_component_200m": "u200",
"wind_v_component_100m": "v100",
"wind_v_component_10m": "v10",
"wind_v_component_200m": "v200"
}

for k, v in rename.items():
variable_coords[variable_coords == k] = v

# assign the new variable names
ds = ds.assign_coords(variable=variable_coords)

return ds

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def nwp_ukv_data(test_t0):
def nwp_ecmwf_data(test_t0):
return make_nwp_data(
shell_path=f"{os.path.dirname(os.path.abspath(__file__))}/test_data/nwp_ecmwf_shell.zarr",
varname="HRES-IFS_uk",
varname="hres-ifs_uk",
test_t0=test_t0,
)

Expand Down

0 comments on commit 742618e

Please sign in to comment.