@@ -25,10 +25,10 @@ def _parse_args():
25
25
)
26
26
# Command line argument for CUPiD example from which to get config.yml
27
27
parser .add_argument (
28
- "--cupid-example " ,
28
+ "--cupid-config-loc " ,
29
29
action = "store" ,
30
- dest = "cupid_example " ,
31
- default = "external_diag_packages" ,
30
+ dest = "cupid_config_loc " ,
31
+ default = None ,
32
32
help = "CUPiD example to use as template for config.yml" ,
33
33
)
34
34
parser .add_argument (
@@ -46,27 +46,20 @@ def _parse_args():
46
46
return parser .parse_args ()
47
47
48
48
49
- def generate_adf_config (cesm_root , cupid_example , adf_file , out_file ):
50
- """Use cupid config file (YAML) from cupid_example and adf_file (YAML)
49
+ def generate_adf_config (cesm_root , cupid_config_loc , adf_file , out_file ):
50
+ """Use cupid config file (YAML) from cupid_config_loc and adf_file (YAML)
51
51
to produce out_file by modifying adf_file with data from cupid config file.
52
52
"""
53
53
sys .path .append (os .path .join (cesm_root , "cime" ))
54
54
55
- # Is cupid_example a valid value?
56
55
cupid_root = os .path .join (cesm_root , "tools" , "CUPiD" )
57
- cupid_examples = os .path .join (cupid_root , "examples" )
58
- valid_examples = [
59
- example
60
- for example in next (os .walk (cupid_examples ))[1 ]
61
- if example not in ["ilamb" ]
62
- ]
63
- if cupid_example not in valid_examples :
64
- error_msg = f"argument --cupid-example: invalid choice '{ cupid_example } '"
65
- raise KeyError (
66
- f"{ error_msg } (choose from subdirectories of { cupid_examples } : { valid_examples } )" ,
67
- )
56
+ # Is cupid_config_loc a valid value?
57
+ if cupid_config_loc is None :
58
+ cupid_config_loc = os .path .join (cupid_root , "examples" , "key_metrics" )
59
+ if not os .path .exists (os .path .join (cupid_config_loc , "config.yml" )):
60
+ raise KeyError (f"Can not find config.yml in { cupid_config_loc } " )
68
61
69
- with open (os .path .join (cupid_root , "examples" , cupid_example , "config.yml" )) as c :
62
+ with open (os .path .join (cupid_config_loc , "config.yml" )) as c :
70
63
c_dict = yaml .safe_load (c )
71
64
with open (adf_file , encoding = "UTF-8" ) as a :
72
65
a_dict = yaml .safe_load (a )
@@ -141,9 +134,9 @@ def generate_adf_config(cesm_root, cupid_example, adf_file, out_file):
141
134
ts_case_names .index (base_case_name ) if base_case_name in ts_case_names else None
142
135
)
143
136
144
- base_case_output_dir = c_dict [ "global_params" ]. get (
145
- " base_case_output_dir" ,
146
- DOUT + "/" + base_case_name ,
137
+ base_case_output_dir = os . path . join (
138
+ c_dict [ "global_params" ]. get ( " base_case_output_dir", DOUT ) ,
139
+ base_case_name ,
147
140
)
148
141
base_start_date = get_date_from_ts (
149
142
c_ts ["atm" ],
@@ -208,9 +201,7 @@ def generate_adf_config(cesm_root, cupid_example, adf_file, out_file):
208
201
"regrid" ,
209
202
) # This is where ADF will make "regrid" files
210
203
a_dict ["diag_basic_info" ]["cam_diag_plot_loc" ] = os .path .join (
211
- cupid_root ,
212
- "examples" ,
213
- cupid_example ,
204
+ cupid_config_loc ,
214
205
"ADF_output" ,
215
206
) # this is where ADF will put plots, and "website" directory
216
207
a_dict ["user" ] = os .environ ["USER" ]
@@ -255,10 +246,10 @@ def generate_adf_config(cesm_root, cupid_example, adf_file, out_file):
255
246
f .write (
256
247
"# This file has been auto-generated using generate_adf_config_file.py\n " ,
257
248
)
258
- f .write (f"# It is based off of examples/ { cupid_example } /config.yml\n " )
249
+ f .write (f"# It is based off of { cupid_config_loc } /config.yml\n " )
259
250
f .write ("# Arguments:\n " )
260
251
f .write (f"# { cesm_root = } \n " )
261
- f .write (f"# { cupid_example = } \n " )
252
+ f .write (f"# { cupid_config_loc = } \n " )
262
253
f .write (f"# { adf_file = } \n " )
263
254
f .write (f"# Output: { out_file = } \n " )
264
255
# enter in each element of the dictionary into the new file
@@ -284,7 +275,7 @@ def get_date_from_ts(data: dict, keyname: str, listindex: int, default=None):
284
275
print (args )
285
276
generate_adf_config (
286
277
args ["cesm_root" ],
287
- args ["cupid_example " ],
278
+ args ["cupid_config_loc " ],
288
279
args ["adf_template" ],
289
280
args ["out_file" ],
290
281
)
0 commit comments