Skip to content

Commit 70a991d

Browse files
author
Steve Goldhaber
committed
Progress
1 parent ef82677 commit 70a991d

2 files changed

Lines changed: 61 additions & 33 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
AKCXS PMTOT PM25 PM2P5 MMRPM2P5
2+
MMRPM1 MMRPM2P5_SRF GRIDAREA DAERH2O MMR_AH2O
3+
ECDRYAER ABSDRYAE ECDRY440 ABSDR440 ECDRY870
4+
ABSDR870 ASYMMDRY ECDRYLT1 ABSDRYBC ABSDRYOC
5+
ABSDRYSU ABSDRYSS ABSDRYDU OD550DRY AB550DRY
6+
DERLT05 DERGT05 DER DOD440 ABS440
7+
DOD500 ABS500 DOD550 ABS550 ABS550AL
8+
DOD670 ABS670 DOD870 ABS870 DLOAD_MI
9+
DLOAD_SS DLOAD_S4 DLOAD_OC DLOAD_BC LOADBCAC
10+
LOADBC0 LOADBC2 LOADBC4 LOADBC12 LOADBC14
11+
LOADOCAC LOADOC3 LOADOC4 LOADOC13 LOADOC14
12+
EC550AER ABS550_A BS550AER EC550SO4 EC550BC
13+
EC550POM EC550SS EC550DU CDOD440 CDOD550
14+
CABS550 CABS550A CDOD870 A550_DU A550_SS
15+
A550_SO4 A550_POM A550_BC D440_DU D440_SS
16+
D440_SO4 D440_POM D440_BC D500_DU D500_SS
17+
D500_SO4 D500_POM D500_BC D550_DU D550_SS
18+
D550_SO4 D550_POM D550_BC D670_DU D670_SS
19+
D670_SO4 D670_POM D670_BC D870_DU D870_SS
20+
D870_SO4 D870_POM D870_BC DLT_DUST DLT_SS
21+
DLT_SO4 DLT_POM DLT_BC DGT_DUST DGT_SS
22+
DGT_SO4 DGT_POM DGT_BC AIRMASS NNAT_0
23+
NNAT_1 NNAT_2 NNAT_4 NNAT_5 NNAT_6
24+
NNAT_7 NNAT_8 NNAT_9 NNAT_10 NNAT_12
25+
NNAT_14 AIRMASSL BETOTVIS BATOTVIS BATSW13
26+
BATLW01 Camrel01 Camrel02 Camrel04 Camrel05
27+
Camrel06 Camrel07 Camrel08 Camrel09 Camrel10
28+
Cxsrel01 Cxsrel02 Cxsrel04 Cxsrel05 Cxsrel06
29+
Cxsrel07 Cxsrel08 Cxsrel09 Cxsrel10

tools/cmip_namelists/cmip_diagnostic_namelists.py

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import re
1616
import sys
1717

18+
# Input and output codes
1819
_FREQUENCY_COLNAME = "CMIP7 Freq."
1920
_MODELTYPE_COLNAME = "Modelling Realm - Primary"
2021
_REGION_COLNAME = "Region"
@@ -27,6 +28,10 @@
2728
'3hr':'! 3-hourly output', '1hr':'! 1-hourly output',
2829
'subhr':'! timestep output'}
2930

31+
# Relative paths
32+
__MYDIR = os.path.dirname(__file__)
33+
__CAMDIR = os.path.dirname(os.path.dirname(__MYDIR))
34+
3035
class Usermod():
3136
"""Class to hold information about a history usermod directory"""
3237

@@ -99,19 +104,21 @@ def is_number(text):
99104
return val
100105

101106
def command_line(args):
102-
"""Read the command line arguments (args) to retrieve the path to the
103-
CMIP7 data request spreadsheet.
104-
Return the path to the spreadsheet file."""
107+
"""Read the command line arguments (args) to retrieve the paths to the
108+
CMIP7 and CAM data request spreadsheets, the config file, and options.
109+
Return all argument values."""
105110
parser = argparse.ArgumentParser(description=__doc__,
106111
formatter_class=argparse.RawTextHelpFormatter)
107112

