Skip to content

Commit

Permalink
Merge branch 'main' into multi_model_stats_equalise_coords
Browse files Browse the repository at this point in the history
  • Loading branch information
schlunma authored Jan 16, 2023
2 parents 30c0780 + 69a284d commit 6df07c7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
10 changes: 7 additions & 3 deletions esmvalcore/esgf/_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def same_file(result):
# cmip5.output1.ICHEC.EC-EARTH.historical
# .mon.atmos.Amon.r1i1p1.v20121115
variable = file.name.split('_')[0]
if 'variable' in facets and facets['variable'] == variable:
if 'variable' not in facets or facets['variable'] == variable:
files.append(file)
else:
logger.debug(
Expand Down Expand Up @@ -279,8 +279,12 @@ def _get_facets(results):
facets = {
'project': project,
}
for idx, key in enumerate(keys):
facets[key] = values[idx]
if len(keys) == len(values):
for idx, key in enumerate(keys):
facets[key] = values[idx]
else:
logger.debug("Wrong dataset_id_template_ %s for dataset %s",
template, dataset_id)
# The dataset_id does not contain the short_name for all projects,
# so get it from the filename if needed:
if 'short_name' not in facets:
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/esgf/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,31 @@ def test_select_by_time_nodate():
assert result == files


def test_invalid_dataset_id_template():
dataset_id = (
'obs4MIPs.IUP.XCH4_CRDP3.xch4.mon.v100')
dataset_id_template = (
'%(project)s.%(institute)s.%(source_id)s.%(time_frequency)s'
)
filenames = ['xch4_ghgcci_l3_v100_200301_201412.nc']
results = [
FileResult(
json={
'title': filename,
'dataset_id': dataset_id + '|esgf.ceda.ac.uk',
'dataset_id_template_': [dataset_id_template],
'project': ['obs4MIPs'],
'size': 100,
'source_id': 'XCH4_CRDP3',
},
context=None,
) for filename in filenames
]
file = ESGFFile(results)

assert file.name == filenames[0]


def test_search_unknown_project():
project = 'Unknown'
msg = (f"Unable to download from ESGF, because project {project} is not on"
Expand Down

0 comments on commit 6df07c7

Please sign in to comment.