Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve anomaly forcings for ISSP cases #292

Merged
merged 24 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d73aa12
Add Anomaly.Forcing.cmip5.rcp45.
samsrabin May 8, 2024
2be3338
Fix 'anomoly_forcing' typo.
samsrabin May 9, 2024
a4d87b3
Update meshfile used for Anomaly.Forcing.*.
samsrabin Aug 8, 2024
5323a11
Fix more typos of "anomaly."
samsrabin Aug 8, 2024
ba85ec4
Add Anomaly.Forcing.cmip6.ssp126.
samsrabin Aug 8, 2024
9b0f714
Add Anomaly.Forcing.cmip6.245, 370, 585.
samsrabin Aug 9, 2024
d921931
anomaly_forcing now automatically set based on compset (ISSP*).
samsrabin Sep 4, 2024
0389799
Now actually sets anomaly_forcing based on compset.
samsrabin Sep 5, 2024
c191e5e
SSP compsets now automatically get anomaly_forcing in datm_in.
samsrabin Sep 5, 2024
b02f0cd
Remove Anomaly.Forcing.Precip, Anomaly.Forcing.Temperature, etc.
samsrabin Sep 5, 2024
074d90d
Set anomaly_forcing = 'none' to not use anomalies in an SSP compset.
samsrabin Sep 5, 2024
0a61422
Only set anomaly_forcing for DATM SSP compsets.
samsrabin Sep 5, 2024
4715267
Provide hint in error message if namelist variable invalid due to sur…
samsrabin Sep 5, 2024
a11abf7
Make datm buildnml more robust.
samsrabin Sep 5, 2024
cd97dea
Bugfix to future-proofing of datm buildnml.
samsrabin Sep 5, 2024
94dcdb0
Add aux_cdeps tests for SSPs other than 585.
samsrabin Sep 6, 2024
a911685
Simplify removal of quotes.
samsrabin Feb 19, 2025
93e59c0
Fix indentation.
samsrabin Feb 19, 2025
196957f
buildnml now errors on mismatch between anomaly forcing and DATM_MODE.
samsrabin Mar 14, 2025
4107fc3
Merge tag 'cdeps1.0.61' into ssp-fix-202503
samsrabin Mar 14, 2025
9b35f06
Merge branch 'ssp-fix-202503' into ssp-fix
samsrabin Mar 14, 2025
b56f0b7
Add comments about new tests in testlist_datm.xml.
samsrabin Mar 18, 2025
8aab1ae
Remove DATM_MODE_ANOMALY_FORCING_MISMATCH option.
samsrabin Mar 19, 2025
e71aa9a
Merge branch 'main' into ssp-fix
samsrabin Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cime_config/stream_cdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ def create_stream_xml(
),
)
if var_key in valid_values:

# # Handle, e.g., 'bilinear' in namelist instead of bilinear (no quotes)
mod_dict[var_key] = re.sub(r"[\"\']", "", mod_dict[var_key])

# Check that key is valid
expect(
mod_dict[var_key] in valid_values[var_key],
"{} can only have values of {} for stream {} in file {}".format(
Expand Down
33 changes: 32 additions & 1 deletion datm/cime_config/buildnml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# pylint: disable=wildcard-import,unused-wildcard-import,wrong-import-position

import os, sys
import re

_CDEPS_CONFIG = os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir,os.pardir,"cime_config")
_CIMEROOT = os.environ.get("CIMEROOT")
Expand Down Expand Up @@ -88,6 +89,18 @@ def _get_neon_data_availability(case, neonsite):
expect(newestdate, "No tower data found on server for NEON site {}".format(neonsite))
return None

####################################################################################
def _check_datm_af_mismatch(anomaly_forcing, datm_mode):
####################################################################################

# CMIP5 and CMIP6 anomalies were only generated relative to GSWP3v1
is_cmip5_or_6 = any(x in anomaly_forcing for x in ["cmip5", "cmip6"])
if is_cmip5_or_6 and datm_mode != "CLMGSWP3v1":
raise SystemExit(
"CMIP5 and CMIP6 anomalies were only generated relative for DATM_MODE='CLMGSWP3v1'"
)


# pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
####################################################################################
def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path):
Expand All @@ -106,6 +119,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path

