@@ -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,10 +126,14 @@ 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
@@ -148,7 +151,7 @@ def process_naml_file(naml_fp):
148151 sections = extract_sections_from_naml (naml_fp )
149152 for section in sections :
150153 dataset_dict = convert_str_to_facets (section )
151- dataset_dict = add_common_facets (dataset_dict )
154+ dataset_dict = add_common_facets (dataset_dict , project )
152155 datasets .append (dataset_dict )
153156 return datasets
154157
@@ -235,8 +238,20 @@ def dict_namelists_in_work_dir():
235238 # Loop over the namelist files in the work directory
236239 for basename , nl_fp in dict_namelists_in_work_dir ().items ():
237240
238- # Extract the datasets from each file
239- datasets = process_naml_file (nl_fp )
241+ # Check if it's model runs
242+ if basename == "model_runs" :
243+
244+ # Extract the datasets from each file
245+ datasets = process_naml_file (nl_fp , "ESMVal" )
246+
247+ # Write the datasets to a YAML file in the target directory
248+ write_datasets_to_yaml (datasets , basename , target_dir )
249+
250+ # Check if it's CMIP6:
251+ if basename == "cmip6_datasets" :
252+
253+ # Extract the datasets from each file
254+ datasets = process_naml_file (nl_fp , "CMIP6" )
240255
241- # Write the datasets to a YAML file in the target directory
242- write_datasets_to_yaml (datasets , basename , target_dir )
256+ # Write the datasets to a YAML file in the target directory
257+ write_datasets_to_yaml (datasets , basename , target_dir )
0 commit comments