Skip to content

Commit a74af76

Browse files
committed
Merge branch 'fix_race_condition_cleanup' of github.com:ESMValGroup/ESMValCore into fix_race_condition_cleanup
2 parents 73c6929 + c5b0750 commit a74af76

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

esmvalcore/_recipe/to_datasets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,12 @@ def _get_datasets_for_variable(
361361
template1.add_supplementary(**supplementary_facets)
362362
for supplementary_ds in template1.supplementaries:
363363
supplementary_ds.facets.pop('preprocessor', None)
364+
supplementary_ds['diagnostic'] = diagnostic_name
365+
supplementary_ds['variable_group'] = variable_group
366+
supplementary_ds['variable_group_subdir'] = 'supplementaries'
364367
for dataset in _dataset_from_files(template1):
365-
dataset['variable_group'] = variable_group
366368
dataset['diagnostic'] = diagnostic_name
369+
dataset['variable_group'] = variable_group
367370
dataset['recipe_dataset_index'] = idx # type: ignore
368371
logger.debug("Found %s", dataset.summary(shorten=True))
369372
datasets.append(dataset)

esmvalcore/local.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ def _get_output_file(variable: dict[str, Any], preproc_dir: Path) -> Path:
486486
preproc_dir,
487487
variable.get('diagnostic', ''),
488488
variable.get('variable_group', ''),
489+
variable.get('variable_group_subdir', ''),
489490
outfile,
490491
)
491492

tests/integration/data_finder.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ get_output_file:
2525
preproc_dir: /test
2626
output_file: /test/test_diag/test/CMIP5_HadGEM2-ES_Amon_historical-rcp85_r1i1p1_ta_1960-1980.nc
2727

28+
- variable:
29+
variable_group: test
30+
variable_group_subdir: supplementaries
31+
short_name: areacella
32+
original_short_name: areacella
33+
dataset: HadGEM2-ES
34+
project: CMIP5
35+
institute: [INPE, MOHC]
36+
frequency: fx
37+
modeling_realm: [atmos]
38+
mip: fx
39+
exp: historical
40+
ensemble: r0i0p0
41+
diagnostic: test_diag
42+
preprocessor: test_preproc
43+
preproc_dir: /test
44+
output_file: /test/test_diag/test/supplementaries/CMIP5_HadGEM2-ES_fx_historical_r0i0p0_areacella.nc
45+
2846
# EMAC
2947

3048
- variable:

tests/unit/recipe/test_to_datasets.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,40 @@ def test_from_recipe_dict(session):
178178
assert len(datasets) == 1
179179

180180

181+
def test_supplementaries_have_subdir(session):
182+
recipe_txt = textwrap.dedent("""
183+
datasets:
184+
- dataset: AWI-ESM-1-1-LR
185+
grid: gn
186+
supplementary_variables:
187+
- short_name: sftof
188+
- dataset: BCC-ESM1
189+
grid: gn
190+
supplementary_variables:
191+
- short_name: sftlf
192+
exp: 1pctCO2
193+
194+
diagnostics:
195+
diagnostic1:
196+
variables:
197+
tas:
198+
ensemble: r1i1p1f1
199+
exp: historical
200+
mip: Amon
201+
project: CMIP6
202+
supplementary_variables:
203+
- short_name: areacella
204+
mip: fx
205+
206+
""")
207+
datasets = Dataset.from_recipe(recipe_txt, session)
208+
print(datasets)
209+
for dataset in datasets:
210+
assert 'variable_group_subdir' not in dataset.facets
211+
for supp_ds in dataset.supplementaries:
212+
assert supp_ds.facets['variable_group_subdir'] == 'supplementaries'
213+
214+
181215
def test_merge_supplementaries_dataset_takes_priority(session):
182216
recipe_txt = textwrap.dedent("""
183217
datasets:
@@ -186,8 +220,8 @@ def test_merge_supplementaries_dataset_takes_priority(session):
186220
- dataset: BCC-ESM1
187221
grid: gn
188222
supplementary_variables:
189-
- short_name: areacella
190-
exp: 1pctCO2
223+
- short_name: areacella
224+
exp: 1pctCO2
191225
192226
preprocessors:
193227
global_mean:
@@ -201,7 +235,7 @@ def test_merge_supplementaries_dataset_takes_priority(session):
201235
ensemble: r1i1p1f1
202236
exp: historical
203237
mip: Amon
204-
preprocessor: global_mean_land
238+
preprocessor: global_mean
205239
project: CMIP6
206240
supplementary_variables:
207241
- short_name: areacella

tests/unit/test_dataset.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ def test_from_recipe_with_supplementary(session, tmp_path):
410410
)
411411
dataset.supplementaries = [
412412
Dataset(
413+
diagnostic='diagnostic1',
414+
variable_group='tos',
415+
variable_group_subdir='supplementaries',
413416
short_name='sftof',
414417
dataset='dataset1',
415418
ensemble='r1i1p1',
@@ -458,6 +461,9 @@ def test_from_recipe_with_skip_supplementary(session, tmp_path):
458461
)
459462
dataset.supplementaries = [
460463
Dataset(
464+
diagnostic='diagnostic1',
465+
variable_group='tos',
466+
variable_group_subdir='supplementaries',
461467
short_name='sftof',
462468
dataset='dataset1',
463469
ensemble='r1i1p1',
@@ -533,6 +539,9 @@ def _find_files(self):
533539
)
534540
dataset.supplementaries = [
535541
Dataset(
542+
diagnostic='diagnostic1',
543+
variable_group='tos',
544+
variable_group_subdir='supplementaries',
536545
short_name='areacello',
537546
dataset='dataset1',
538547
institute='X',

0 commit comments

Comments
 (0)