@@ -99,7 +99,7 @@ def convert_str_to_facets(section):
9999 return section_dict
100100
101101
102- def add_common_facets (dataset_dict , project = "CMIP6" ):
102+ def add_common_facets (dataset_dict , project ):
103103 """
104104 Add start year, end year and project to a dataset dictionary.
105105
@@ -109,7 +109,6 @@ def add_common_facets(dataset_dict, project="CMIP6"):
109109 A dictionary containing the facets of a dataset.
110110 project: str
111111 A string indicating the project to which the dataset belongs.
112- Default is "CMIP6".
113112
114113 Returns
115114 -------
@@ -127,17 +126,23 @@ def add_common_facets(dataset_dict, project="CMIP6"):
127126 dataset_dict ["end_year" ] = end_year
128127 dataset_dict ["project" ] = project
129128
129+ # Add MOHC as an institute only for generated CMEW runs
130+ if dataset_dict ["project" ] == "ESMVal" :
131+ dataset_dict ["institute" ] = "MOHC"
132+
130133 return dataset_dict
131134
132135
133- def process_naml_file (naml_fp ):
136+ def process_naml_file (naml_fp , project = None ):
134137 """
135138 Extract the datasets and their facets from a namelist file.
136139
137140 Parameters
138141 ----------
139142 naml_fp: str
140143 The file path to the namelist file containing the datasets.
144+ project: str, optional
145+ A string indicating the project to which the dataset belongs.
141146
142147 Returns
143148 -------
@@ -148,7 +153,7 @@ def process_naml_file(naml_fp):
148153 sections = extract_sections_from_naml (naml_fp )
149154 for section in sections :
150155 dataset_dict = convert_str_to_facets (section )
151- dataset_dict = add_common_facets (dataset_dict )
156+ dataset_dict = add_common_facets (dataset_dict , project )
152157 datasets .append (dataset_dict )
153158 return datasets
154159
@@ -269,11 +274,19 @@ def use_facet_as_key(filepath, key_facet="suite_id"):
269274 # Loop over the namelist files in the work directory
270275 for basename , nl_fp in dict_namelists_in_work_dir ().items ():
271276
272- # Extract the datasets from each file
273- datasets = process_naml_file (nl_fp )
277+ # Check if it's model runs
278+ if basename == "model_runs" :
279+
280+ # Write the datasets to a YAML file with ESMVal project
281+ datasets = process_naml_file (nl_fp , "ESMVal" )
282+ write_datasets_to_yaml (datasets , basename , target_dir )
283+
284+ # Check if it's CMIP6:
285+ if basename == "cmip6_datasets" :
274286
275- # Write the datasets to a YAML file in the target directory
276- write_datasets_to_yaml (datasets , basename , target_dir )
287+ # Write the datasets to a YAML file with CMIP6 project
288+ datasets = process_naml_file (nl_fp , "CMIP6" )
289+ write_datasets_to_yaml (datasets , basename , target_dir )
277290
278291 # Reformat the model_runs YAML file to use suite_ids as keys
279292 use_facet_as_key (f"{ target_dir } /model_runs.yml" )
0 commit comments