Skip to content

Commit

Permalink
Merge remote-tracking branch 'escomp/ctsm5.2.mksurfdata' into ctsm5.2…
Browse files Browse the repository at this point in the history
…_makefile

 Conflicts:
	.git-blame-ignore-revs
	python/ctsm/modify_input_files/modify_fsurdat.py
	python/ctsm/test/test_sys_fsurdat_modifier.py
	python/ctsm/test/test_sys_mesh_modifier.py
	python/ctsm/test/test_unit_fsurdat_modifier.py
	python/ctsm/test/test_unit_subset_data.py
	tools/mksurfdata_esmf/src/mksurfdata.F90
	tools/site_and_regional/default_data.cfg
  • Loading branch information
ekluzek committed Nov 16, 2023
2 parents 5179d62 + 9583b22 commit f714c38
Show file tree
Hide file tree
Showing 31 changed files with 158 additions and 103 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ e44dc469439e02e9ee582dab274d890ebdfab104
b88e1cd1b28e3609684c79a2ec0e88f26cfc362b
51c102c5df2e0ef971b5f8eeeb477567899af63a
7dacad70e74e2ec97f6492d4e7a3cb5dd498bcd7
a0d014fae9550dd9ffbc934abd29ef16176f8208
c7b7ca1d94ac19abb9ecea9fb5b712ddbdd6645d
b565b55ce7a9f8d812a573d716a5fd3d78cfea81
fdf72cd011e2ba318987a1e100efc5a1847c9d04
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ ctsm.input_data_list.previous
/tools/mksurfdata_esmf/PET*
/tools/mksurfdata_esmf/job_name.o*
/tools/mksurfdata_esmf/mksurfdata_in
/tools/mksurfdata_esmf/bld
/tools/mksurfdata_esmf/src
/tools/mksurfdata_esmf/surfdata_*.nc
/tools/mksurfdata_esmf/landuse.timeseries_*.nc
/tools/mksurfdata_esmf/mksurfdata_jobscript_multi
Expand Down
3 changes: 2 additions & 1 deletion cime_config/SystemTests/mksurfdataesmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@ def _modify_user_nl(self):
"""
append_to_user_nl_files(caseroot = self._get_caseroot(),
component = "clm",
contents = "fsurdat = '{}'".format(self._fsurdat_nc))
contents = "fsurdat = '{}'".format(self._fsurdat_nc) + "\n" +
"convert_ocean_to_land = .true.")
10 changes: 9 additions & 1 deletion python/ctsm/modify_input_files/fsurdat_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ def read_cfg_subgrid(config, cfg_path, numurbl=3):

subgrid_settings = {}
var_list = config.options(section)
valid_list = ["pct_natveg", "pct_crop", "pct_lake", "pct_glacier", "pct_wetland", "pct_urban"]
valid_list = [
"pct_natveg",
"pct_crop",
"pct_lake",
"pct_glacier",
"pct_wetland",
"pct_urban",
"pct_ocean",
]
varsum = 0
for var in var_list:
if valid_list.count(var) == 0:
Expand Down
6 changes: 6 additions & 0 deletions python/ctsm/modify_input_files/modify_fsurdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ def check_varlist(
abort(
"Variable "
+ varname
+ " is "
+ str(len(val))
+ " is of the wrong size. It should be = "
+ str(dim1)
+ " in "
Expand Down Expand Up @@ -363,6 +365,7 @@ def zero_nonveg(self):
self.setvar_lev0("PCT_WETLAND", 0)
self.setvar_lev0("PCT_URBAN", 0)
self.setvar_lev0("PCT_GLACIER", 0)
self.setvar_lev0("PCT_OCEAN", 0)

def setvar_lev0(self, var, val):
"""
Expand Down Expand Up @@ -409,6 +412,7 @@ def set_idealized(self):
std_elev = 0 # standard deviation of elevation
slope = 0 # mean topographic slope
landfrac_pft = 1
landfrac_mksurfdata = 1
# if pct_nat_veg had to be set to less than 100, then each special
# landunit would have to receive a unique pct value rather than the
# common value used here in pct_not_nat_veg = 0
Expand All @@ -426,11 +430,13 @@ def set_idealized(self):
self.setvar_lev0("zbedrock", zbedrock)
self.setvar_lev0("SOIL_COLOR", soil_color)
self.setvar_lev0("LANDFRAC_PFT", landfrac_pft)
self.setvar_lev0("LANDFRAC_MKSURFDATA", landfrac_mksurfdata)
self.setvar_lev0("PCT_WETLAND", pct_not_nat_veg)
self.setvar_lev0("PCT_CROP", pct_not_nat_veg)
self.setvar_lev0("PCT_LAKE", pct_not_nat_veg)
self.setvar_lev0("PCT_URBAN", pct_not_nat_veg)
self.setvar_lev0("PCT_GLACIER", pct_not_nat_veg)
self.setvar_lev0("PCT_OCEAN", pct_not_nat_veg)
self.setvar_lev0("PCT_NATVEG", pct_nat_veg)

