|
27 | 27 | "atmos_static_scalar_2.ak.nc", |
28 | 28 | "atmos_static_scalar_3.ck.nc"] |
29 | 29 |
|
| 30 | +# Tiled (cubed-sphere) component |
| 31 | +TILED_COMP_NAME = "atmos_cubedsphere" |
| 32 | +TILED_CDLFILES = [f"atmos_cubedsphere_1.tile{t}.cdl" for t in range(1, 7)] |
| 33 | +TILED_NCFILES = [f"atmos_cubedsphere_1.tile{t}.nc" for t in range(1, 7)] |
| 34 | + |
30 | 35 | # Input/Output directories |
31 | 36 | # OutDir for generating netcdf files; used as input for combine-statics task |
32 | 37 | NCGEN_OUT = f"{TEST_DIR}/test-output/ncgen-output" |
@@ -196,6 +201,71 @@ def test_combine_statics_output_data(load_ncfile): |
196 | 201 | assert (val == expected_data).all() |
197 | 202 | #print(f"{v} has values: {val}") |
198 | 203 |
|
| 204 | +#### TILED (CUBED-SPHERE) TEST CASE #### |
| 205 | +# NOTE: The tiled component directory is created inside test_ncgen_tiled_nc_files |
| 206 | +# rather than at module level. An empty component directory would cause |
| 207 | +# `cdo merge *.nc` to fail when the non-tiled test_combine_statics runs first. |
| 208 | + |
| 209 | +def test_tiled_cdl_files_exist(): |
| 210 | + """ |
| 211 | + Test for the existence of tiled CDL test files (one per cube face) |
| 212 | + """ |
| 213 | + assert all(Path(f"{DATA_DIR}/{f}").exists() for f in TILED_CDLFILES) |
| 214 | + |
| 215 | +def test_ncgen_tiled_nc_files(): |
| 216 | + """ |
| 217 | + Generate tiled netCDF files from CDL files; test they exist in the |
| 218 | + correct input location for combine-statics |
| 219 | + """ |
| 220 | + Path(f"{NCGEN_OUT}/{TILED_COMP_NAME}/P0Y/P0Y").mkdir(parents=True, exist_ok=True) |
| 221 | + for cdl, nc in zip(TILED_CDLFILES, TILED_NCFILES): |
| 222 | + output = f"{NCGEN_OUT}/{TILED_COMP_NAME}/P0Y/P0Y/{nc}" |
| 223 | + ex = ["ncgen", "-k", "64-bit offset", |
| 224 | + "-o", output, |
| 225 | + f"{DATA_DIR}/{cdl}"] |
| 226 | + sp = subprocess.run(ex, check=True) |
| 227 | + assert all([sp.returncode == 0, |
| 228 | + Path(output).exists()]) |
| 229 | + |
| 230 | +def test_combine_statics_tiled(monkeypatch): |
| 231 | + """ |
| 232 | + Test that combine-statics produces one output file per tile for a |
| 233 | + tiled (cubed-sphere) component |
| 234 | + """ |
| 235 | + monkeypatch.setenv("inputDir", NCGEN_OUT) |
| 236 | + monkeypatch.setenv("outputDir", COMBINE_STATICS_OUT) |
| 237 | + |
| 238 | + script = f"{COMBINE_STATICS_DIR}/bin/combine-statics" |
| 239 | + sp = subprocess.run(script, check=True) |
| 240 | + |
| 241 | + assert sp.returncode == 0 |
| 242 | + for t in range(1, 7): |
| 243 | + assert Path(f"{COMBINE_STATICS_OUT}/{TILED_COMP_NAME}/{TILED_COMP_NAME}.static.tile{t}.nc").is_file() |
| 244 | + |
| 245 | +@pytest.fixture(name="load_tiled_ncfile") |
| 246 | +def load_tiled_dataset(): |
| 247 | + """ |
| 248 | + Load tile1 output file using xarray for content validation |
| 249 | + """ |
| 250 | + outfile = f"{TILED_COMP_NAME}.static.tile1.nc" |
| 251 | + sf = xr.open_dataset(f"{COMBINE_STATICS_OUT}/{TILED_COMP_NAME}/{outfile}") |
| 252 | + yield sf |
| 253 | + sf.close() |
| 254 | + |
| 255 | +def test_combine_statics_tiled_output_variables(load_tiled_ncfile): |
| 256 | + """ |
| 257 | + Test that tiled output file contains the expected variable |
| 258 | + """ |
| 259 | + assert "orog" in load_tiled_ncfile.data_vars |
| 260 | + |
| 261 | +def test_combine_statics_tiled_output_data(load_tiled_ncfile): |
| 262 | + """ |
| 263 | + Test that tile1 output contains the expected data values |
| 264 | + """ |
| 265 | + expected = np.array([[1, 2], [3, 4]], dtype=np.float32) |
| 266 | + assert (load_tiled_ncfile["orog"].values == expected).all() |
| 267 | + |
| 268 | + |
199 | 269 | #####assert only one lat and lon exists........... |
200 | 270 | # TO-DO: Having issues trying to generate an expected failure when |
201 | 271 | # adding a static netcdf file that should fail at cdo merge |
|
0 commit comments