Skip to content

Commit

Permalink
Add test_evenly_split_cropland to test_sys_fsurdat_modifier.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsrabin committed Aug 2, 2023
1 parent 9ad4eb0 commit e613405
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions python/ctsm/test/test_sys_fsurdat_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,49 @@ def test_opt_sections(self):
np.testing.assert_array_equal(fsurdat_out_data.T_BUILDING_MIN, lev1)
np.testing.assert_array_equal(fsurdat_out_data.ALB_ROOF_DIR, lev2_two)
np.testing.assert_array_equal(fsurdat_out_data.TK_ROOF, lev2_five)

def test_evenly_split_cropland(self):
"""
Test that evenly splitting cropland works
"""
self._cfg_file_path = os.path.join(
path_to_ctsm_root(),
"python",
"ctsm",
"crop_calendars",
"modify_fsurdat_allcropseverywhere.cfg")
infile_basename_noext = "surfdata_5x5_amazon_16pfts_Irrig_CMIP6_simyr2000_c171214"
outfile = os.path.join(
self._tempdir,
infile_basename_noext + "_output_allcropseverywhere.nc",
)
sys.argv = [
"fsurdat_modifier",
self._cfg_file_path,
"-i",
os.path.join(
self._testinputs_path, infile_basename_noext + ".nc"
),
"-o",
outfile,
]
parser = fsurdat_modifier_arg_process()
fsurdat_modifier(parser)
# Read the resultant output file and make sure the fields are changed as expected
fsurdat_out_data = xr.open_dataset(outfile)
zero0d = np.zeros((5, 5))
hundred0d = np.full((5, 5), 100.0)
zero_urban = np.zeros((3, 5, 5))
Ncrops = fsurdat_out_data.dims["cft"]
pct_cft = np.full((Ncrops, 5, 5), 100/Ncrops)
np.testing.assert_array_equal(fsurdat_out_data.PCT_NATVEG, zero0d)
np.testing.assert_array_equal(fsurdat_out_data.PCT_CROP, hundred0d)
np.testing.assert_array_equal(fsurdat_out_data.PCT_LAKE, zero0d)
np.testing.assert_array_equal(fsurdat_out_data.PCT_WETLAND, zero0d)
np.testing.assert_array_equal(fsurdat_out_data.PCT_LAKE, zero0d)
np.testing.assert_array_equal(fsurdat_out_data.PCT_GLACIER, zero0d)
np.testing.assert_array_equal(fsurdat_out_data.PCT_URBAN, zero_urban)
np.testing.assert_array_equal(fsurdat_out_data.PCT_CFT, pct_cft)

def test_1x1_mexicocity(self):
"""
Expand Down

0 comments on commit e613405

Please sign in to comment.