Skip to content

Commit fb569f1

Browse files
committed
Refactor SUBSETDATAPOINT to use new SUBSETDATASHARED parent class.
1 parent 5a3ae01 commit fb569f1

File tree

2 files changed

+77
-56
lines changed

2 files changed

+77
-56
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""
2+
Parent class for CTSM-specific tests that first run the subset_data tool and then ensure
3+
that CTSM does not fail using the just-generated input files
4+
"""
5+
6+
import os
7+
import sys
8+
import logging
9+
from CIME.SystemTests.system_tests_common import SystemTestsCommon
10+
from CIME.user_mod_support import apply_user_mods
11+
from CIME.XML.standard_module_setup import *
12+
13+
# In case we need to import subset_data later
14+
_CTSM_PYTHON = os.path.join(
15+
os.path.dirname(os.path.realpath(__file__)), os.pardir, os.pardir, "python"
16+
)
17+
sys.path.insert(1, _CTSM_PYTHON)
18+
19+
logger = logging.getLogger(__name__)
20+
21+
22+
class SUBSETDATASHARED(SystemTestsCommon):
23+
def __init__(self, case, subset_data_cmd):
24+
"""
25+
initialize an object interface to the SMS system test
26+
"""
27+
SystemTestsCommon.__init__(self, case)
28+
29+
# Check the test setup
30+
if not self._case.get_value("LND_GRID") == "CLM_USRDAT":
31+
raise RuntimeError("SUBSETDATA tests require resolution CLM_USRDAT")
32+
if "serial" not in self._case.get_value("MPILIB"):
33+
raise RuntimeError("SUBSETDATA tests require a serial MPILIB")
34+
if "BGC-CROP" not in self._case.get_value("COMPSET"):
35+
raise RuntimeError("SUBSETDATA tests require a BGC-CROP compset")
36+
37+
# Add standard subset_data arguments
38+
out_dir = os.path.join(self._get_caseroot(), "subset_data_output")
39+
self.usermods_dir = os.path.join(out_dir, "user_mods")
40+
self.subset_data_cmd = subset_data_cmd + [
41+
"--create-user-mods",
42+
"--outdir",
43+
out_dir,
44+
"--user-mods-dir",
45+
self.usermods_dir,
46+
"--overwrite",
47+
]
48+
49+
def build_phase(self, sharedlib_only=False, model_only=False):
50+
51+
# Import subset_data. Do it here rather than at top because otherwise the import will
52+
# be attempted even during RUN phase.
53+
# pylint: disable=wrong-import-position,import-outside-toplevel
54+
from ctsm.subset_data import main as subset_data
55+
56+
# Run the tool
57+
sys.argv = self.subset_data_cmd
58+
subset_data()
59+
60+
# Required so that CTSM doesn't fail
61+
user_nl_clm_path = os.path.join(self.usermods_dir, "user_nl_clm")
62+
with open(user_nl_clm_path, "a", encoding="utf-8") as user_nl_clm:
63+
user_nl_clm.write("\ncheck_dynpft_consistency = .false.")
64+
65+
# Apply the user mods
66+
self._case.flush(flushall=True)
67+
apply_user_mods(self._get_caseroot(), self.usermods_dir)
68+
self._case.read_xml()
69+
70+
# Do the build
71+
super().build_phase(sharedlib_only, model_only)

cime_config/SystemTests/subsetdatapoint.py

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,20 @@
33
that CTSM does not fail using the just-generated input files
44
"""
55

6-
import os
7-
import sys
8-
import logging
9-
from CIME.SystemTests.system_tests_common import SystemTestsCommon
10-
from CIME.user_mod_support import apply_user_mods
11-
from CIME.XML.standard_module_setup import *
6+
from subsetdata import SUBSETDATASHARED
127

13-
# In case we need to import subset_data later
14-
_CTSM_PYTHON = os.path.join(
15-
os.path.dirname(os.path.realpath(__file__)), os.pardir, os.pardir, "python"
16-
)
17-
sys.path.insert(1, _CTSM_PYTHON)
188

19-
logger = logging.getLogger(__name__)
20-
21-
22-
class SUBSETDATAPOINT(SystemTestsCommon):
9+
class SUBSETDATAPOINT(SUBSETDATASHARED):
2310
def __init__(self, case):
2411
"""
2512
initialize an object interface to the SMS system test
2613
"""
27-
SystemTestsCommon.__init__(self, case)
28-
29-
# Check the test setup
30-
if not self._case.get_value("LND_GRID") == "CLM_USRDAT":
31-
raise RuntimeError("SUBSETDATAPOINT tests require resolution CLM_USRDAT")
32-
if "serial" not in self._case.get_value("MPILIB"):
33-
raise RuntimeError("SUBSETDATAPOINT tests require a serial MPILIB")
34-
if "BGC-CROP" not in self._case.get_value("COMPSET"):
35-
raise RuntimeError("SUBSETDATAPOINT tests require a BGC-CROP compset")
36-
37-
def build_phase(self, sharedlib_only=False, model_only=False):
38-
39-
# Where the output files will be saved
40-
out_dir = os.path.join(self._get_caseroot(), "subset_data_output")
41-
usermods_dir = os.path.join(out_dir, "user_mods")
4214

43-
# Import subset_data. Do it here rather than at top because otherwise the import will
44-
# be attempted even during RUN phase.
45-
# pylint: disable=wrong-import-position,import-outside-toplevel
46-
from ctsm.subset_data import main as subset_data
47-
48-
# Run the tool
4915
lat = 45.402252
5016
lon = -92.798085
51-
sys.argv = [
17+
18+
# Don't need to include things that are added during SUBSETDATASHARED.__init__()
19+
subset_data_cmd = [
5220
"tools/site_and_regional/subset_data",
5321
"point",
5422
"--lat",
@@ -65,24 +33,6 @@ def build_phase(self, sharedlib_only=False, model_only=False):
6533
"1901",
6634
"--datm-eyr",
6735
"1901",
68-
"--create-user-mods",
69-
"--outdir",
70-
out_dir,
71-
"--user-mods-dir",
72-
usermods_dir,
73-
"--overwrite",
7436
]
75-
subset_data()
76-
77-
# Required so that CTSM doesn't fail
78-
user_nl_clm_path = os.path.join(usermods_dir, "user_nl_clm")
79-
with open(user_nl_clm_path, "a", encoding="utf-8") as user_nl_clm:
80-
user_nl_clm.write("\ncheck_dynpft_consistency = .false.")
81-
82-
# Apply the user mods
83-
self._case.flush(flushall=True)
84-
apply_user_mods(self._get_caseroot(), usermods_dir)
85-
self._case.read_xml()
8637

87-
# Do the build
88-
super().build_phase(sharedlib_only, model_only)
38+
super().__init__(case, subset_data_cmd)

0 commit comments

Comments
 (0)