for lev in self.file.nlevsoi:
Expand Down
1 change: 1 addition & 0 deletions python/ctsm/site_and_regional/single_point_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ def modify_surfdata_atpoint(self, f_orig):
f_mod["PCT_WETLAND"][:, :] = 0.0
f_mod["PCT_URBAN"][:, :, :] = 0.0
f_mod["PCT_GLACIER"][:, :] = 0.0
f_mod["PCT_OCEAN"][:, :] = 0.0

if self.dom_pft is not None:
max_dom_pft = max(self.dom_pft)
Expand Down
29 changes: 11 additions & 18 deletions python/ctsm/test/test_sys_fsurdat_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setUp(self):
self._testinputs_path = testinputs_path
self._fsurdat_in = os.path.join(
testinputs_path,
"surfdata_5x5_amazon_hist_78pfts_CMIP6_2000_c230517.nc",
"surfdata_5x5_amazon_hist_16pfts_CMIP6_2000_c231031.nc",
)
self._tempdir = tempfile.mkdtemp()
self._cfg_file_path = os.path.join(self._tempdir, "modify_fsurdat.cfg")
Expand Down Expand Up @@ -76,8 +76,8 @@ def test_short_config(self):
self._cfg_file_path = os.path.join(self._testinputs_path, "modify_fsurdat_short.cfg")
sys.argv = ["fsurdat_modifier", self._cfg_file_path]
parser = fsurdat_modifier_arg_process()
fsurdat_out = (
"ctsm/test/testinputs/surfdata_5x5_amazon_hist_78pfts_CMIP6_2000_c230517_out.nc"
fsurdat_out = os.path.join(
self._testinputs_path, "surfdata_5x5_amazon_hist_16pfts_CMIP6_2000_c231031.out.nc"
)
if os.path.exists(fsurdat_out):
os.remove(fsurdat_out)
Expand Down Expand Up @@ -134,14 +134,14 @@ def test_opt_sections(self):
self._cfg_file_path = os.path.join(self._testinputs_path, "modify_fsurdat_opt_sections.cfg")
outfile = os.path.join(
self._tempdir,
"surfdata_5x5_amazon_hist_78pfts_CMIP6_2000_c230517_output_urban.nc",
"surfdata_5x5_amazon_hist_16pfts_CMIP6_2000_c231031_output_urban.nc",
)
sys.argv = [
"fsurdat_modifier",
self._cfg_file_path,
"-i",
os.path.join(
self._testinputs_path, "surfdata_5x5_amazon_hist_78pfts_CMIP6_2000_c230517.nc"
self._testinputs_path, "surfdata_5x5_amazon_hist_16pfts_CMIP6_2000_c231031.nc"
),
"-o",
outfile,
Expand Down Expand Up @@ -180,16 +180,9 @@ def test_opt_sections(self):
lev2_two = np.empty((2, 3, 5, 5))
lev2_two[0, :, :, :] = 200.0
lev2_two[1, :, :, :] = 100.0
lev2_five = np.empty((5, 3, 5, 5))
lev2_five[0, :, :, :] = 1.0
lev2_five[1, :, :, :] = 2.0
lev2_five[2, :, :, :] = 3.0
lev2_five[3, :, :, :] = 4.0
lev2_five[4, :, :, :] = 5.0
lev2_ten = np.empty((10, 3, 5, 5))
for l in range(10):
lev2_ten[l, :, :, :] = float(l + 1)

for x in range(10):
lev2_ten[x, :, :, :] = float(x + 1)
lev1 = np.array(
[
[
Expand Down Expand Up @@ -219,7 +212,7 @@ def test_opt_sections(self):
np.testing.assert_array_equal(fsurdat_out_data.PCT_CROP, zero0d)
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_OCEAN, zero0d)
np.testing.assert_array_equal(fsurdat_out_data.PCT_GLACIER, zero0d)
np.testing.assert_array_equal(fsurdat_out_data.PCT_URBAN, pct_urban)
np.testing.assert_array_equal(fsurdat_out_data.LAKEDEPTH, one0d * 200.0)
Expand All @@ -236,15 +229,15 @@ def test_1x1_mexicocity(self):
)
expectfile = os.path.join(
self._testinputs_path,
"surfdata_1x1_mexicocityMEX_hist_16pfts_Irrig_CMIP6_simyr2000_c221206_modified.nc",
"surfdata_1x1_mexicocityMEX_hist_16pfts_CMIP6_2000_c231103_modified.nc",
)
outfile = os.path.join(
self._tempdir,
"surfdata_1x1_mexicocityMEX_hist_16pfts_Irrig_CMIP6_simyr2000_c221206_modified.nc",
"surfdata_1x1_mexicocityMEX_hist_16pfts_CMIP6_2000_c231103_modified.nc",
)
infile = os.path.join(
self._testinputs_path,
"surfdata_1x1_mexicocityMEX_hist_16pfts_Irrig_CMIP6_simyr2000_c221206.nc",
"surfdata_1x1_mexicocityMEX_hist_16pfts_CMIP6_2000_c231103.nc",
)
sys.argv = [
"fsurdat_modifier",
Expand Down
11 changes: 7 additions & 4 deletions python/ctsm/test/test_sys_mesh_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def setUp(self):
self._cfg_template_path = os.path.join(
path_to_ctsm_root(), "tools/modify_input_files/modify_mesh_template.cfg"
)
self.testinputs_path = os.path.join(path_to_ctsm_root(), "python/ctsm/test/testinputs")
self.fsurdat_in = None
testinputs_path = os.path.join(path_to_ctsm_root(), "python/ctsm/test/testinputs")
fsurdat_in = os.path.join(
testinputs_path,
"surfdata_5x5_amazon_hist_16pfts_CMIP6_2000_c231031.nc",
)
self._tempdir = tempfile.mkdtemp()
self._cfg_file_path = os.path.join(self._tempdir, "modify_mesh_mask.cfg")
self._mesh_mask_in = os.path.join(self._tempdir, "mesh_mask_in.nc")
Expand Down Expand Up @@ -116,8 +119,8 @@ def createLandMaskFile(self):
if os.path.exists(self._landmask_file):
os.remove(self._landmask_file)
ncap2_cmd = (
"ncap2 -A -v -s 'mod_lnd_props=LANDFRAC_PFT.convert(NC_INT)' "
+ "-A -v -s 'landmask=LANDFRAC_PFT.convert(NC_INT)' "
"ncap2 -A -v -s 'mod_lnd_props=LANDFRAC_MKSURFDATA.convert(NC_INT)' "
+ "-A -v -s 'landmask=LANDFRAC_MKSURFDATA.convert(NC_INT)' "
+ f"-A -v -s {self._lat_varname}={self._lat_varname} "
+ f"-A -v -s {self._lon_varname}={self._lon_varname} "
+ f"{self.fsurdat_in} {self._landmask_file}"
Expand Down
10 changes: 5 additions & 5 deletions python/ctsm/test/test_unit_fsurdat_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,9 @@ def setUp(self):
self._testinputs_path = testinputs_path
self._fsurdat_in = os.path.join(
testinputs_path,
"surfdata_5x5_amazon_hist_78pfts_CMIP6_2000_c230517.nc",
"surfdata_5x5_amazon_hist_16pfts_CMIP6_2000_c231031.nc",
)
self._tempdir = tempfile.mkdtemp()
self._fsurdat_in = os.path.join(
testinputs_path,
"surfdata_5x5_amazon_hist_78pfts_CMIP6_2000_c230517.nc",
)
self._fsurdat_out = os.path.join(self._tempdir, "fsurdat_out.nc")
sys.argv = [
"fsurdat_modifier",
Expand Down Expand Up @@ -133,6 +129,7 @@ def test_read_subgrid_allglacier(self):
self.config.set(section, "pct_urban", "0. 0. 0.")
self.config.set(section, "pct_lake", "0.")
self.config.set(section, "pct_wetland", "0.")
self.config.set(section, "pct_ocean", "0.")
self.config.set(section, "pct_glacier", "100.")
self.config.set(section, "pct_natveg", "0.")
self.config.set(section, "pct_crop", "0.")
Expand All @@ -146,6 +143,7 @@ def test_read_subgrid_allspecial(self):
self.config.set(section, "pct_urban", "0. 0. 0.")
self.config.set(section, "pct_lake", "25.")
self.config.set(section, "pct_wetland", "35.")
self.config.set(section, "pct_ocean", "0.")
self.config.set(section, "pct_glacier", "40.")
self.config.set(section, "pct_natveg", "0.")
self.config.set(section, "pct_crop", "0.")
Expand All @@ -159,6 +157,7 @@ def test_read_subgrid_allurban(self):
self.config.set(section, "pct_urban", "100.0 0.0 0.0")
self.config.set(section, "pct_lake", "0.")
self.config.set(section, "pct_wetland", "0.")
self.config.set(section, "pct_ocean", "0.")
self.config.set(section, "pct_glacier", "0.")
self.config.set(section, "pct_natveg", "0.")
self.config.set(section, "pct_crop", "0.")
Expand Down Expand Up @@ -218,6 +217,7 @@ def test_subgrid_notsumtohundred(self):
self.config.set(section, "pct_urban", "0. 0. 0.")
self.config.set(section, "pct_lake", "0.")
self.config.set(section, "pct_wetland", "0.")
self.config.set(section, "pct_ocean", "0.")
self.config.set(section, "pct_glacier", "0.")
self.config.set(section, "pct_natveg", "0.")
self.config.set(section, "pct_crop", "0.")
Expand Down
2 changes: 1 addition & 1 deletion python/ctsm/test/test_unit_modify_fsurdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def test_check_varlist_lists_wrongsizes(self):
lev1list = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
settings = {"var_lev1": lev1list}
with self.assertRaisesRegex(
SystemExit, "Variable var_lev1 is of the wrong size. It should be"
SystemExit, "Variable var_lev1 is " + str(len(lev1list)) + ". It should be"
):
self.modify_fsurdat.check_varlist(settings)

Expand Down
12 changes: 12 additions & 0 deletions python/ctsm/test/test_unit_singlept_data_surfdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ class TestSinglePointCaseSurfaceNoCrop(unittest.TestCase):
coords={"lsmlat": lsmlat, "lsmlon": lsmlon},
attrs={"long_name": "percent wetland", "units": "unitless"},
),
"PCT_OCEAN": xr.DataArray(
data=np.random.rand(1, 1),
dims=["lsmlat", "lsmlon"],
coords={"lsmlat": lsmlat, "lsmlon": lsmlon},
attrs={"long_name": "percent ocean", "units": "unitless"},
),
"PCT_URBAN": xr.DataArray(
data=np.random.rand(1, 1, 3),
dims=["lsmlat", "lsmlon", "numurbl"],
Expand Down Expand Up @@ -656,6 +662,12 @@ class TestSinglePointCaseSurfaceCrop(unittest.TestCase):
coords={"lsmlat": lsmlat, "lsmlon": lsmlon},
attrs={"long_name": "percent wetland", "units": "unitless"},
),
"PCT_OCEAN": xr.DataArray(
data=np.random.rand(1, 1),
dims=["lsmlat", "lsmlon"],
coords={"lsmlat": lsmlat, "lsmlon": lsmlon},
attrs={"long_name": "percent ocean", "units": "unitless"},
),
"PCT_URBAN": xr.DataArray(
data=np.random.rand(1, 1, 3),
dims=["lsmlat", "lsmlon", "numurbl"],
Expand Down
4 changes: 2 additions & 2 deletions python/ctsm/test/test_unit_subset_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_inputdata_setup_files_basic(self):
files = setup_files(self.args, self.defaults, self.cesmroot)
self.assertEqual(
files["fsurf_in"],
"surfdata_0.9x1.25_hist_16pfts_CMIP6_2000_c230517.nc",
"surfdata_0.9x1.25_hist_16pfts_CMIP6_1850-2015_c231031.nc",
"fsurf_in filename not whats expected",
)
self.assertEqual(
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_check_args_outsurfdat_fails_without_overwrite(self):
outfile = os.path.join(
os.getcwd(),
"ctsm/test/testinputs/",
"surfdata_1x1_mexicocityMEX_hist_16pfts_Irrig_CMIP6_simyr2000_c221206.nc",
"surfdata_1x1_mexicocityMEX_hist_16pfts_CMIP6_2000_c231103.nc",
)
self.assertTrue(os.path.exists(outfile), str(outfile) + " outfile should exist")

Expand Down
8 changes: 4 additions & 4 deletions python/ctsm/test/testinputs/default_data.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ tpqwname = CLMGSWP3v1.TPQW

[surfdat]
dir = lnd/clm2/surfdata_esmf/ctsm5.2.0
surfdat_16pft = surfdata_0.9x1.25_hist_16pfts_CMIP6_2000_c230517.nc
surfdat_78pft = surfdata_0.9x1.25_hist_78pfts_CMIP6_2000_c230517.nc
surfdat_16pft = surfdata_0.9x1.25_hist_16pfts_CMIP6_1850-2015_c231031.nc
surfdat_78pft = surfdata_0.9x1.25_hist_78pfts_CMIP6_1850-2015_c231031.nc

[landuse]
dir = lnd/clm2/surfdata_esmf/ctsm5.2.0
landuse_16pft = landuse.timeseries_0.9x1.25_hist_78_CMIP6_1850-2015_c230601.nc
landuse_78pft = landuse.timeseries_0.9x1.25_hist_78_CMIP6_1850-2015_c230601.nc
landuse_16pft = landuse.timeseries_0.9x1.25_hist_16_CMIP6_1850-2015_c231031.nc
landuse_78pft = landuse.timeseries_0.9x1.25_hist_78_CMIP6_1850-2015_c231031.nc

[domain]
file = share/domains/domain.lnd.fv0.9x1.25_gx1v7.151020.nc
15 changes: 8 additions & 7 deletions python/ctsm/test/testinputs/modify_fsurdat_1x1mexicocity.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ PCT_NATVEG= 0.0
PCT_GLACIER= 0.0
PCT_WETLAND= 0.0
PCT_LAKE = 0.0
PCT_OCEAN = 0.0

# Section with a list of variables to prcoess
[modify_fsurdat_variable_list]
Expand Down Expand Up @@ -70,13 +71,13 @@ ALB_ROOF_DIF = 0.2 0.2
ALB_WALL_DIR = 0.25 0.25
ALB_WALL_DIF = 0.25 0.25

# Variabls on nlevurb which is 5
TK_ROOF = 0.20 0.93 0.93 0.03 0.16
TK_WALL = 0.88 0.88 0.88 0.88 0.88
TK_IMPROAD = 0.82 0.82 2.10 2.10 2.10
CV_ROOF = 1760000.0 1500000.0 1500000.0 250000.0 870000.0
CV_WALL = 1540000.0 1540000.0 1540000.0 1540000.0 1540000.0
CV_IMPROAD = 1740000.0 1740000.0 2000000.0 2000000.0 2000000.0
# Variabls on nlevurb which is 10
TK_ROOF = 0.20 0.93 0.93 0.03 0.16 0.20 0.93 0.93 0.03 0.16
TK_WALL = 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88 0.88
TK_IMPROAD = 0.82 0.82 2.10 2.10 2.10 0.82 0.82 2.10 2.10 2.10
CV_ROOF = 1760000.0 1500000.0 1500000.0 250000.0 870000.0 1760000.0 1500000.0 1500000.0 250000.0 870000.0
CV_WALL = 1540000.0 1540000.0 1540000.0 1540000.0 1540000.0 1540000.0 1540000.0 1540000.0 1540000.0 1540000.0
CV_IMPROAD = 1740000.0 1740000.0 2000000.0 2000000.0 2000000.0 1740000.0 1740000.0 2000000.0 2000000.0 2000000.0

# Natural and Crop PFT's don't really need to be set, since they have zero area, but
# it looks better to do so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ PCT_CROP = 0.0
PCT_LAKE = 0.0
PCT_GLACIER = 0.0
PCT_WETLAND = 0.0
PCT_OCEAN = 0.0
# NOTE: PCT_URBAN must be a list of three floats that sum to the total urban area
PCT_URBAN = 100.0 0.0 0.0

Expand Down
4 changes: 2 additions & 2 deletions python/ctsm/test/testinputs/modify_fsurdat_short.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[modify_fsurdat_basic_options]

fsurdat_in = ctsm/test/testinputs/surfdata_5x5_amazon_hist_78pfts_CMIP6_2000_c230517.nc
fsurdat_out = ctsm/test/testinputs/surfdata_5x5_amazon_hist_78pfts_CMIP6_2000_c230517_out.nc
fsurdat_in = ctsm/test/testinputs/surfdata_5x5_amazon_hist_16pfts_CMIP6_2000_c231031.nc
fsurdat_out = ctsm/test/testinputs/surfdata_5x5_amazon_hist_16pfts_CMIP6_2000_c231031.out.nc

idealized = False
process_subgrid_section = False
Expand Down
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Loading

0 comments on commit f714c38

Please sign in to comment.