Skip to content

Commit 6cf780a

Browse files
committed
Using explicit project
1 parent 5e863ad commit 6cf780a

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

CMEW/app/add_datasets/bin/add_datasets_to_share.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

CMEW/app/add_datasets/bin/test_add_datasets_to_share.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test_add_common_facets(mock_env_vars):
120120
"project": "CMIP6",
121121
}
122122

123-
actual = add_common_facets(dataset_dict)
123+
actual = add_common_facets(dataset_dict, "CMIP6")
124124
assert actual == expected
125125

126126

@@ -148,7 +148,7 @@ def test_process_naml_file(path_to_mock_nl, mock_env_vars):
148148
},
149149
]
150150

151-
actual = process_naml_file(path_to_mock_nl)
151+
actual = process_naml_file(path_to_mock_nl, "CMIP6")
152152
assert actual == expected
153153

154154

0 commit comments

Comments
 (0)