Skip to content

Commit

Permalink
Updates to chgres_cube from integration with SRW (ufs-community#610)
Browse files Browse the repository at this point in the history
* Updates to chgres_cube
test coverage failing

* revert key order; partial logic fix

* coverage fixed, partial logic updates

* schema and key logic complete

* revert missed changes to chgres_cube.yaml

* cap python version for rtd environment

* fix pi brain typo

* Update src/uwtools/resources/jsonschema/chgres-cube.jsonschema

Co-authored-by: Christina Holt <[email protected]>

* apply changes from comments

* restore missing "atm_files_input_grid"

* remove anyOf requirement with dir

---------

Co-authored-by: Christina Holt <[email protected]>
  • Loading branch information
WeirAE and christinaholtNOAA authored Oct 14, 2024
1 parent e2eb7fc commit a802a35
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 26 deletions.
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.12
- 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
19 changes: 14 additions & 5 deletions src/uwtools/drivers/chgres_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,34 @@ 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"]:
for k in ["mosaic_file_target_grid", "varmap_file", "vcoord_file_target_grid"]:
input_files.append(config_files[k])
for k in [
"atm_core_files_input_grid",
"atm_files_input_grid",
"atm_tracer_files_input_grid",
"grib2_file_input_grid",
"nst_files_input_grid",
"sfc_files_input_grid",
]:
if k in config_files:
grid_path = Path(config_files["data_dir_input_grid"])
v = config_files[k]
if isinstance(v, str):
input_files.append(grid_path / v)
else:
input_files.extend([grid_path / f for f in v])
for k in [
"orog_files_input_grid",
"orog_files_target_grid",
"sfc_files_input_grid",
"varmap_file",
]:
if k in config_files:
grid_path = Path(config_files[k.replace("files", "dir")])
v = config_files[k]
if isinstance(v, str):
input_files.append(v)
input_files.append(grid_path / v)
else:
input_files += v
input_files.extend([grid_path / f for f in v])
yield [file(Path(input_file)) for input_file in input_files]
self._create_user_updated_config(
config_class=NMLConfig,
Expand Down
38 changes: 25 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,31 @@
"update_values": {
"properties": {
"config": {
"additionalProperties": {
"type": [
"array",
"boolean",
"number",
"string"
"additionalProperties": false,
"dependencies": {
"atm_core_files_input_grid": [
"data_dir_input_grid"
],
"atm_files_input_grid": [
"data_dir_input_grid"
],
"atm_tracer_files_input_grid": [
"data_dir_input_grid"
],
"grib2_file_input_grid": [
"data_dir_input_grid"
],
"nst_files_input_grid": [
"data_dir_input_grid"
],
"orog_files_input_grid": [
"orog_dir_input_grid"
],
"orog_files_target_grid": [
"orog_dir_target_grid"
],
"sfc_files_input_grid": [
"data_dir_input_grid"
]
},
"properties": {
Expand Down Expand Up @@ -91,13 +110,6 @@
"type": "string"
},
"external_model": {
"enum": [
"GFS",
"HRRR",
"NAM",
"RAP",
"UKMET"
],
"type": "string"
},
"fix_dir_target_grid": {
Expand Down
7 changes: 6 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,11 @@ def config(tmp_path):
"grib2_file_input_grid": str(afile),
"mosaic_file_input_grid": str(afile),
"mosaic_file_target_grid": str(afile),
"orog_dir_input_grid": "/path/to/dir",
"orog_files_input_grid": [str(afile), str(afile)],
"orog_dir_target_grid": "/path/to/dir",
"orog_files_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

0 comments on commit a802a35

Please sign in to comment.