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

Updates to chgres_cube from integration with SRW #610

Merged
merged 13 commits into from
Oct 14, 2024
1 change: 1 addition & 0 deletions docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: readthedocs
channels:
- conda-forge
dependencies:
- python>=3.9,<3.13
- sphinx_rtd_theme=2.0.*
- sphinxcontrib-bibtex=2.6.*
- tree
3 changes: 2 additions & 1 deletion docs/shared/chgres_cube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ chgres_cube:
fix_dir_target_grid: /path/to/fixdir
grib2_file_input_grid: a.file.gb2
mosaic_file_target_grid: /path/to/mosaic/C432.mosaic.halo4.nc
orog_files_target_grid: /path/to/orog/C432.oro_data.tile7.halo4.nc
orog_dir_target_grid: /path/to/fixdir
orog_files_target_grid: C432.oro_data.tile7.halo4.nc
sfc_files_input_grid: sfc.t{{cycle.strftime('%H') }}z.nc
varmap_file: /path/to/varmap_table
vcoord_file_target_grid: /path/to/global_hyblev.l65.txt
Expand Down
34 changes: 27 additions & 7 deletions src/uwtools/drivers/chgres_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,39 @@ def namelist_file(self):
input_files.append(base_file)
if update_values := namelist.get(STR.updatevalues):
config_files = update_values["config"]
for k in ["mosaic_file_target_grid", "vcoord_file_target_grid"]:
input_files.append(config_files[k])
for k in [
"atm_core_files_input_grid",
file_keys = [
"atm_files_input_grid",
"atm_tracer_files_input_grid",
"grib2_file_input_grid",
"mosaic_file_target_grid",
"nst_files_input_grid",
"sfc_files_input_grid",
"orog_files_input_grid",
"orog_files_target_grid",
"sfc_files_input_grid",
]
path_keys = [
"atm_core_files_input_grid",
"atm_tracer_files_input_grid",
"varmap_file",
]:
"vcoord_file_target_grid",
]
dir_keys = [
"data_dir_input_grid",
"data_dir_input_grid",
"fix_dir_target_grid",
"data_dir_input_grid",
"data_dir_input_grid",
"orog_dir_input_grid",
"orog_dir_target_grid",
]
for file_key, dir_key in zip(file_keys, dir_keys):
if file_key and dir_key in config_files:
v = config_files[file_key]
if isinstance(v, str):
full_path = Path(config_files[dir_key]) / config_files[file_key]
input_files.append(full_path)
else:
input_files += v
for k in path_keys:
if k in config_files:
v = config_files[k]
if isinstance(v, str):
Expand Down
64 changes: 51 additions & 13 deletions src/uwtools/resources/jsonschema/chgres-cube.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,57 @@
"update_values": {
"properties": {
"config": {
"additionalProperties": {
"type": [
"array",
"boolean",
"number",
"string"
"additionalProperties": false,
"anyOf": [
{
"required": [
"data_dir_input_grid",
"atm_files_input_grid"
]
},
{
"required": [
"data_dir_input_grid",
"grib2_files_input_grid"
]
},
{
"required": [
"data_dir_input_grid",
"nst_files_input_grid"
]
},
{
"required": [
"data_dir_input_grid",
"sfc_files_input_grid"
]
}
],
"dependencies": {
"atm_files_input_grid": [
"data_dir_input_grid"
],
"grib2_file_input_grid": [
"data_dir_input_grid"
],
"nst_files_input_grid": [
"data_dir_input_grid"
],
"orog_dir_input_grid": [
"orog_files_input_grid"
],
"orog_dir_target_grid": [
"orog_files_target_grid"
],
"orog_files_input_grid": [
"orog_files_dir_grid"
],
"orog_files_target_grid": [
"orog_dir_target_grid"
],
"sfc_files_input_grid": [
"data_dir_input_grid"
]
},
"properties": {
Expand Down Expand Up @@ -91,13 +136,6 @@
"type": "string"
},
"external_model": {
"enum": [
"GFS",
"HRRR",
"NAM",
"RAP",
"UKMET"
],
"type": "string"
},
"fix_dir_target_grid": {
Expand Down
3 changes: 2 additions & 1 deletion src/uwtools/tests/drivers/test_chgres_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def config(tmp_path):
"update_values": {
"config": {
"atm_core_files_input_grid": [str(afile), str(afile)],
"atm_files_input_grid": str(afile),
"atm_files_input_grid": [str(afile), str(afile)],
"atm_tracer_files_input_grid": str(afile),
"atm_weight_file": str(afile),
"convert_atm": True,
Expand All @@ -59,6 +59,7 @@ def config(tmp_path):
"grib2_file_input_grid": str(afile),
"mosaic_file_input_grid": str(afile),
"mosaic_file_target_grid": str(afile),
"nst_files_input_grid": str(afile),
"sfc_files_input_grid": str(afile),
"varmap_file": str(afile),
"vcoord_file_target_grid": str(afile),
Expand Down
9 changes: 3 additions & 6 deletions src/uwtools/tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,8 @@ def test_schema_chgres_cube_namelist_update_values(chgres_cube_config, chgres_cu
# Some entries are required:
for key in ["mosaic_file_target_grid", "vcoord_file_target_grid"]:
assert "is a required property" in errors(with_del(config, key))
# Additional entries of namelist-compatible types are permitted:
for val in [[1, 2, 3], True, 42, 3.14, "bar"]:
assert not errors(with_set(config, val, "foo"))
# Additional top-level keys are not allowed:
assert "Additional properties are not allowed" in errors({**config, "foo": "bar"})
# Namelist values must be of the correct type:
# boolean:
for key in [
Expand All @@ -545,9 +544,6 @@ def test_schema_chgres_cube_namelist_update_values(chgres_cube_config, chgres_cu
"wam_cold_start",
]:
assert "not of type 'boolean'" in errors(with_set(config, None, key))
# enum:
for key in ["external_model", "input_type"]:
assert "is not one of" in errors(with_set(config, None, key))
# integer:
for key in [
"cycle_day",
Expand Down Expand Up @@ -590,6 +586,7 @@ def test_schema_chgres_cube_namelist_update_values(chgres_cube_config, chgres_cu
]:
assert "is not of type 'array', 'string'\n" in errors(with_set(config, None, key))
assert "is not of type 'string'\n" in errors(with_set(config, [1, 2, 3], key))
assert not errors(with_set(config, ["foo", "bar", "baz"], key))


# esg-grid
Expand Down
Loading