Skip to content

Commit

Permalink
Improve variable alias managament (#595)
Browse files Browse the repository at this point in the history
Add support for several variables that have different names in CMP5 and CMIP6
  • Loading branch information
Javier Vegas-Regidor authored Oct 2, 2020
1 parent f99f60a commit 2ce46b8
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 159 deletions.
13 changes: 13 additions & 0 deletions doc/recipe/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,19 @@ define the ``start_year`` and ``end_year`` items in the variable section,
because the diagnostic script assumes that all the data has the same time
range.

Variable short names usually do not change between datasets supported by
ESMValCore, as they are usually changed to match CMIP. Nevertheless, there are
small changes in variable names in CMIP6 with respect to CMIP5 (i.e. sea ice
concentration changed from ``sic`` to ``siconc``). ESMValCore is aware of some
of them and can do the automatic translation when needed. It will even do the
translation in the preprocessed file so the diagnostic does not have to deal
with this complexity, setting the short name in all files to match the one used
by the recipe. For example, if ``sic`` is requested, ESMValTool will
find ``sic`` or ``siconc`` depending on the project, but all preprocessed files
while use ``sic`` as their short_name. If the recipe requested ``siconc``, the
preprocessed files will be identical except that they will use the short_name
``siconc`` instead.

Diagnostic and variable specific datasets
-----------------------------------------
The ``additional_datasets`` option can be used to add datasets beyond those
Expand Down
4 changes: 3 additions & 1 deletion esmvalcore/_data_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,12 @@ def _get_filenames_glob(variable, drs):


def _find_input_files(variable, rootpath, drs):
short_name = variable['short_name']
variable['short_name'] = variable['original_short_name']
input_dirs = _find_input_dirs(variable, rootpath, drs)
filenames_glob = _get_filenames_glob(variable, drs)
files = find_files(input_dirs, filenames_glob)

variable['short_name'] = short_name
return (files, input_dirs, filenames_glob)


Expand Down
4 changes: 3 additions & 1 deletion esmvalcore/_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _add_cmor_info(variable, override=False):
raise RecipeError(
f"Unable to load CMOR table (project) '{project}' for variable "
f"'{short_name}' with mip '{mip}'")

variable['original_short_name'] = table_entry.short_name
for key in cmor_keys:
if key not in variable or override:
value = getattr(table_entry, key, None)
Expand Down Expand Up @@ -348,6 +348,8 @@ def _get_default_settings(variable, config_user, derive=False):

# Configure saving cubes to file
settings['save'] = {'compress': config_user['compress_netcdf']}
if variable['short_name'] != variable['original_short_name']:
settings['save']['alias'] = variable['short_name']

return settings

Expand Down
Loading

0 comments on commit 2ce46b8

Please sign in to comment.