Skip to content

Commit

Permalink
Merge pull request ESCOMP#2164 from slevis-lmwg/ocn_v_wetland_iss1886
Browse files Browse the repository at this point in the history
Distinguish between ocean and wetland in fsurdat files
  • Loading branch information
slevis-lmwg authored Nov 13, 2023
2 parents e8dd1eb + 960e951 commit 9583b22
Show file tree
Hide file tree
Showing 30 changed files with 162 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,3 +7,4 @@ e44dc469439e02e9ee582dab274d890ebdfab104
b88e1cd1b28e3609684c79a2ec0e88f26cfc362b
51c102c5df2e0ef971b5f8eeeb477567899af63a
7dacad70e74e2ec97f6492d4e7a3cb5dd498bcd7
a0d014fae9550dd9ffbc934abd29ef16176f8208
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
12 changes: 10 additions & 2 deletions python/ctsm/modify_input_files/modify_fsurdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ def check_varlist(self, settings, allow_uppercase_vars=False):
)
if len(val) != dim1:
abort(
"Variable " + varname + " is of the wrong size. It should be = " + str(dim1)
"Variable "
+ varname
+ " is "
+ str(len(val))
+ ". It should be = "
+ str(dim1)
)
return settings_return

Expand Down Expand Up @@ -351,6 +356,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 @@ -396,8 +402,8 @@ def set_idealized(self):
max_sat_area = 0 # max saturated area
std_elev = 0 # standard deviation of elevation
slope = 0 # mean topographic slope
pftdata_mask = 1
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 @@ -415,11 +421,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: 13 additions & 16 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,12 +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 x in range(10):
lev2_ten[x, :, :, :] = x + 1
lev1 = np.array(
[
[
Expand Down Expand Up @@ -215,13 +212,13 @@ 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)
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)
np.testing.assert_array_equal(fsurdat_out_data.TK_ROOF, lev2_ten)

def test_1x1_mexicocity(self):
"""
Expand All @@ -232,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
6 changes: 3 additions & 3 deletions python/ctsm/test/test_sys_mesh_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def setUp(self):
testinputs_path = os.path.join(path_to_ctsm_root(), "python/ctsm/test/testinputs")
fsurdat_in = os.path.join(
testinputs_path,
"surfdata_5x5_amazon_16pfts_Irrig_CMIP6_simyr2000_c171214.nc",
"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")
Expand Down Expand Up @@ -96,8 +96,8 @@ def setUp(self):
self._lon_dimname = fsurdat_in_data[self._lat_varname].dims[1]

ncap2_cmd = (
"ncap2 -A -v -s 'mod_lnd_props=PFTDATA_MASK' "
+ "-A -v -s 'landmask=PFTDATA_MASK' "
"ncap2 -A -v -s 'mod_lnd_props=LANDFRAC_MKSURFDATA' "
+ "-A -v -s 'landmask=LANDFRAC_MKSURFDATA' "
+ f"-A -v -s {self._lat_varname}={self._lat_varname} "
+ f"-A -v -s {self._lon_varname}={self._lon_varname} "
+ f"{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_16pfts_Irrig_CMIP6_simyr2000_c171214.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_16pfts_Irrig_CMIP6_simyr2000_c171214.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_Irrig_CMIP6_simyr2000_c190214.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
3 changes: 2 additions & 1 deletion python/ctsm/test/testinputs/modify_fsurdat_opt_sections.cfg
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 All @@ -48,4 +49,4 @@ CANYON_HWR = 200.00 150.0 100.
HT_ROOF = 200.0 150.0 100.
T_BUILDING_MIN = 200 150.0 100.
ALB_ROOF_DIR = 200. 100.
TK_ROOF = 1. 2. 3. 4. 5.
TK_ROOF = 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
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 9583b22

Please sign in to comment.