108-
parser.add_argument("csv_file", metavar='<path to CMIP7 data request file>', type=str)
109-
parser.add_argument("--usermods_dir", type=str, default="-",
113+
parser.add_argument("cmip_file", metavar='<path to CMIP7 data request file>', type=str)
114+
parser.add_argument("cam_file", metavar='<path to CAM data request file>', type=str)
115+
parser.add_argument("--usermods_dir", type=str,
116+
default=os.path.join(__CAMDIR,"cime_config", "usermods_dirs")
110117
help="Path to write namelist file entries")
111118
parser.add_argument("--overwrite", action='store_true', default=False,
112119
help="Overwrite namelist file(s) if they exist")
113120
pargs = parser.parse_args(args)
114-
return pargs.csv_file, pargs.usermods_dir, pargs.overwrite
121+
return pargs.cmip_file, cam_file, pargs.usermods_dir, pargs.overwrite
115122

116123
def read_config_file(filename):
117124
"""Read a fincl group configuration (ini-style) file.
@@ -146,37 +153,29 @@ def flex_open(filename=None, mode='w'):
146153
if fh is not sys.stdout:
147154
fh.close()
148155

149-
def read_diagnostic_fieldnames(include_cosp=False):
150-
"""Read the master list of CAM diagnostic (history) fieldnames from the
151-
saved master list.
152-
If <include_cosp> is True, include the COSP diagnostic fieldnames in the
153-
master list. Otherwise, keep a separate list of COSP fieldnames
154-
Return the list of fieldnames and the list of COSP fieldnames."""
155-
156-
cam_diag_fieldname_file = os.path.join(os.path.dirname(__file__),
157-
"master_fieldlist.txt")
156+
def read_fieldname_file(filename):
157+
"""Read a fieldname file and return all fieldnames as a list."""
158+
diag_fieldname_file = os.path.join(__MYDIR, filename)
158159
all_fieldnames = []
159-
cosp_fieldnames = []
160-
with open(cam_diag_fieldname_file, mode='r') as infile:
160+
with open(diag_fieldname_file, mode='r') as infile:
161161
for line in infile:
162162
fieldnames = [x.strip() for x in line.split()]
163163
all_fieldnames.extend(fieldnames)
164164
# end for
165165
# end with
166-
# Handle COSP fieldnames separately
167-
cosp_diag_fieldname_file = os.path.join(os.path.dirname(__file__),
168-
"cosp_fieldlist.txt")
169-
with open(cosp_diag_fieldname_file, mode='r') as infile:
170-
for line in infile:
171-
fieldnames = [x.strip() for x in line.split()]
172-
if include_cosp:
173-
all_fieldnames.extend(fieldnames)
174-
else:
175-
cosp_fieldnames.extend(fieldnames)
176-
# end for
177-
# end with
178-
# end if
179-
return all_fieldnames, cosp_fieldnames
166+
return all_fieldnames
167+
168+
def read_diagnostic_fieldnames():
169+
"""Read the master list of CAM diagnostic (history) fieldnames from the
170+
saved master list.
171+
Keep separate lists of COSP and Aerocom fieldnames
172+
Return the fieldname three lists."""
173+
174+
all_fieldnames = read_fieldname_file("master_fieldlist.txt")
175+
cosp_fieldnames = read_fieldname_file("cosp_fieldlist.txt")
176+
aerocom_fieldnames = read_fieldname_file("aerocom_fieldlist.txt")
177+
178+
return all_fieldnames, cosp_fieldnames, aerocom_fieldnames
180179

181180
def parse_spreadsheet(csvfile, model_name="atmos"):
182181
"""Parse <csvfile> and return a dictionary of the requested CAM fields at
@@ -295,13 +294,13 @@ def generate_namelist_entries(data_request, nl_filename, maxline=125, hist_files
295294
###############################################################################
296295

297296
if __name__ == "__main__":
298-
csvfile, usermods_dir, overwrite = command_line(sys.argv[1:])
297+
cmipfile, camfile, usermods_dir, overwrite = command_line(sys.argv[1:])
299298
if not overwrite and os.path.exists(nl_filename):
300299
raise ValueError(f"namelist file, '{nl_filename}', exists, aborting")
301300
# end if
302301
# read configuration
303302
usermod_dict = read_config_file(config_file)
304-
all_fieldnames, cosp_fieldnames = read_diagnostic_fieldnames(include_cosp)
303+
all_fieldnames, cosp_fieldnames, aerocom_fieldnames = read_diagnostic_fieldnames()
305304
data_request = parse_spreadsheet(csvfile)
306305
missing = check_for_missing_fieldnames(all_fieldnames, data_request)
307306
# Separate the COSP fields from the others

0 commit comments

Comments
 (0)