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

Support multiple paths in input_dir #1000

Merged
merged 3 commits into from
Feb 15, 2021
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
17 changes: 16 additions & 1 deletion doc/quickstart/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Input file paths
----------------

When looking for input files, the ``esmvaltool`` command provided by
ESMValCore replaces the placeholders ``[item]`` in
ESMValCore replaces the placeholders ``{item}`` in
``input_dir`` and ``input_file`` with the values supplied in the recipe.
ESMValCore will try to automatically fill in the values for institute, frequency,
and modeling_realm based on the information provided in the CMOR tables
Expand All @@ -240,6 +240,21 @@ The resulting directory path would look something like this:

CMIP/MOHC/HadGEM3-GC31-LL/historical/r1i1p1f3/Omon/tos/gn/latest

Please, bear in mind that ``input_dirs`` can also be a list for those cases in
which may be needed:

.. code-block:: yaml

- '{exp}/{ensemble}/original/{mip}/{short_name}/{grid}/{latestversion}'
- '{exp}/{ensemble}/computed/{mip}/{short_name}/{grid}/{latestversion}'

In that case, the resultant directories will be:

.. code-block:: bash

historical/r1i1p1f3/original/Omon/tos/gn/latest
historical/r1i1p1f3/computed/Omon/tos/gn/latest

For a more in-depth description of how to configure ESMValCore so it can find
your data please see :ref:`CMOR-DRS`.

Expand Down
15 changes: 11 additions & 4 deletions esmvalcore/_data_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,18 @@ def select_files(filenames, start_year, end_year):
return selection


def _replace_tags(path, variable):
def _replace_tags(paths, variable):
"""Replace tags in the config-developer's file with actual values."""
path = path.strip('/')
tlist = re.findall(r'{([^}]*)}', path)
paths = [path]
if isinstance(paths, str):
paths = (paths.strip('/'), )
else:
paths = [path.strip('/') for path in paths]
tlist = set()

for path in paths:
tlist = tlist.union(re.findall(r'{([^}]*)}', path))
logger.debug(tlist)

for tag in tlist:
original_tag = tag
tag, _, _ = _get_caps_options(tag)
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/data_finder/test_replace_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Tests for _replace_tags in _data_finder.py."""

from esmvalcore._data_finder import _replace_tags

VARIABLE = {
'short_name': 'tas',
}


def test_replace_tags_str():
assert _replace_tags('folder/subfolder/{short_name}',
VARIABLE) == ['folder/subfolder/tas']


def test_replace_tags_list_of_str():
assert _replace_tags(('folder/subfolder/{short_name}',
'folder2/{short_name}', 'subfolder/{short_name}'),
VARIABLE) == [
'folder/subfolder/tas',
'folder2/tas',
'subfolder/tas',
]