Skip to content

Commit

Permalink
Black format
Browse files Browse the repository at this point in the history
  • Loading branch information
ekluzek committed Oct 19, 2023
1 parent 76415f3 commit 309dd6e
Showing 1 changed file with 44 additions and 36 deletions.
80 changes: 44 additions & 36 deletions cime_config/SystemTests/mksurfdataesmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,31 @@

logger = logging.getLogger(__name__)

class MKSURFDATAESMF(SystemTestsCommon):

class MKSURFDATAESMF(SystemTestsCommon):
def __init__(self, case):
"""
initialize an object interface to the SMS system test
"""
SystemTestsCommon.__init__(self, case)

# Paths and strings needed throughout
ctsm_root = self._case.get_value('COMP_ROOT_DIR_LND')
self._tool_path = os.path.join(ctsm_root, 'tools/mksurfdata_esmf')
self._tool_bld = os.path.join(self._get_caseroot(), 'tool_bld')
ctsm_root = self._case.get_value("COMP_ROOT_DIR_LND")
self._tool_path = os.path.join(ctsm_root, "tools/mksurfdata_esmf")
self._tool_bld = os.path.join(self._get_caseroot(), "tool_bld")
time_stamp = datetime.today().strftime("%y%m%d")
self._res = '10x15' # see important comment in script's docstring
self._model_yr = '1850'
self._jobscript = os.path.join(self._get_caseroot(),
'mksurfdata_jobscript_single')
self._fsurdat_namelist = os.path.join(self._get_caseroot(),
f'surfdata_{self._res}_hist_78pfts_CMIP6_{self._model_yr}_c{time_stamp}.namelist')
self._fsurdat_nc = os.path.join(self._get_caseroot(),
f'surfdata_{self._res}_hist_78pfts_CMIP6_{self._model_yr}_c{time_stamp}.nc')
self._TestStatus_log_path = os.path.join(self._get_caseroot(),
'TestStatus.log')
self._res = "10x15" # see important comment in script's docstring
self._model_yr = "1850"
self._jobscript = os.path.join(self._get_caseroot(), "mksurfdata_jobscript_single")
self._fsurdat_namelist = os.path.join(
self._get_caseroot(),
f"surfdata_{self._res}_hist_78pfts_CMIP6_{self._model_yr}_c{time_stamp}.namelist",
)
self._fsurdat_nc = os.path.join(
self._get_caseroot(),
f"surfdata_{self._res}_hist_78pfts_CMIP6_{self._model_yr}_c{time_stamp}.nc",
)
self._TestStatus_log_path = os.path.join(self._get_caseroot(), "TestStatus.log")