caseroot = case.get_value("CASEROOT")
datm_mode = case.get_value("DATM_MODE")
mismatch_ok = case.get_value("DATM_MODE_ANOMALY_FORCING_MISMATCH")
datm_topo = case.get_value("DATM_TOPO")
datm_presaero = case.get_value("DATM_PRESAERO")
datm_presndep = case.get_value("DATM_PRESNDEP")
Expand All @@ -115,6 +129,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path
atm_grid = case.get_value("ATM_GRID")
model_grid = case.get_value("GRID")
comp_lnd = case.get_value("COMP_LND")
compset = case.get_value("COMPSET")

# Check for incompatible options.
if "CLM" in datm_mode and comp_lnd == "clm":
Expand All @@ -135,6 +150,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path
logger.debug("DATM preso3 mode is {}".format(datm_preso3))
logger.debug("DATM topo mode is {}".format(datm_topo))
logger.debug("CLM_USRDAT_NAME is {}".format(clm_usrdat_name))
logger.debug("COMPSET is {}".format(compset))

# Initialize namelist defaults
config = {}
Expand Down Expand Up @@ -177,6 +193,17 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path

nmlgen.init_defaults(infile, config)

# Get anomaly forcing
# First, look in namelist
anomaly_forcing = nmlgen.get_value("anomaly_forcing")
if not anomaly_forcing or anomaly_forcing[0] is None:
# If not in namelist, check whether it's an SSP compset
ssp = re.search(r"^SSP\d+_DATM", compset)
if ssp:
ssp = ssp.group().replace("_DATM", "")
anomaly_forcing = ["Anomaly.Forcing.cmip6." + ssp.lower()]
nmlgen.set_value("anomaly_forcing", anomaly_forcing)

# Generate datm_in
namelist_file = os.path.join(confdir, "datm_in")
nmlgen.write_output_file(namelist_file, data_list_path, groups=['datm_nml','const_forcing_nml'])
Expand Down Expand Up @@ -205,8 +232,12 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen, data_list_path
bias_correct = nmlgen.get_value("bias_correct")
if bias_correct is not None:
streamlist.append(bias_correct)

# Set anomaly forcing in datm.streams.xml
anomaly_forcing = nmlgen.get_value("anomaly_forcing")
if anomaly_forcing[0] is not None:
if anomaly_forcing[0] is not None and anomaly_forcing[0] != "none":
if not mismatch_ok:
_check_datm_af_mismatch(anomaly_forcing[0], datm_mode)
streamlist += anomaly_forcing

# Generate datm.streams.xml
Expand Down
11 changes: 11 additions & 0 deletions datm/cime_config/config_component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
<desc>Name of atmospheric component</desc>
</entry>

<entry id="DATM_MODE_ANOMALY_FORCING_MISMATCH">
<type>logical</type>
<valid_values>TRUE,FALSE</valid_values>
<default_value>FALSE</default_value>
<group>run_component_datm</group>
<file>env_run.xml</file>
<desc> If set to true, then user will be allowed to specify an anomaly forcing that was based
on a different climate forcing than what's given in DATM_MODE
</desc>
</entry>

<entry id="DATM_MODE">
<type>char</type>
<valid_values>CORE2_NYF,CORE2_IAF,CLM_QIAN,CLM_QIAN_WISO,1PT,CLMCRUNCEP,CLMCRUNCEPv7,CLMGSWP3v1,CLMNLDAS2,CPLHIST,CORE_IAF_JRA,CORE_IAF_JRA_1p4_2018,CORE_IAF_JRA_1p5_2023,ERA5,SIMPLE</valid_values>
Expand Down
2 changes: 1 addition & 1 deletion datm/cime_config/namelist_definition_datm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
<type>char(10)</type>
<category>datm</category>
<group>datm_nml</group>
<valid_values>Anomaly.Forcing.Precip,Anomaly.Forcing.Temperature,Anomaly.Forcing.Pressure,Anomaly.Forcing.Humidity,Anomaly.Forcing.Uwind,Anomaly.Forcing.Vwind,Anomaly.Forcing.Shortwave,Anomaly.Forcing.Longwave</valid_values>
<valid_values>none,Anomaly.Forcing.cmip5.rcp45,Anomaly.Forcing.cmip6.ssp126,Anomaly.Forcing.cmip6.ssp245,Anomaly.Forcing.cmip6.ssp370,Anomaly.Forcing.cmip6.ssp585</valid_values>
<desc>
If set, include anomaly forcing streams in namelist.
</desc>
Expand Down
Loading