Skip to content

Commit

Permalink
Generalize var names third_dim, fourth_dim to lev1_dim, lev2_dim
Browse files Browse the repository at this point in the history
  • Loading branch information
slevis-lmwg committed Nov 30, 2021
1 parent c83c269 commit 7b2ff24
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions python/ctsm/modify_fsurdat/modify_fsurdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def set_dom_nat_pft(self, dom_nat_pft, lai, sai, hgt_top, hgt_bot):

for pft in self.file.natpft:
# initialize 3D variable; set outside the loop below
self.setvar_lev1('PCT_NAT_PFT', val=0, third_dim=pft)
self.setvar_lev1('PCT_NAT_PFT', val=0, lev1_dim=pft)
# set 3D variable value for dom_nat_pft
self.setvar_lev1('PCT_NAT_PFT', val=100, third_dim=dom_nat_pft)
self.setvar_lev1('PCT_NAT_PFT', val=100, lev1_dim=dom_nat_pft)

# dictionary of 4d variables to loop over
vars_4d = {'MONTHLY_LAI': lai,
Expand Down Expand Up @@ -175,8 +175,8 @@ def set_lai_sai_hgts(self, dom_nat_pft, var, val):
abort(errmsg)
for mon in self.file.time - 1: # loop over 12 months
# set 4D variable to value for dom_nat_pft
self.setvar_lev2(var, val[int(mon)], third_dim=dom_nat_pft,
fourth_dim=mon)
self.setvar_lev2(var, val[int(mon)], lev1_dim=dom_nat_pft,
lev2_dim=mon)


def zero_nonveg(self):
Expand Down Expand Up @@ -204,22 +204,22 @@ def setvar_lev0(self, var, val):
self.not_rectangle, other=val)


def setvar_lev1(self, var, val, third_dim):
def setvar_lev1(self, var, val, lev1_dim):
"""
Sets 3d variable var to value val in user-defined rectangle,
defined as "other" in the function
"""
self.file[var][third_dim, ...] = self.file[var][third_dim, ...].where(
self.file[var][lev1_dim, ...] = self.file[var][lev1_dim, ...].where(
self.not_rectangle, other=val)


def setvar_lev2(self, var, val, third_dim, fourth_dim):
def setvar_lev2(self, var, val, lev1_dim, lev2_dim):
"""
Sets 4d variable var to value val in user-defined rectangle,
defined as "other" in the function
"""
self.file[var][fourth_dim,third_dim, ...] = \
self.file[var][fourth_dim,third_dim, ...].where(
self.file[var][lev2_dim,lev1_dim, ...] = \
self.file[var][lev2_dim,lev1_dim, ...].where(
self.not_rectangle, other=val)


Expand Down Expand Up @@ -273,15 +273,15 @@ def set_idealized(self):

for lev in self.file.nlevsoi:
# set next three 3D variables to values representing loam
self.setvar_lev1('PCT_SAND', val=pct_sand, third_dim=lev)
self.setvar_lev1('PCT_CLAY', val=pct_clay, third_dim=lev)
self.setvar_lev1('ORGANIC', val=organic, third_dim=lev)
self.setvar_lev1('PCT_SAND', val=pct_sand, lev1_dim=lev)
self.setvar_lev1('PCT_CLAY', val=pct_clay, lev1_dim=lev)
self.setvar_lev1('ORGANIC', val=organic, lev1_dim=lev)

for crop in self.file.cft:
cft_local = crop - (max(self.file.natpft) + 1)
# initialize 3D variable; set outside the loop below
self.setvar_lev1('PCT_CFT', val=0, third_dim=cft_local)
self.setvar_lev1('PCT_CFT', val=0, lev1_dim=cft_local)

# set 3D variable
# NB. sum(PCT_CFT) must = 100 even though PCT_CROP = 0
self.setvar_lev1('PCT_CFT', val=100, third_dim=0)
self.setvar_lev1('PCT_CFT', val=100, lev1_dim=0)

0 comments on commit 7b2ff24

Please sign in to comment.