def build_phase(self, sharedlib_only=False, model_only=False):
"""
Expand All @@ -58,49 +60,53 @@ def build_phase(self, sharedlib_only=False, model_only=False):
# if the test stops and gets restarted.
if sharedlib_only:
# Paths and strings
build_script_path = os.path.join(self._tool_path,
'gen_mksurfdata_build.sh')
nml_script_path = os.path.join(self._tool_path,
'gen_mksurfdata_namelist.py')
gen_jobscript_path = os.path.join(self._tool_path,
'gen_mksurfdata_jobscript_single.py')
gen_mksurfdata_namelist = f'{nml_script_path} --res {self._res} --start-year {self._model_yr} --end-year {self._model_yr}'
gen_mksurfdata_jobscript = f'{gen_jobscript_path} --number-of-nodes 12 --tasks-per-node 12 --namelist-file {self._fsurdat_namelist}'
build_script_path = os.path.join(self._tool_path, "gen_mksurfdata_build.sh")
nml_script_path = os.path.join(self._tool_path, "gen_mksurfdata_namelist.py")
gen_jobscript_path = os.path.join(self._tool_path, "gen_mksurfdata_jobscript_single.py")
gen_mksurfdata_namelist = f"{nml_script_path} --res {self._res} --start-year {self._model_yr} --end-year {self._model_yr}"
gen_mksurfdata_jobscript = f"{gen_jobscript_path} --number-of-nodes 12 --tasks-per-node 12 --namelist-file {self._fsurdat_namelist}"

# Rm tool_bld and build executable that will generate fsurdat
try:
subprocess.check_call(f'rm -rf {self._tool_bld}', shell=True)
subprocess.check_call(f"rm -rf {self._tool_bld}", shell=True)
except subprocess.CalledProcessError as e:
sys.exit(f'{e} ERROR REMOVING {self._tool_bld}. DETAILS IN {self._TestStatus_log_path}')
sys.exit(
f"{e} ERROR REMOVING {self._tool_bld}. DETAILS IN {self._TestStatus_log_path}"
)
try:
subprocess.check_call(f'{build_script_path} --blddir {self._tool_bld}', shell=True)
subprocess.check_call(f"{build_script_path} --blddir {self._tool_bld}", shell=True)
except subprocess.CalledProcessError as e:
sys.exit(f'{e} ERROR RUNNING {build_script_path}. DETAILS IN {self._TestStatus_log_path}')
sys.exit(
f"{e} ERROR RUNNING {build_script_path}. DETAILS IN {self._TestStatus_log_path}"
)

# Generate namelist for generating fsurdat (rm namelist if exists)
if os.path.exists(self._fsurdat_namelist):
os.remove(self._fsurdat_namelist)
try:
subprocess.check_call(gen_mksurfdata_namelist, shell=True)
except subprocess.CalledProcessError as e:
sys.exit(f'{e} ERROR RUNNING {gen_mksurfdata_namelist}. DETAILS IN {self._TestStatus_log_path}')
sys.exit(
f"{e} ERROR RUNNING {gen_mksurfdata_namelist}. DETAILS IN {self._TestStatus_log_path}"
)

# Generate jobscript that will run the executable
if os.path.exists(self._jobscript):
os.remove(self._jobscript)
try:
subprocess.check_call(gen_mksurfdata_jobscript, shell=True)
except subprocess.CalledProcessError as e:
sys.exit(f'{e} ERROR RUNNING {gen_mksurfdata_jobscript}. DETAILS IN {self._TestStatus_log_path}')
sys.exit(
f"{e} ERROR RUNNING {gen_mksurfdata_jobscript}. DETAILS IN {self._TestStatus_log_path}"
)
# Change self._jobscript to an executable file
subprocess.check_call(f'chmod a+x {self._jobscript}', shell=True)
subprocess.check_call(f"chmod a+x {self._jobscript}", shell=True)

# Call this step only once even if the test stops and gets restarted.
if not os.path.exists(os.path.join(self._get_caseroot(),
'done_MKSURFDATAESMF_setup.txt')):
if not os.path.exists(os.path.join(self._get_caseroot(), "done_MKSURFDATAESMF_setup.txt")):
# Modify user_nl_clm to point to the generated fsurdat
self._modify_user_nl()
with open('done_MKSURFDATAESMF_setup.txt', 'w') as fp:
with open("done_MKSURFDATAESMF_setup.txt", "w") as fp:
pass

self.build_indv(sharedlib_only=sharedlib_only, model_only=model_only)
Expand All @@ -117,7 +123,7 @@ def run_phase(self):
try:
subprocess.check_call(self._jobscript, shell=True)
except subprocess.CalledProcessError as e:
sys.exit(f'{e} ERROR RUNNING {self._jobscript}; details in {self._TestStatus_log_path}')
sys.exit(f"{e} ERROR RUNNING {self._jobscript}; details in {self._TestStatus_log_path}")

# Submit CTSM run that uses fsurdat just generated
self.run_indv()
Expand All @@ -126,6 +132,8 @@ def _modify_user_nl(self):
"""
Modify user_nl_clm to point to the generated fsurdat
"""
append_to_user_nl_files(caseroot = self._get_caseroot(),
component = "clm",
contents = "fsurdat = '{}'".format(self._fsurdat_nc))
append_to_user_nl_files(
caseroot=self._get_caseroot(),
component="clm",
contents="fsurdat = '{}'".format(self._fsurdat_nc),
)

0 comments on commit 309dd6e

Please sign in to comment.