Skip to content

Commit 8a2b73d

Browse files
author
Steve Goldhaber
committed
Fix extract master_fieldlist
1 parent 9b31327 commit 8a2b73d

3 files changed

Lines changed: 676 additions & 791 deletions

File tree

tools/cmip_namelists/chemistry.py

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,37 @@
1414

1515
## chemistry diag pre- and post-fixes
1616
## Each list entry is a pair of possible new chemistry names
17-
__CHEM_DIAG_PRE_POST = [('GS_', ''), ('AQ_', ''), ('AQ_', '_OCW'),
18-
('sink_', ''), ('sink_', '_S'),
19-
('CT_', ''), ('SF', ''), ('emis_', ''),
20-
('D', 'CHM'), ('F', '_fvm'), ('TA', ''), ('TM', ''),
21-
('VD', ''), ('', 'CONU'), ('', 'DDF'), ('', 'DDV'),
22-
('', 'DTQ'), ('', 'GVF'), ('', 'INS'), ('', 'SBC'),
23-
('', 'SBS'), ('', 'SF'), ('', 'SFSBC'), ('', 'SFSBD'),
24-
('', 'SFSBS'), ('', 'SFSEC'), ('', 'SFSED'),
25-
('', 'SFSES'), ('', 'SFSIC'), ('', 'SFSID'),
26-
('', 'SFSIS'), ('', 'SFWET'), ('', 'SFWETC'),
27-
('', 'SIC'), ('', 'SIS'), ('', 'TBF'), ('', 'WET'),
28-
('', 'WETC'), ('', '_CHML'), ('', '_CHMP'),
29-
('', '_SRF'), ('', '_fvm'), ('', '_mixnuc1'),
30-
('', '_num'), ('', '_qneg3'), ('', '_qneg3_col'),
31-
('', '_sfcoag1'), ('', '_sfcsiz3'), ('', '_sfcsiz4'),
32-
('', '_sfgaex2')]
17+
__CHEM_DIAG_PRE_POST = [('GS_', ''), ('AQ_', ''), ('AQ_', '_OCW'),
18+
('sink_', ''), ('sink_', '_S'), ('CT_', ''),
19+
('SF', ''), ('emis_', ''), ('D', 'CHM'),
20+
('F', '_fvm'), ('TA', ''), ('TM', ''),
21+
('VD', ''), ('', 'CONU'), ('', 'DDF'),
22+
('', 'DDV'), ('', 'DTQ'), ('', 'GVF'),
23+
('', 'INS'), ('', 'SBC'), ('', 'SBS'),
24+
('', 'SF'), ('', 'SFSBC'), ('', 'SFSBD'),
25+
('', 'SFSBS'), ('', 'SFSEC'), ('', 'SFSED'),
26+
('', 'SFSES'), ('', 'SFSIC'), ('', 'SFSID'),
27+
('', 'SFSIS'), ('', 'SFWET'), ('', 'SFWETC'),
28+
('', 'SIC'), ('', 'SIS'), ('', 'TBF'),
29+
('', 'WET'), ('', 'WETC'), ('', '_CHML'),
30+
('', '_CHMP'), ('', '_SRF'), ('', '_fvm'),
31+
('', '_mixnuc1'), ('', '_num'), ('', '_qneg3'),
32+
('', '_qneg3_col'), ('', '_sfcoag1'), ('', '_sfcsiz3'),
33+
('', '_sfcsiz4'), ('', '_sfgaex2'), ('', '_OCWDDF'),
34+
('', '_OCWGVF'), ('', '_OCWSFSBC'), ('', '_OCW'),
35+
('', '_OCWSFSBS'), ('', '_OCWSFSIC'),
36+
('', '_OCWSFSIS'), ('', '_OCWSFWET'), ('', '_OCWTBF'),
37+
('', '_OCW_mixnuc1'),
38+
('', '_OCWclcoagTend'), ('', 'coagTend'),
39+
('', 'condTend'), ('', '_CLXF'), ('', '_CMXF'),
40+
('', '_XFRC'), ('', 'clcoagTend'),
41+
('DC', ''), ('WD_A_', ''), ('cb_', ''),
42+
('cb_', '_OCW')]
43+
44+
__ESM_FIXED_FIELDS = {'CO2_OCN', 'CO2_FFF', 'CO2_LND', 'CO2'}
45+
__ESM_DIAG_PRE_POST = [('', '_BOT'), ('', '_fvm'), ('', '_qneg3'),
46+
('', '_qneg3_col'), ('F', '_fvm'), ('SF', ''),
47+
('TA', ''), ('TM', ''), ('VD', '')]
3348

