Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with searching for files on ESGF #1863

Merged
merged 2 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions esmvalcore/esgf/_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,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 @@ -278,8 +278,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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should do something smarter here..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continued in #1920

# 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