3449
## Find chem species in mo_sim_dat.F90
3550
__SOLSYM_RE = re.compile(r"solsym[(][: 0-9]+[)] = [(]/(.*)$")
@@ -107,6 +122,21 @@ def read_chem_species(chem_name):
107122

108123
return species_list
109124

125+
def all_diags_set(species_list, pre_post_list):
126+
"""Using a list of species names, <species_list>, create a set that
127+
includes these names plus each name decorated by the pre- and post-patterns
128+
from <pre_post_list>.
129+
Return this set of strings.
130+
"""
131+
diag_names = set()
132+
for speci in species_list:
133+
diag_names.add(speci)
134+
for decor in pre_post_list:
135+
diag_names.add(f"{decor[0]}{speci}{decor[1]}")
136+
# end if
137+
# end for
138+
return diag_names
139+
110140
def all_chem_names(chem_name=None):
111141
"""Return a set containing all chemistry diagnostic names for one
112142
chemistry scheme (chem_name==None) or for all chemistry schemes
@@ -119,14 +149,15 @@ def all_chem_names(chem_name=None):
119149
all_chem_file = os.path.join(__MYDIR, "chemistry_fieldlist.txt")
120150
all_species = read_fieldname_file(all_chem_file)
121151
# end if
122-
for chem_speci in all_species:
123-
diag_names.add(chem_speci)
124-
for decor in __CHEM_DIAG_PRE_POST:
125-
diag_names.add(f"{decor[0]}{chem_speci}{decor[1]}")
126-
# end if
127-
# end for
152+
diag_names = all_diags_set(all_species, __CHEM_DIAG_PRE_POST)
128153
return diag_names
129154

155+
def all_emission_names():
156+
"""Return a set of all the diagnostic field names associated with the
157+
CO2 emission-driven constituent fields, including CO2.
158+
"""
159+
return all_diags_set(__ESM_FIXED_FIELDS, __ESM_DIAG_PRE_POST)
160+
130161
###############################################################################
131162

132163
if __name__ == "__main__":

tools/cmip_namelists/extract_master_list.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import re
1111
import sys
1212
## Local imports
13-
from chemistry import all_chem_names
13+
from chemistry import all_chem_names, all_emission_names
1414

1515
_BEGIN_MASTER_LIST_RE = re.compile(r"[ ]*[*]+ MASTER FIELD LIST [*]+")
1616
_END_MASTER_LIST_RE = re.compile(r"[ ]*intht:nfmaster=")
@@ -45,7 +45,7 @@ def parse_diagnostic_fieldnames(logfiles, output_file):
4545

4646
all_fieldnames = set()
4747
in_masterlist = False
48-
chem_names = all_chem_names()
48+
exclude_names = all_chem_names() | all_emission_names()
4949
linenum = 0
5050
for logfile in logfiles:
5151
with open(logfile, mode='r') as infile:
@@ -59,7 +59,7 @@ def parse_diagnostic_fieldnames(logfiles, output_file):
5959
fieldmatch = _FIELDLINE_RE.match(line)
6060
if fieldmatch is not None:
6161
fldname = fieldmatch.group(1)
62-
if ('&IC' not in fldname) and (fldname not in chem_names):
62+
if ('&IC' not in fldname) and (fldname not in exclude_names):
6363
all_fieldnames.add(fldname)
6464
# end if
6565
else:

0 commit comments

Comments
 (0)