diff --git a/doc/develop/derivation.rst b/doc/develop/derivation.rst index a1bf5a44b3..0267f7ca3a 100644 --- a/doc/develop/derivation.rst +++ b/doc/develop/derivation.rst @@ -27,8 +27,8 @@ A typical example looks like this: if project == 'CMIP6': mip = 'Ofx' required = [ - {'short_name': 'var_a'}, - {'short_name': 'var_b', 'mip': mip, 'optional': True}, + {'cmor_name': 'var_a'}, + {'cmor_name': 'var_b', 'mip': mip, 'optional': True}, ] return required diff --git a/doc/develop/fixing_data.rst b/doc/develop/fixing_data.rst index 1782ca984a..35986902b1 100644 --- a/doc/develop/fixing_data.rst +++ b/doc/develop/fixing_data.rst @@ -74,7 +74,7 @@ coordinates. In our example it looks like this: month_number x - - year x - - Attributes: - {'cmor_table': 'CMIPX', 'mip': 'Amon', 'short_name': 'tas', 'frequency': 'mon'}) + {'cmor_table': 'CMIPX', 'mip': 'Amon', 'cmor_name': 'tas', 'frequency': 'mon'}) So now the mistake is clear: the latitude coordinate is badly named and the @@ -140,7 +140,7 @@ so we will implement the ``fix_metadata`` method: latitude = tas_cube.coord('altitude') # Fix the names. Latitude values, units and - latitude.short_name = 'lat' + latitude.var_name = 'lat' latitude.standard_name = 'latitude' latitude.long_name = 'latitude' return cubes @@ -200,7 +200,7 @@ from the one you just created: latitude = tas_cube.coord('altitude') # Fix the names. Latitude values, units and - latitude.short_name = 'lat' + latitude.var_name = 'lat' latitude.standard_name = 'latitude' latitude.long_name = 'latitude' return cubes diff --git a/doc/recipe/overview.rst b/doc/recipe/overview.rst index 7798878620..688b53dc79 100644 --- a/doc/recipe/overview.rst +++ b/doc/recipe/overview.rst @@ -227,7 +227,7 @@ A (simplified) example diagnostics section could look like - atmos variables: variable_name: - short_name: ta + cmor_name: ta preprocessor: preprocessor_name mip: Amon scripts: @@ -271,7 +271,7 @@ that wildcard expansion can be used to define ancestors. diagnostic_1: variables: airtemp: - short_name: ta + cmor_name: ta preprocessor: preprocessor_name mip: Amon scripts: @@ -280,7 +280,7 @@ that wildcard expansion can be used to define ancestors. diagnostic_2: variables: precip: - short_name: pr + cmor_name: pr preprocessor: preprocessor_name mip: Amon scripts: diff --git a/esmvalcore/_recipe.py b/esmvalcore/_recipe.py index 6db4df455c..681ab36be3 100644 --- a/esmvalcore/_recipe.py +++ b/esmvalcore/_recipe.py @@ -63,21 +63,22 @@ def _add_cmor_info(variable, override=False): logger.debug("If not present: adding keys from CMOR table to %s", variable) # Copy the following keys from CMOR table cmor_keys = [ - 'standard_name', 'long_name', 'units', 'modeling_realm', 'frequency' + 'cmor_name', 'short_name', 'standard_name', 'long_name', 'units', + 'modeling_realm', 'frequency' ] project = variable['project'] mip = variable['mip'] - short_name = variable['short_name'] + cmor_name = variable['cmor_name'] derive = variable.get('derive', False) table = CMOR_TABLES.get(project) if table: - table_entry = table.get_variable(mip, short_name, derive) + table_entry = table.get_variable(mip, cmor_name, derive) else: table_entry = None if table_entry is None: raise RecipeError( f"Unable to load CMOR table (project) '{project}' for variable " - f"'{short_name}' with mip '{mip}'") + f"'{cmor_name}' with mip '{mip}'") variable['original_short_name'] = table_entry.short_name for key in cmor_keys: if key not in variable or override: @@ -99,11 +100,11 @@ def _special_name_to_dataset(variable, special_name): if special_name not in variable: raise RecipeError( "Preprocessor {preproc} uses {name}, but {name} is not " - "defined for variable {short_name} of diagnostic " + "defined for variable {cmor_name} of diagnostic " "{diagnostic}".format( preproc=variable['preprocessor'], name=special_name, - short_name=variable['short_name'], + cmor_name=variable['cmor_name'], diagnostic=variable['diagnostic'], )) special_name = variable[special_name] @@ -141,7 +142,7 @@ def _update_target_levels(variable, variables, settings, config_user): filename=filename, project=variable_data['project'], dataset=dataset, - short_name=variable_data['short_name'], + cmor_name=variable_data['cmor_name'], mip=variable_data['mip'], frequency=variable_data['frequency'], fix_dir=os.path.splitext(variable_data['filename'])[0] + @@ -201,7 +202,7 @@ def _dataset_to_file(variable, config_user): """Find the first file belonging to dataset from variable info.""" (files, dirnames, filenames) = _get_input_files(variable, config_user) if not files and variable.get('derive'): - required_vars = get_required(variable['short_name'], + required_vars = get_required(variable['cmor_name'], variable['project']) for required_var in required_vars: _augment(required_var, variable) @@ -264,8 +265,8 @@ def _get_default_settings(variable, config_user, derive=False): fix = { 'project': variable['project'], 'dataset': variable['dataset'], - 'short_name': variable['short_name'], 'mip': variable['mip'], + 'cmor_name': variable['cmor_name'], } # File fixes fix_dir = os.path.splitext(variable['filename'])[0] + '_fixed' @@ -287,6 +288,7 @@ def _get_default_settings(variable, config_user, derive=False): if derive: settings['derive'] = { + 'cmor_name': variable['cmor_name'], 'short_name': variable['short_name'], 'standard_name': variable['standard_name'], 'long_name': variable['long_name'], @@ -297,7 +299,7 @@ def _get_default_settings(variable, config_user, derive=False): settings['cmor_check_metadata'] = { 'cmor_table': variable['project'], 'mip': variable['mip'], - 'short_name': variable['short_name'], + 'cmor_name': variable['cmor_name'], 'frequency': variable['frequency'], 'check_level': config_user.get('check_level', CheckLevels.DEFAULT) } @@ -329,7 +331,8 @@ def _add_fxvar_keys(fx_info, variable): """Add keys specific to fx variable to use get_input_filelist.""" fx_variable = deepcopy(variable) fx_variable.update(fx_info) - fx_variable['variable_group'] = fx_info['short_name'] + fx_variable['variable_group'] = fx_info['cmor_name'] + fx_variable['cmor_name'] = fx_info['cmor_name'] # add special ensemble for CMIP5 only if fx_variable['project'] == 'CMIP5': @@ -344,19 +347,19 @@ def _add_fxvar_keys(fx_info, variable): def _search_fx_mip(tables, found_mip, variable, fx_info, config_user): fx_files = None for mip in tables: - fx_cmor = tables[mip].get(fx_info['short_name']) + fx_cmor = tables[mip].get(fx_info['cmor_name']) if fx_cmor: found_mip = True fx_info['mip'] = mip fx_info = _add_fxvar_keys(fx_info, variable) logger.debug( "For fx variable '%s', found table '%s'", - fx_info['short_name'], mip) + fx_info['cmor_name'], mip) fx_files = _get_input_files(fx_info, config_user)[0] if fx_files: logger.debug( "Found fx variables '%s':\n%s", - fx_info['short_name'], pformat(fx_files)) + fx_info['cmor_name'], pformat(fx_files)) return found_mip, fx_info, fx_files @@ -370,7 +373,7 @@ def _get_fx_files(variable, fx_info, config_user): get_project_config(var_project) except ValueError: raise RecipeError( - f"Requested fx variable '{fx_info['short_name']}' " + f"Requested fx variable '{fx_info['cmor_name']}' " f"with parent variable '{variable}' does not have " f"a '{var_project}' project in config-developer.") project_tables = CMOR_TABLES[var_project].tables @@ -381,7 +384,7 @@ def _get_fx_files(variable, fx_info, config_user): found_mip, fx_info, fx_files = _search_fx_mip( project_tables, found_mip, variable, fx_info, config_user) else: - fx_cmor = project_tables[fx_info['mip']].get(fx_info['short_name']) + fx_cmor = project_tables[fx_info['mip']].get(fx_info['cmor_name']) if fx_cmor: found_mip = True fx_info = _add_fxvar_keys(fx_info, variable) @@ -390,13 +393,13 @@ def _get_fx_files(variable, fx_info, config_user): # If fx variable was not found in any table, raise exception if not found_mip: raise RecipeError( - f"Requested fx variable '{fx_info['short_name']}' " + f"Requested fx variable '{fx_info['cmor_name']}' " f"not available in any CMOR table for '{var_project}'") # flag a warning if not fx_files: logger.warning( - "Missing data for fx variable '%s'", fx_info['short_name']) + "Missing data for fx variable '%s'", fx_info['cmor_name']) # allow for empty lists corrected for by NE masks if fx_files: @@ -434,8 +437,8 @@ def _update_fx_files(step_name, settings, variable, config_user, fx_vars): fx_info = {} if 'mip' not in fx_info: fx_info.update({'mip': None}) - if 'short_name' not in fx_info: - fx_info.update({'short_name': fx_var}) + if 'cmor_name' not in fx_info: + fx_info.update({'cmor_name': fx_var}) fx_files, fx_info = _get_fx_files(variable, fx_info, config_user) if fx_files: fx_info['filename'] = fx_files @@ -445,7 +448,7 @@ def _update_fx_files(step_name, settings, variable, config_user, fx_vars): logger.info('Using fx_files: %s for variable %s during step %s', pformat(settings['add_fx_variables']['fx_variables']), - variable['short_name'], step_name) + variable['cmor_name'], step_name) def _fx_list_to_dict(fx_vars): @@ -453,8 +456,8 @@ def _fx_list_to_dict(fx_vars): user_fx_vars = {} for fx_var in fx_vars: if isinstance(fx_var, dict): - short_name = fx_var['short_name'] - user_fx_vars.update({short_name: fx_var}) + cmor_name = fx_var['cmor_name'] + user_fx_vars.update({cmor_name: fx_var}) continue user_fx_vars.update({fx_var: None}) return user_fx_vars @@ -462,6 +465,7 @@ def _fx_list_to_dict(fx_vars): def _update_fx_settings(settings, variable, config_user): """Update fx settings depending on the needed method.""" + # get fx variables either from user defined attribute or fixed def _get_fx_vars_from_attribute(step_settings, step_name): user_fx_vars = step_settings.get('fx_variables') @@ -530,7 +534,7 @@ def _get_ancestors(variable, config_user): filenames) = _get_input_files(variable, config_user) logger.info("Using input files for variable %s of dataset %s:\n%s", - variable['short_name'], variable['dataset'], + variable['cmor_name'], variable['dataset'], '\n'.join(input_files)) if (not config_user.get('skip-nonexistent') or variable['dataset'] == variable.get('reference_dataset')): @@ -684,7 +688,6 @@ def _get_preprocessor_products(variables, profile, order, ancestor_products, for variable in variables: variable['filename'] = get_output_file(variable, config_user['preproc_dir']) - if ancestor_products: grouped_ancestors = _match_products(ancestor_products, variables) else: @@ -845,7 +848,7 @@ def _get_derive_input_variables(variables, config_user): def append(group_prefix, var): """Append variable `var` to a derive input group.""" - group = group_prefix + var['short_name'] + group = group_prefix + var['cmor_name'] var['variable_group'] = group if group not in derive_input: derive_input[group] = [] @@ -860,7 +863,7 @@ def append(group_prefix, var): append(group_prefix, var) else: # Process input data needed to derive variable - required_vars = get_required(variable['short_name'], + required_vars = get_required(variable['cmor_name'], variable['project']) for var in required_vars: _augment(var, variable) @@ -886,10 +889,10 @@ def _get_preprocessor_task(variables, profiles, config_user, task_name): if preproc_name not in profiles: raise RecipeError( "Unknown preprocessor {} in variable {} of diagnostic {}".format( - preproc_name, variable['short_name'], variable['diagnostic'])) + preproc_name, variable['cmor_name'], variable['diagnostic'])) profile = deepcopy(profiles[variable['preprocessor']]) logger.info("Creating preprocessor '%s' task for variable '%s'", - variable['preprocessor'], variable['short_name']) + variable['preprocessor'], variable['cmor_name']) variables = _limit_datasets(variables, profile, config_user.get('max_datasets')) for variable in variables: @@ -1078,7 +1081,7 @@ def _initialize_variables(self, raw_variable, raw_datasets): variables.append(variable) required_keys = { - 'short_name', + 'cmor_name', 'mip', 'dataset', 'project', @@ -1114,8 +1117,8 @@ def _initialize_preprocessor_output(self, diagnostic_name, raw_variables, else: raw_variable = deepcopy(raw_variable) raw_variable['variable_group'] = variable_group - if 'short_name' not in raw_variable: - raw_variable['short_name'] = variable_group + if 'cmor_name' not in raw_variable: + raw_variable['cmor_name'] = variable_group raw_variable['diagnostic'] = diagnostic_name raw_variable['preprocessor'] = str( raw_variable.get('preprocessor', 'default')) diff --git a/esmvalcore/_recipe_checks.py b/esmvalcore/_recipe_checks.py index 21cff6a4a9..a8d30a1e1e 100644 --- a/esmvalcore/_recipe_checks.py +++ b/esmvalcore/_recipe_checks.py @@ -97,7 +97,7 @@ def variable(var, required_keys): if missing: raise RecipeError( "Missing keys {} from variable {} in diagnostic {}".format( - missing, var.get('short_name'), var.get('diagnostic'))) + missing, var.get('cmor_name'), var.get('diagnostic'))) def data_availability(input_files, var, dirnames, filenames): diff --git a/esmvalcore/cmor/_fixes/fix.py b/esmvalcore/cmor/_fixes/fix.py index 12aee7b9a0..e2d309c3ea 100644 --- a/esmvalcore/cmor/_fixes/fix.py +++ b/esmvalcore/cmor/_fixes/fix.py @@ -3,7 +3,7 @@ import inspect import os -from ..table import CMOR_TABLES +from ..table import get_var_info class Fix: @@ -15,7 +15,7 @@ def __init__(self, vardef): Parameters ---------- - vardef: basestring + vardef: esmvalcore.cmor.table.VariableInfo CMOR table entry """ @@ -31,14 +31,14 @@ def fix_file(self, filepath, output_dir): Parameters ---------- - filepath: basestring + filepath: str file to fix - output_dir: basestring + output_dir: str path to the folder to store the fixe files, if required Returns ------- - basestring + str Path to the corrected file. It can be different from the original filepath if a fix has been applied, but if not it should be the original filepath @@ -121,7 +121,7 @@ def __ne__(self, other): return not self.__eq__(other) @staticmethod - def get_fixes(project, dataset, mip, short_name): + def get_fixes(project, dataset, mip, cmor_name): """ Get the fixes that must be applied for a given dataset. @@ -141,19 +141,18 @@ def get_fixes(project, dataset, mip, short_name): project: str dataset: str mip: str - short_name: str + cmor_name: str Returns ------- list(Fix) Fixes to apply for the given data """ - cmor_table = CMOR_TABLES[project] - vardef = cmor_table.get_variable(mip, short_name) + vardef = get_var_info(project, mip, cmor_name) project = project.replace('-', '_').lower() dataset = dataset.replace('-', '_').lower() - short_name = short_name.replace('-', '_').lower() + cmor_name = cmor_name.replace('-', '_').lower() fixes = [] try: @@ -162,7 +161,7 @@ def get_fixes(project, dataset, mip, short_name): classes = inspect.getmembers(fixes_module, inspect.isclass) classes = dict((name.lower(), value) for name, value in classes) - for fix_name in (short_name, 'allvars'): + for fix_name in (cmor_name, 'allvars'): try: fixes.append(classes[fix_name](vardef)) except KeyError: diff --git a/esmvalcore/cmor/check.py b/esmvalcore/cmor/check.py index 9fcbb5a62b..dfab5584d5 100644 --- a/esmvalcore/cmor/check.py +++ b/esmvalcore/cmor/check.py @@ -4,7 +4,6 @@ from enum import IntEnum import cf_units -import iris.coord_categorisation import iris.coords import iris.exceptions import iris.util @@ -939,7 +938,7 @@ def report_debug_message(self, message, *args): def _get_cmor_checker(table, mip, - short_name, + cmor_name, frequency, fail_on_error=False, check_level=CheckLevels.DEFAULT, @@ -952,9 +951,9 @@ def _get_cmor_checker(table, table, ', '.join(CMOR_TABLES))) cmor_table = CMOR_TABLES[table] - var_info = cmor_table.get_variable(mip, short_name) + var_info = cmor_table.get_variable(mip, cmor_name) if var_info is None: - var_info = CMOR_TABLES['custom'].get_variable(mip, short_name) + var_info = CMOR_TABLES['custom'].get_variable(mip, cmor_name) def _checker(cube): return CMORCheck(cube, @@ -970,7 +969,7 @@ def _checker(cube): def cmor_check_metadata(cube, cmor_table, mip, - short_name, + cmor_name, frequency, check_level=CheckLevels.DEFAULT): """Check if metadata conforms to variable's CMOR definition. @@ -981,20 +980,20 @@ def cmor_check_metadata(cube, ---------- cube: iris.cube.Cube Data cube to check. - cmor_table: basestring + cmor_table: str CMOR definitions to use. mip: Variable's mip. - short_name: basestring - Variable's short name. - frequency: basestring + cmor_name: str + Variable's name. + frequency: str Data frequency. check_level: CheckLevels Level of strictness of the checks. """ checker = _get_cmor_checker(cmor_table, mip, - short_name, + cmor_name, frequency, check_level=check_level) checker(cube).check_metadata() @@ -1004,7 +1003,7 @@ def cmor_check_metadata(cube, def cmor_check_data(cube, cmor_table, mip, - short_name, + cmor_name, frequency, check_level=CheckLevels.DEFAULT): """Check if data conforms to variable's CMOR definition. @@ -1015,28 +1014,28 @@ def cmor_check_data(cube, ---------- cube: iris.cube.Cube Data cube to check. - cmor_table: basestring + cmor_table: str CMOR definitions to use. mip: Variable's mip. - short_name: basestring - Variable's short name - frequency: basestring + cmor_name: str + Variable's name + frequency: str Data frequency check_level: CheckLevels Level of strictness of the checks. """ checker = _get_cmor_checker(cmor_table, mip, - short_name, + cmor_name, frequency, check_level=check_level) checker(cube).check_data() return cube -def cmor_check(cube, cmor_table, mip, short_name, frequency, check_level): - """Check if cube conforms to variable's CMOR definition. +def cmor_check(cube, cmor_table, mip, cmor_name, frequency, check_level): + """Check if cube conforms to variable's CMOR definiton. Equivalent to calling cmor_check_metadata and cmor_check_data consecutively. @@ -1045,13 +1044,13 @@ def cmor_check(cube, cmor_table, mip, short_name, frequency, check_level): ---------- cube: iris.cube.Cube Data cube to check. - cmor_table: basestring + cmor_table: str CMOR definitions to use. mip: Variable's mip. - short_name: basestring - Variable's short name. - frequency: basestring + cmor_name: str + Variable's name. + frequency: str Data frequency. check_level: enum.IntEnum Level of strictness of the checks. @@ -1059,13 +1058,13 @@ def cmor_check(cube, cmor_table, mip, short_name, frequency, check_level): cmor_check_metadata(cube, cmor_table, mip, - short_name, + cmor_name, frequency, check_level=check_level) cmor_check_data(cube, cmor_table, mip, - short_name, + cmor_name, frequency, check_level=check_level) return cube diff --git a/esmvalcore/cmor/fix.py b/esmvalcore/cmor/fix.py index 23cc98e4f9..43e73f8e54 100644 --- a/esmvalcore/cmor/fix.py +++ b/esmvalcore/cmor/fix.py @@ -10,13 +10,15 @@ from iris.cube import CubeList from ._fixes.fix import Fix -from .check import CheckLevels, _get_cmor_checker +from .table import get_var_info +from .check import _get_cmor_checker, CheckLevels logger = logging.getLogger(__name__) -def fix_file(file, short_name, project, dataset, mip, output_dir): - """Fix files before ESMValTool can load them. +def fix_file(file, cmor_name, project, dataset, mip, output_dir): + """ + Fix files before ESMValTool can load them. This fixes are only for issues that prevent iris from loading the cube or that cannot be fixed after the cube is loaded. @@ -27,8 +29,8 @@ def fix_file(file, short_name, project, dataset, mip, output_dir): ---------- file: str Path to the original file - short_name: str - Variable's short name + cmor_name: str + Variable's cmor name project: str dataset:str output_dir: str @@ -42,13 +44,13 @@ def fix_file(file, short_name, project, dataset, mip, output_dir): for fix in Fix.get_fixes(project=project, dataset=dataset, mip=mip, - short_name=short_name): + cmor_name=cmor_name): file = fix.fix_file(file, output_dir) return file def fix_metadata(cubes, - short_name, + cmor_name, project, dataset, mip, @@ -65,8 +67,8 @@ def fix_metadata(cubes, ---------- cubes: iris.cube.CubeList Cubes to fix - short_name: str - Variable's short name + cmor_name: str + Variable's cmor name project: str dataset: str @@ -92,7 +94,8 @@ def fix_metadata(cubes, fixes = Fix.get_fixes(project=project, dataset=dataset, mip=mip, - short_name=short_name) + cmor_name=cmor_name) + short_name = get_var_info(project, mip, cmor_name).short_name fixed_cubes = [] by_file = defaultdict(list) for cube in cubes: @@ -107,7 +110,7 @@ def fix_metadata(cubes, checker = _get_cmor_checker(frequency=frequency, table=project, mip=mip, - short_name=short_name, + cmor_name=cmor_name, check_level=check_level, fail_on_error=False, automatic_fixes=True) @@ -142,7 +145,7 @@ def _get_single_cube(cube_list, short_name, project, dataset): def fix_data(cube, - short_name, + cmor_name, project, dataset, mip, @@ -161,8 +164,8 @@ def fix_data(cube, ---------- cube: iris.cube.Cube Cube to fix - short_name: str - Variable's short name + cmor_name: str + Variable's name project: str dataset: str mip: str @@ -185,12 +188,12 @@ def fix_data(cube, for fix in Fix.get_fixes(project=project, dataset=dataset, mip=mip, - short_name=short_name): + cmor_name=cmor_name): cube = fix.fix_data(cube) checker = _get_cmor_checker(frequency=frequency, table=project, mip=mip, - short_name=short_name, + cmor_name=cmor_name, fail_on_error=False, automatic_fixes=True, check_level=check_level) diff --git a/esmvalcore/cmor/table.py b/esmvalcore/cmor/table.py index 508ba47a8a..5d96640e56 100644 --- a/esmvalcore/cmor/table.py +++ b/esmvalcore/cmor/table.py @@ -22,7 +22,7 @@ """dict of str, obj: CMOR info objects.""" -def get_var_info(project, mip, short_name): +def get_var_info(project, mip, cmor_name): """Get variable information. Parameters @@ -31,10 +31,10 @@ def get_var_info(project, mip, short_name): Dataset's project. mip : str Variable's cmor table. - short_name : str - Variable's short name. + cmor_name : str + Variable's cmor name. """ - return CMOR_TABLES[project].get_variable(mip, short_name) + return CMOR_TABLES[project].get_variable(mip, cmor_name) def read_cmor_tables(cfg_developer=None): @@ -139,15 +139,15 @@ def get_table(self, table): """ return self.tables.get(table) - def get_variable(self, table_name, short_name, derived=False): + def get_variable(self, table_name, cmor_name, derived=False): """Search and return the variable info. Parameters ---------- table_name: basestring Table name - short_name: basestring - Variable's short name + cmor_name: basestring + Variable's CMOR name derived: bool, optional Variable is derived. Info retrieval for derived variables always look on the default tables if variable is not find in the @@ -159,7 +159,7 @@ def get_variable(self, table_name, short_name, derived=False): Return the VariableInfo object for the requested variable if found, returns None if not """ - alt_names_list = self._get_alt_names_list(short_name) + alt_names_list = self._get_alt_names_list(cmor_name) table = self.get_table(table_name) if table: @@ -197,10 +197,10 @@ def _look_in_all_tables(self, alt_names_list): break return var_info - def _get_alt_names_list(self, short_name): - alt_names_list = [short_name] + def _get_alt_names_list(self, cmor_name): + alt_names_list = [cmor_name] for alt_names in self.alt_names: - if short_name in alt_names: + if cmor_name in alt_names: alt_names_list.extend([ alt_name for alt_name in alt_names if alt_name not in alt_names_list @@ -227,7 +227,7 @@ class CMIP6Info(InfoBase): Parameters ---------- - cmor_tables_path: basestring + cmor_tables_path: str Path to the folder containing the Tables folder with the json files default: object @@ -367,7 +367,7 @@ def get_table(self, table): Parameters ---------- - table: basestring + table: str Table name Returns @@ -458,19 +458,21 @@ def _read_json_list_variable(self, parameter): class VariableInfo(JsonInfo): """Class to read and store variable information.""" - def __init__(self, table_type, short_name): + def __init__(self, table_type, cmor_name): """Class to read and store variable information. Parameters ---------- - short_name: str - variable's short name + cmor_name: str + variable's CMOR name """ super(VariableInfo, self).__init__() self.table_type = table_type self.modeling_realm = [] """Modeling realm""" - self.short_name = short_name + self.cmor_name = cmor_name + """CMOR's table name""" + self.short_name = cmor_name """Short name""" self.standard_name = '' """Standard name""" @@ -524,6 +526,7 @@ def read_json(self, json_data, default_freq): """ self._json_data = json_data + self.short_name = self._read_json_variable('out_name') self.standard_name = self._read_json_variable('standard_name') self.long_name = self._read_json_variable('long_name') self.units = self._read_json_variable('units') @@ -616,7 +619,7 @@ class CMIP5Info(InfoBase): Parameters ---------- - cmor_tables_path: basestring + cmor_tables_path: str Path to the folder containing the Tables folder with the json files default: object @@ -737,13 +740,15 @@ def _read_coordinate(self, value): setattr(coord, key, value) return coord - def _read_variable(self, short_name, frequency): - var = VariableInfo('CMIP5', short_name) + def _read_variable(self, cmor_name, frequency): + var = VariableInfo('CMIP5', cmor_name) var.frequency = frequency while self._read_line(): key, value = self._last_line_read if key in ('variable_entry', 'axis_entry'): break + if key == 'out_name': + setattr(var, 'short_name', value) if key in ('dimensions', 'modeling_realm'): setattr(var, key, value.split()) elif hasattr(var, key): @@ -757,7 +762,7 @@ def get_table(self, table): Parameters ---------- - table: basestring + table: str Table name Returns @@ -774,7 +779,7 @@ class CMIP3Info(CMIP5Info): Parameters ---------- - cmor_tables_path: basestring + cmor_tables_path: str Path to the folder containing the Tables folder with the json files default: object @@ -799,8 +804,8 @@ def _read_coordinate(self, value): coord.var_name = coord.name return coord - def _read_variable(self, short_name, frequency): - var = super()._read_variable(short_name, frequency) + def _read_variable(self, cmor_name, frequency): + var = super()._read_variable(cmor_name, frequency) var.frequency = None var.modeling_realm = None return var @@ -811,7 +816,7 @@ class CustomInfo(CMIP5Info): Parameters ---------- - cmor_tables_path: basestring or None + cmor_tables_path: str or None Full path to the table or name for the table if it is present in ESMValTool repository """ @@ -843,15 +848,15 @@ def __init__(self, cmor_tables_path=None): print(msg) raise - def get_variable(self, table, short_name, derived=False): + def get_variable(self, table, cmor_name, derived=False): """Search and return the variable info. Parameters ---------- - table: basestring + table: str Table name - short_name: basestring - Variable's short name + cmor_name: str + Variable's cmor name derived: bool, optional Variable is derived. Info retrieval for derived variables always look on the default tables if variable is not find in the @@ -863,7 +868,7 @@ def get_variable(self, table, short_name, derived=False): Return the VariableInfo object for the requested variable if found, returns None if not """ - return self.tables['custom'].get(short_name, None) + return self.tables['custom'].get(cmor_name, None) def _read_table_file(self, table_file, table=None): with open(table_file) as self._current_table: diff --git a/esmvalcore/preprocessor/_ancillary_vars.py b/esmvalcore/preprocessor/_ancillary_vars.py index 5d6dbe32d1..c5c220b021 100644 --- a/esmvalcore/preprocessor/_ancillary_vars.py +++ b/esmvalcore/preprocessor/_ancillary_vars.py @@ -18,12 +18,12 @@ def _load_fx(fx_info, check_level): for fx_file in fx_info['filename']: loaded_cube = load(fx_file, callback=concatenate_callback) - short_name = fx_info['short_name'] + cmor_name = fx_info['cmor_name'] project = fx_info['project'] dataset = fx_info['dataset'] mip = fx_info['mip'] freq = fx_info['frequency'] - loaded_cube = fix_metadata(loaded_cube, short_name=short_name, + loaded_cube = fix_metadata(loaded_cube, cmor_name=cmor_name, project=project, dataset=dataset, mip=mip, frequency=freq, check_level=check_level) @@ -32,15 +32,15 @@ def _load_fx(fx_info, check_level): fx_cube = concatenate(fx_cubes) fx_cube = cmor_check_metadata(fx_cube, cmor_table=project, mip=mip, - short_name=short_name, frequency=freq, + cmor_name=cmor_name, frequency=freq, check_level=check_level) - fx_cube = fix_data(fx_cube, short_name=short_name, project=project, + fx_cube = fix_data(fx_cube, cmor_name=cmor_name, project=project, dataset=dataset, mip=mip, frequency=freq, check_level=check_level) fx_cube = cmor_check_data(fx_cube, cmor_table=project, mip=mip, - short_name=fx_cube.var_name, frequency=freq, + cmor_name=cmor_name, frequency=freq, check_level=check_level) return fx_cube diff --git a/esmvalcore/preprocessor/_derive/__init__.py b/esmvalcore/preprocessor/_derive/__init__.py index 17209f0006..6bc9654327 100644 --- a/esmvalcore/preprocessor/_derive/__init__.py +++ b/esmvalcore/preprocessor/_derive/__init__.py @@ -16,16 +16,15 @@ def _get_all_derived_variables(): Returns ------- dict - All derived variables with `short_name` (keys) and the associated + All derived variables with `cmor_name` (keys) and the associated python classes (values). - """ derivers = {} for path in Path(__file__).parent.glob('[a-z]*.py'): - short_name = path.stem + cmor_name = path.stem module = importlib.import_module( - f'esmvalcore.preprocessor._derive.{short_name}') - derivers[short_name] = getattr(module, 'DerivedVariable') + f'esmvalcore.preprocessor._derive.{cmor_name}') + derivers[cmor_name] = getattr(module, 'DerivedVariable') return derivers @@ -34,34 +33,33 @@ def _get_all_derived_variables(): __all__ = list(ALL_DERIVED_VARIABLES) -def get_required(short_name, project): +def get_required(cmor_name, project): """Return all required variables for derivation. - Get all information (at least `short_name`) required for derivation. + Get all information (at least `var_name`) required for derivation. Parameters ---------- - short_name : str - `short_name` of the variable to derive. + cmor_name : str + name of the variable to derive. project : str `project` of the variable to derive. Returns ------- list - List of dictionaries (including at least the key `short_name`). - + List of dictionaries (including at least the key `cmor_name`). """ - if short_name not in ALL_DERIVED_VARIABLES: + if cmor_name not in ALL_DERIVED_VARIABLES: raise NotImplementedError( - f"Cannot derive variable '{short_name}', no derivation script " + f"Cannot derive variable '{cmor_name}', no derivation script " f"available") - DerivedVariable = ALL_DERIVED_VARIABLES[short_name] # noqa: N806 + DerivedVariable = ALL_DERIVED_VARIABLES[cmor_name] # noqa: N806 variables = deepcopy(DerivedVariable().required(project)) return variables -def derive(cubes, short_name, long_name, units, standard_name=None): +def derive(cubes, cmor_name, short_name, long_name, units, standard_name=None): """Derive variable. Parameters @@ -69,8 +67,8 @@ def derive(cubes, short_name, long_name, units, standard_name=None): cubes: iris.cube.CubeList Includes all the needed variables for derivation defined in :func:`get_required`. - short_name: str - short_name + cmor_name: str + cmor_name long_name: str long_name units: str @@ -82,7 +80,6 @@ def derive(cubes, short_name, long_name, units, standard_name=None): ------- iris.cube.Cube The new derived variable. - """ if short_name == cubes[0].var_name: return cubes[0] @@ -90,13 +87,15 @@ def derive(cubes, short_name, long_name, units, standard_name=None): cubes = iris.cube.CubeList(cubes) # Derive variable - DerivedVariable = ALL_DERIVED_VARIABLES[short_name.lower()] # noqa: N806 + DerivedVariable = ALL_DERIVED_VARIABLES[cmor_name.lower()] # noqa: N806 try: cube = DerivedVariable().calculate(cubes) except Exception as exc: - msg = (f"Derivation of variable '{short_name}' failed. If you used " + msg = (f"Derivation of variable '{cmor_name}' failed. If you used " f"the option '--skip-nonexistent' for running your recipe, " - f"this might be caused by missing input data for derivation") + f"this might be caused by missing input data for derivation " + f"('{cmor_name}' needs the variables " + f"{DerivedVariable().required}).") raise ValueError(msg) from exc # Set standard attributes diff --git a/esmvalcore/preprocessor/_derive/alb.py b/esmvalcore/preprocessor/_derive/alb.py index a45d5dbfe5..34f35c0b94 100644 --- a/esmvalcore/preprocessor/_derive/alb.py +++ b/esmvalcore/preprocessor/_derive/alb.py @@ -18,10 +18,10 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rsdscs' + 'cmor_name': 'rsdscs' }, { - 'short_name': 'rsuscs' + 'cmor_name': 'rsuscs' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/amoc.py b/esmvalcore/preprocessor/_derive/amoc.py index fd09caf4b3..7496ab174a 100644 --- a/esmvalcore/preprocessor/_derive/amoc.py +++ b/esmvalcore/preprocessor/_derive/amoc.py @@ -11,7 +11,7 @@ class DerivedVariable(DerivedVariableBase): @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'msftmyz', 'mip': 'Omon'}] + required = [{'cmor_name': 'msftmyz', 'mip': 'Omon'}] return required @staticmethod diff --git a/esmvalcore/preprocessor/_derive/asr.py b/esmvalcore/preprocessor/_derive/asr.py index 30f65c4ff8..0c321a17cd 100644 --- a/esmvalcore/preprocessor/_derive/asr.py +++ b/esmvalcore/preprocessor/_derive/asr.py @@ -11,7 +11,7 @@ class DerivedVariable(DerivedVariableBase): @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'rsdt'}, {'short_name': 'rsut'}] + required = [{'cmor_name': 'rsdt'}, {'cmor_name': 'rsut'}] return required @staticmethod diff --git a/esmvalcore/preprocessor/_derive/clhmtisccp.py b/esmvalcore/preprocessor/_derive/clhmtisccp.py index b20d1ee0ff..b5cbaa723d 100644 --- a/esmvalcore/preprocessor/_derive/clhmtisccp.py +++ b/esmvalcore/preprocessor/_derive/clhmtisccp.py @@ -12,7 +12,7 @@ class DerivedVariable(DerivedVariableBase): @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'clisccp'}] + required = [{'cmor_name': 'clisccp'}] return required @staticmethod diff --git a/esmvalcore/preprocessor/_derive/clhtkisccp.py b/esmvalcore/preprocessor/_derive/clhtkisccp.py index 9b9b5106e2..57dd1fceab 100644 --- a/esmvalcore/preprocessor/_derive/clhtkisccp.py +++ b/esmvalcore/preprocessor/_derive/clhtkisccp.py @@ -12,7 +12,7 @@ class DerivedVariable(DerivedVariableBase): @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'clisccp'}] + required = [{'cmor_name': 'clisccp'}] return required @staticmethod diff --git a/esmvalcore/preprocessor/_derive/cllmtisccp.py b/esmvalcore/preprocessor/_derive/cllmtisccp.py index 28b5104ea8..53efa2c26e 100644 --- a/esmvalcore/preprocessor/_derive/cllmtisccp.py +++ b/esmvalcore/preprocessor/_derive/cllmtisccp.py @@ -12,7 +12,7 @@ class DerivedVariable(DerivedVariableBase): @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'clisccp'}] + required = [{'var_name': 'clisccp'}] return required @staticmethod diff --git a/esmvalcore/preprocessor/_derive/clltkisccp.py b/esmvalcore/preprocessor/_derive/clltkisccp.py index 3d0ba17363..4b64655367 100644 --- a/esmvalcore/preprocessor/_derive/clltkisccp.py +++ b/esmvalcore/preprocessor/_derive/clltkisccp.py @@ -12,7 +12,7 @@ class DerivedVariable(DerivedVariableBase): @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'clisccp'}] + required = [{'cmor_name': 'clisccp'}] return required @staticmethod diff --git a/esmvalcore/preprocessor/_derive/clmmtisccp.py b/esmvalcore/preprocessor/_derive/clmmtisccp.py index 53129d065e..51ce0aee8e 100644 --- a/esmvalcore/preprocessor/_derive/clmmtisccp.py +++ b/esmvalcore/preprocessor/_derive/clmmtisccp.py @@ -12,7 +12,7 @@ class DerivedVariable(DerivedVariableBase): @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'clisccp'}] + required = [{'cmor_name': 'clisccp'}] return required @staticmethod diff --git a/esmvalcore/preprocessor/_derive/clmtkisccp.py b/esmvalcore/preprocessor/_derive/clmtkisccp.py index a61314a470..0ce38c0045 100644 --- a/esmvalcore/preprocessor/_derive/clmtkisccp.py +++ b/esmvalcore/preprocessor/_derive/clmtkisccp.py @@ -12,7 +12,7 @@ class DerivedVariable(DerivedVariableBase): @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'clisccp'}] + required = [{'cmor_name': 'clisccp'}] return required @staticmethod diff --git a/esmvalcore/preprocessor/_derive/ctotal.py b/esmvalcore/preprocessor/_derive/ctotal.py index 18bef27071..91c447bb99 100644 --- a/esmvalcore/preprocessor/_derive/ctotal.py +++ b/esmvalcore/preprocessor/_derive/ctotal.py @@ -17,22 +17,22 @@ def required(project): if project == 'CMIP5': required = [ { - 'short_name': 'cVeg', + 'cmor_name': 'cVeg', 'mip': 'Lmon' }, { - 'short_name': 'cSoil', + 'cmor_name': 'cSoil', 'mip': 'Lmon' }, ] elif project == 'CMIP6': required = [ { - 'short_name': 'cVeg', + 'cmor_name': 'cVeg', 'mip': 'Lmon' }, { - 'short_name': 'cSoil', + 'cmor_name': 'cSoil', 'mip': 'Emon' }, ] diff --git a/esmvalcore/preprocessor/_derive/et.py b/esmvalcore/preprocessor/_derive/et.py index abdde1c191..7759da1848 100644 --- a/esmvalcore/preprocessor/_derive/et.py +++ b/esmvalcore/preprocessor/_derive/et.py @@ -15,7 +15,7 @@ class DerivedVariable(DerivedVariableBase): @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'hfls', 'mip': 'Amon'}] + required = [{'cmor_name': 'hfls', 'mip': 'Amon'}] return required @staticmethod diff --git a/esmvalcore/preprocessor/_derive/lvp.py b/esmvalcore/preprocessor/_derive/lvp.py index 84572f424d..775342518c 100644 --- a/esmvalcore/preprocessor/_derive/lvp.py +++ b/esmvalcore/preprocessor/_derive/lvp.py @@ -2,7 +2,6 @@ authors: - weig_ka - """ from esmvalcore.iris_helpers import var_name_constraint @@ -12,19 +11,18 @@ class DerivedVariable(DerivedVariableBase): """Derivation of variable `lvp`.""" - @staticmethod def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'hfls' + 'cmor_name': 'hfls' }, { - 'short_name': 'pr' + 'cmor_name': 'pr' }, { - 'short_name': 'evspsbl' + 'cmor_name': 'evspsbl' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/lwcre.py b/esmvalcore/preprocessor/_derive/lwcre.py index ed7b1ada77..17bcbab846 100644 --- a/esmvalcore/preprocessor/_derive/lwcre.py +++ b/esmvalcore/preprocessor/_derive/lwcre.py @@ -13,10 +13,10 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rlut' + 'cmor_name': 'rlut' }, { - 'short_name': 'rlutcs' + 'cmor_name': 'rlutcs' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/lwp.py b/esmvalcore/preprocessor/_derive/lwp.py index f033070b0b..6462d5d750 100644 --- a/esmvalcore/preprocessor/_derive/lwp.py +++ b/esmvalcore/preprocessor/_derive/lwp.py @@ -17,10 +17,10 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'clwvi' + 'cmor_name': 'clwvi' }, { - 'short_name': 'clivi' + 'cmor_name': 'clivi' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/netcre.py b/esmvalcore/preprocessor/_derive/netcre.py index 806a79000b..60ee25b104 100644 --- a/esmvalcore/preprocessor/_derive/netcre.py +++ b/esmvalcore/preprocessor/_derive/netcre.py @@ -13,16 +13,16 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rlut' + 'cmor_name': 'rlut' }, { - 'short_name': 'rlutcs' + 'cmor_name': 'rlutcs' }, { - 'short_name': 'rsut' + 'cmor_name': 'rsut' }, { - 'short_name': 'rsutcs' + 'cmor_name': 'rsutcs' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/ohc.py b/esmvalcore/preprocessor/_derive/ohc.py index d8d374b312..ea5d4cb32f 100644 --- a/esmvalcore/preprocessor/_derive/ohc.py +++ b/esmvalcore/preprocessor/_derive/ohc.py @@ -1,8 +1,7 @@ """Derivation of variable `ohc`.""" import iris -from iris import Constraint - from cf_units import Unit +from iris import Constraint from ._baseclass import DerivedVariableBase @@ -11,26 +10,25 @@ class DerivedVariable(DerivedVariableBase): """Derivation of variable `ohc`.""" - @staticmethod def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'thetao' + 'cmor_name': 'thetao' }, { - 'short_name': 'volcello', + 'cmor_name': 'volcello', 'mip': 'fx' }, ] if project == 'CMIP6': required = [ { - 'short_name': 'thetao' + 'cmor_name': 'thetao' }, { - 'short_name': 'volcello', + 'cmor_name': 'volcello', 'mip': 'Ofx' }, ] @@ -38,8 +36,7 @@ def required(project): @staticmethod def calculate(cubes): - """ - Compute ocean heat content. + """Compute ocean heat content. Use c_p*rho_0= 4.09169e+6 J m-3 K-1 (Kuhlbrodt et al., 2015, Clim. Dyn.) diff --git a/esmvalcore/preprocessor/_derive/rlns.py b/esmvalcore/preprocessor/_derive/rlns.py index ed41aae039..121c58c6c8 100644 --- a/esmvalcore/preprocessor/_derive/rlns.py +++ b/esmvalcore/preprocessor/_derive/rlns.py @@ -13,10 +13,10 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rlds' + 'cmor_name': 'rlds' }, { - 'short_name': 'rlus' + 'cmor_name': 'rlus' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/rlnst.py b/esmvalcore/preprocessor/_derive/rlnst.py index 4eecd9b90d..aa211b9108 100644 --- a/esmvalcore/preprocessor/_derive/rlnst.py +++ b/esmvalcore/preprocessor/_derive/rlnst.py @@ -17,13 +17,13 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rlds' + 'cmor_name': 'rlds' }, { - 'short_name': 'rlus' + 'cmor_name': 'rlus' }, { - 'short_name': 'rlut' + 'cmor_name': 'rlut' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/rlnstcs.py b/esmvalcore/preprocessor/_derive/rlnstcs.py index 10613216a9..fb2013c869 100644 --- a/esmvalcore/preprocessor/_derive/rlnstcs.py +++ b/esmvalcore/preprocessor/_derive/rlnstcs.py @@ -17,13 +17,13 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rldscs' + 'cmor_name': 'rldscs' }, { - 'short_name': 'rlus' + 'cmor_name': 'rlus' }, { - 'short_name': 'rlutcs' + 'cmor_name': 'rlutcs' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/rlntcs.py b/esmvalcore/preprocessor/_derive/rlntcs.py index 49a7f498ab..d2e308ff05 100644 --- a/esmvalcore/preprocessor/_derive/rlntcs.py +++ b/esmvalcore/preprocessor/_derive/rlntcs.py @@ -10,7 +10,7 @@ class DerivedVariable(DerivedVariableBase): @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'rlutcs'}] + required = [{'cmor_name': 'rlutcs'}] return required @staticmethod diff --git a/esmvalcore/preprocessor/_derive/rsns.py b/esmvalcore/preprocessor/_derive/rsns.py index 27ba4cb968..7c1d1fb04a 100644 --- a/esmvalcore/preprocessor/_derive/rsns.py +++ b/esmvalcore/preprocessor/_derive/rsns.py @@ -13,10 +13,10 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rsds' + 'cmor_name': 'rsds' }, { - 'short_name': 'rsus' + 'cmor_name': 'rsus' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/rsnst.py b/esmvalcore/preprocessor/_derive/rsnst.py index e2a2a53b21..f709f5f2f3 100644 --- a/esmvalcore/preprocessor/_derive/rsnst.py +++ b/esmvalcore/preprocessor/_derive/rsnst.py @@ -17,16 +17,16 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rsds' + 'cmor_name': 'rsds' }, { - 'short_name': 'rsdt' + 'cmor_name': 'rsdt' }, { - 'short_name': 'rsus' + 'cmor_name': 'rsus' }, { - 'short_name': 'rsut' + 'cmor_name': 'rsut' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/rsnstcs.py b/esmvalcore/preprocessor/_derive/rsnstcs.py index 976be64003..cb2296dc7c 100644 --- a/esmvalcore/preprocessor/_derive/rsnstcs.py +++ b/esmvalcore/preprocessor/_derive/rsnstcs.py @@ -17,16 +17,16 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rsdscs' + 'cmor_name': 'rsdscs' }, { - 'short_name': 'rsdt' + 'cmor_name': 'rsdt' }, { - 'short_name': 'rsuscs' + 'cmor_name': 'rsuscs' }, { - 'short_name': 'rsutcs' + 'cmor_name': 'rsutcs' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/rsnstcsnorm.py b/esmvalcore/preprocessor/_derive/rsnstcsnorm.py index a6445bbb64..0c339e4ebd 100644 --- a/esmvalcore/preprocessor/_derive/rsnstcsnorm.py +++ b/esmvalcore/preprocessor/_derive/rsnstcsnorm.py @@ -18,16 +18,16 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rsdscs' + 'var_name': 'rsdscs' }, { - 'short_name': 'rsdt' + 'var_name': 'rsdt' }, { - 'short_name': 'rsuscs' + 'var_name': 'rsuscs' }, { - 'short_name': 'rsutcs' + 'var_name': 'rsutcs' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/rsnt.py b/esmvalcore/preprocessor/_derive/rsnt.py index 7838c3a0b1..e340cd8ef0 100644 --- a/esmvalcore/preprocessor/_derive/rsnt.py +++ b/esmvalcore/preprocessor/_derive/rsnt.py @@ -13,10 +13,10 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rsdt' + 'var_name': 'rsdt' }, { - 'short_name': 'rsut' + 'var_name': 'rsut' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/rsntcs.py b/esmvalcore/preprocessor/_derive/rsntcs.py index 9a4586d3fd..b150e9c71d 100644 --- a/esmvalcore/preprocessor/_derive/rsntcs.py +++ b/esmvalcore/preprocessor/_derive/rsntcs.py @@ -12,10 +12,10 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rsdt' + 'var_name': 'rsdt' }, { - 'short_name': 'rsutcs' + 'var_name': 'rsutcs' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/rtnt.py b/esmvalcore/preprocessor/_derive/rtnt.py index 012773ad69..3faa86e039 100644 --- a/esmvalcore/preprocessor/_derive/rtnt.py +++ b/esmvalcore/preprocessor/_derive/rtnt.py @@ -13,13 +13,13 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rsdt' + 'cmor_name': 'rsdt' }, { - 'short_name': 'rsut' + 'cmor_name': 'rsut' }, { - 'short_name': 'rlut' + 'cmor_name': 'rlut' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/sispeed.py b/esmvalcore/preprocessor/_derive/sispeed.py index 168b2e5525..8fb8eefad9 100644 --- a/esmvalcore/preprocessor/_derive/sispeed.py +++ b/esmvalcore/preprocessor/_derive/sispeed.py @@ -1,10 +1,10 @@ """Derivation of variable `sispeed`.""" import logging + from iris import Constraint from .._regrid import regrid - from ._baseclass import DerivedVariableBase logger = logging.getLogger(__name__) @@ -12,20 +12,18 @@ class DerivedVariable(DerivedVariableBase): """Derivation of variable `sispeed`.""" - @staticmethod def required(project): """Declare the variables needed for derivation.""" if project == 'CMIP6': - required = [{'short_name': 'siu'}, {'short_name': 'siv'}] + required = [{'cmor_name': 'siu'}, {'cmor_name': 'siv'}] else: - required = [{'short_name': 'usi'}, {'short_name': 'vsi'}] + required = [{'cmor_name': 'usi'}, {'cmor_name': 'vsi'}] return required @staticmethod def calculate(cubes): - """ - Compute sispeed module from velocity components siu and siv. + """Compute sispeed module from velocity components siu and siv. Arguments --------- @@ -34,7 +32,6 @@ def calculate(cubes): Returns ------- Cube containing sea ice speed. - """ siu = cubes.extract_cube(Constraint(name='sea_ice_x_velocity')) siv = cubes.extract_cube(Constraint(name='sea_ice_y_velocity')) diff --git a/esmvalcore/preprocessor/_derive/sithick.py b/esmvalcore/preprocessor/_derive/sithick.py index ad80709d8f..9f2ca22403 100644 --- a/esmvalcore/preprocessor/_derive/sithick.py +++ b/esmvalcore/preprocessor/_derive/sithick.py @@ -12,9 +12,9 @@ class DerivedVariable(DerivedVariableBase): def required(project): """Declare the variables needed for derivation.""" required = [{ - 'short_name': 'sit', + 'cmor_name': 'sit', }, { - 'short_name': 'sic', + 'cmor_name': 'sic', }] return required diff --git a/esmvalcore/preprocessor/_derive/sm.py b/esmvalcore/preprocessor/_derive/sm.py index 495e8bd304..fbc85f8167 100644 --- a/esmvalcore/preprocessor/_derive/sm.py +++ b/esmvalcore/preprocessor/_derive/sm.py @@ -10,11 +10,10 @@ class DerivedVariable(DerivedVariableBase): """Derivation of variable `sm`.""" - @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'mrsos'}] + required = [{'cmor_name': 'mrsos'}] return required @staticmethod @@ -26,7 +25,6 @@ def calculate(cubes): Convert moisture content of soil layer (kg/m2) into volumetric soil moisture (m3/m3), assuming density of water 998.2 kg/m2 (at temperature 20 deg C). - """ mrsos_cube = cubes.extract_cube(var_name_constraint('mrsos')) diff --git a/esmvalcore/preprocessor/_derive/swcre.py b/esmvalcore/preprocessor/_derive/swcre.py index 9fcf056f4f..63874d9e4f 100644 --- a/esmvalcore/preprocessor/_derive/swcre.py +++ b/esmvalcore/preprocessor/_derive/swcre.py @@ -13,10 +13,10 @@ def required(project): """Declare the variables needed for derivation.""" required = [ { - 'short_name': 'rsut' + 'var_name': 'rsut' }, { - 'short_name': 'rsutcs' + 'var_name': 'rsutcs' }, ] return required diff --git a/esmvalcore/preprocessor/_derive/toz.py b/esmvalcore/preprocessor/_derive/toz.py index 32fd9e8334..2e333e538e 100644 --- a/esmvalcore/preprocessor/_derive/toz.py +++ b/esmvalcore/preprocessor/_derive/toz.py @@ -21,14 +21,13 @@ class DerivedVariable(DerivedVariableBase): """Derivation of variable `toz`.""" - @staticmethod def required(project): """Declare the variables needed for derivation.""" if project == 'CMIP6': - required = [{'short_name': 'o3'}, {'short_name': 'ps'}] + required = [{'cmor_name': 'o3'}, {'cmor_name': 'ps'}] else: - required = [{'short_name': 'tro3'}, {'short_name': 'ps'}] + required = [{'cmor_name': 'tro3'}, {'cmor_name': 'ps'}] return required @staticmethod @@ -39,7 +38,6 @@ def calculate(cubes): ---- The surface pressure is used as a lower integration bound. A fixed upper integration bound of 0 Pa is used. - """ tro3_cube = cubes.extract_cube( iris.Constraint(name='mole_fraction_of_ozone_in_air')) diff --git a/esmvalcore/preprocessor/_derive/uajet.py b/esmvalcore/preprocessor/_derive/uajet.py index 677736e433..0d4f2ee0d0 100644 --- a/esmvalcore/preprocessor/_derive/uajet.py +++ b/esmvalcore/preprocessor/_derive/uajet.py @@ -17,7 +17,7 @@ class DerivedVariable(DerivedVariableBase): @staticmethod def required(project): """Declare the variables needed for derivation.""" - required = [{'short_name': 'ua'}] + required = [{'cmor_name': 'ua'}] return required @staticmethod diff --git a/esmvalcore/preprocessor/_derive/vegfrac.py b/esmvalcore/preprocessor/_derive/vegfrac.py index b4585dcd80..c0ecd31c83 100644 --- a/esmvalcore/preprocessor/_derive/vegfrac.py +++ b/esmvalcore/preprocessor/_derive/vegfrac.py @@ -2,23 +2,29 @@ import dask.array as da import iris + from esmvalcore.iris_helpers import var_name_constraint from .._regrid import regrid - from ._baseclass import DerivedVariableBase class DerivedVariable(DerivedVariableBase): """Derivation of variable `vegFrac`.""" - @staticmethod def required(project): """Declare the variables needed for derivation.""" required = [ - {'short_name': 'baresoilFrac'}, - {'short_name': 'residualFrac'}, - {'short_name': 'sftlf', 'mip': 'fx'}, + { + 'cmor_name': 'baresoilFrac' + }, + { + 'cmor_name': 'residualFrac' + }, + { + 'cmor_name': 'sftlf', + 'mip': 'fx' + }, ] return required diff --git a/esmvalcore/preprocessor/_io.py b/esmvalcore/preprocessor/_io.py index f508f0fa4f..7773dd7ee1 100644 --- a/esmvalcore/preprocessor/_io.py +++ b/esmvalcore/preprocessor/_io.py @@ -32,7 +32,6 @@ def _fix_aux_factories(cube): """Fix :class:`iris.aux_factory.AuxCoordFactory` after concatenation. Necessary because of bug in :mod:`iris` (see issue #2478). - """ coord_names = [coord.name() for coord in cube.coords()] @@ -197,10 +196,13 @@ def concatenate(cubes): return result -def save(cubes, filename, optimize_access='', compress=False, alias='', +def save(cubes, + filename, + optimize_access='', + compress=False, + alias='', **kwargs): - """ - Save iris cubes to file. + """Save iris cubes to file. Parameters ---------- @@ -226,7 +228,6 @@ def save(cubes, filename, optimize_access='', compress=False, alias='', ------- str filename - """ # Rename some arguments kwargs['target'] = filename @@ -266,8 +267,8 @@ def save(cubes, filename, optimize_access='', compress=False, alias='', if alias: for cube in cubes: - logger.debug( - 'Changing var_name from %s to %s', cube.var_name, alias) + logger.debug('Changing var_name from %s to %s', cube.var_name, + alias) cube.var_name = alias iris.save(cubes, **kwargs) @@ -355,7 +356,7 @@ def _write_ncl_metadata(output_dir, metadata): variable_info[key] = variable[key] filename = os.path.join(output_dir, - variable_info['short_name'] + '_info.ncl') + variable_info['cmor_name'] + '_info.ncl') write_ncl_settings(info, filename) return filename diff --git a/esmvalcore/preprocessor/_regrid.py b/esmvalcore/preprocessor/_regrid.py index 7ff8dde22d..297d58053d 100644 --- a/esmvalcore/preprocessor/_regrid.py +++ b/esmvalcore/preprocessor/_regrid.py @@ -733,7 +733,7 @@ def get_cmor_levels(cmor_table, coordinate): coordinate, cmor_table)) -def get_reference_levels(filename, project, dataset, short_name, mip, +def get_reference_levels(filename, project, dataset, cmor_name, mip, frequency, fix_dir): """Get level definition from a reference dataset. @@ -766,7 +766,7 @@ def get_reference_levels(filename, project, dataset, short_name, mip, """ filename = fix_file( file=filename, - short_name=short_name, + cmor_name=cmor_name, project=project, dataset=dataset, mip=mip, @@ -775,7 +775,7 @@ def get_reference_levels(filename, project, dataset, short_name, mip, cubes = load(filename, callback=concatenate_callback) cubes = fix_metadata( cubes=cubes, - short_name=short_name, + cmor_name=cmor_name, project=project, dataset=dataset, mip=mip, diff --git a/tests/integration/cmor/_fixes/cmip5/test_bcc_csm1_1.py b/tests/integration/cmor/_fixes/cmip5/test_bcc_csm1_1.py index a55007923e..39a4981b2f 100644 --- a/tests/integration/cmor/_fixes/cmip5/test_bcc_csm1_1.py +++ b/tests/integration/cmor/_fixes/cmip5/test_bcc_csm1_1.py @@ -22,7 +22,6 @@ def test_cl_fix(): class TestTos(unittest.TestCase): """Test tos fixes.""" - def test_get(self): """Test fix get.""" self.assertListEqual( @@ -79,13 +78,13 @@ def test_tos_fix_data(): [[-30.0, -23.75, -13.75, -20.0], [-23.75, 3.75, 13.75, -13.75], [3.75, 10.0, 20.0, 13.75]]]) - np.testing.assert_allclose(fixed_cube.coord('latitude').bounds, - latitude_bounds) + np.testing.assert_allclose( + fixed_cube.coord('latitude').bounds, latitude_bounds) longitude_bounds = np.array([[[140.625, 99.375, 99.375, 140.625], [99.375, 140.625, 140.625, 99.375], [140.625, 99.375, 99.375, 140.625]], [[140.625, 99.375, 99.375, 140.625], [99.375, 140.625, 140.625, 99.375], [140.625, 99.375, 99.375, 140.625]]]) - np.testing.assert_allclose(fixed_cube.coord('longitude').bounds, - longitude_bounds) + np.testing.assert_allclose( + fixed_cube.coord('longitude').bounds, longitude_bounds) diff --git a/tests/integration/cmor/_fixes/cmip5/test_bnu_esm.py b/tests/integration/cmor/_fixes/cmip5/test_bnu_esm.py index e8045902f5..9937f2a32a 100644 --- a/tests/integration/cmor/_fixes/cmip5/test_bnu_esm.py +++ b/tests/integration/cmor/_fixes/cmip5/test_bnu_esm.py @@ -50,6 +50,7 @@ def test_get(self): def test_fix_metadata(self): """Test unit change.""" + cube = self.fix.fix_metadata([self.cube])[0] self.assertEqual(cube.units, Unit('1e-6')) self.assertEqual(cube.data[0], 1.0) diff --git a/tests/integration/cmor/_fixes/cmip5/test_ccsm4.py b/tests/integration/cmor/_fixes/cmip5/test_ccsm4.py index 21019ad02d..aa844f2390 100644 --- a/tests/integration/cmor/_fixes/cmip5/test_ccsm4.py +++ b/tests/integration/cmor/_fixes/cmip5/test_ccsm4.py @@ -24,7 +24,6 @@ def test_cl_fix(): class TestCsoil(unittest.TestCase): """Test cSoil fixes.""" - def setUp(self): """Prepare tests.""" self.cube = Cube([1.0, 1.e33], var_name='cSoil', units='kg m-2') @@ -44,7 +43,6 @@ def test_fix_data(self): class TestsRlut(unittest.TestCase): """Test for rlut fixes.""" - def setUp(self): """Prepare tests.""" self.cube = Cube([1.0, 2.0], var_name='rlut') @@ -75,7 +73,6 @@ def test_fix_metadata(self): class TestsRlutcs(unittest.TestCase): """Test for rlutcs fixes.""" - def setUp(self): """Prepare tests.""" self.cube = Cube([1.0, 2.0], var_name='rlutcs') @@ -106,7 +103,6 @@ def test_fix_metadata(self): class TestSo(unittest.TestCase): """Tests for so fixes.""" - def setUp(self): """Prepare tests.""" self.cube = Cube([1.0, 2.0], var_name='so', units='1.0') diff --git a/tests/integration/cmor/_fixes/cmip5/test_cnrm_cm5.py b/tests/integration/cmor/_fixes/cmip5/test_cnrm_cm5.py index ae9da2ef04..deaacf5e84 100644 --- a/tests/integration/cmor/_fixes/cmip5/test_cnrm_cm5.py +++ b/tests/integration/cmor/_fixes/cmip5/test_cnrm_cm5.py @@ -4,8 +4,8 @@ from cf_units import Unit from iris.cube import Cube -from esmvalcore.cmor.fix import Fix from esmvalcore.cmor._fixes.cmip5.cnrm_cm5 import Msftmyz, Msftmyzba +from esmvalcore.cmor.fix import Fix class TestMsftmyz(unittest.TestCase): diff --git a/tests/integration/cmor/_fixes/cmip5/test_hadgem2_cc.py b/tests/integration/cmor/_fixes/cmip5/test_hadgem2_cc.py index ed2f7c0d1f..8d339bb276 100644 --- a/tests/integration/cmor/_fixes/cmip5/test_hadgem2_cc.py +++ b/tests/integration/cmor/_fixes/cmip5/test_hadgem2_cc.py @@ -1,8 +1,8 @@ """Test HADGEM2-CC fixes.""" import unittest +from esmvalcore.cmor._fixes.cmip5.hadgem2_cc import O2, AllVars from esmvalcore.cmor.fix import Fix -from esmvalcore.cmor._fixes.cmip5.hadgem2_cc import AllVars, O2 class TestAllVars(unittest.TestCase): diff --git a/tests/integration/cmor/_fixes/cmip5/test_miroc_esm_chem.py b/tests/integration/cmor/_fixes/cmip5/test_miroc_esm_chem.py index 186f321710..a98318f9e4 100644 --- a/tests/integration/cmor/_fixes/cmip5/test_miroc_esm_chem.py +++ b/tests/integration/cmor/_fixes/cmip5/test_miroc_esm_chem.py @@ -5,8 +5,8 @@ from cf_units import Unit from iris.cube import Cube -from esmvalcore.cmor.fix import Fix from esmvalcore.cmor._fixes.cmip5.miroc_esm_chem import Tro3 +from esmvalcore.cmor.fix import Fix class TestTro3(unittest.TestCase): diff --git a/tests/integration/cmor/_fixes/cmip5/test_mri_esm1.py b/tests/integration/cmor/_fixes/cmip5/test_mri_esm1.py index c00af1d6fe..e30fceebc0 100644 --- a/tests/integration/cmor/_fixes/cmip5/test_mri_esm1.py +++ b/tests/integration/cmor/_fixes/cmip5/test_mri_esm1.py @@ -1,8 +1,8 @@ """Test MRI-ESM1 fixes.""" import unittest -from esmvalcore.cmor.fix import Fix from esmvalcore.cmor._fixes.cmip5.mri_esm1 import Msftmyz +from esmvalcore.cmor.fix import Fix class TestMsftmyz(unittest.TestCase): diff --git a/tests/integration/cmor/_fixes/cmip5/test_noresm1_me.py b/tests/integration/cmor/_fixes/cmip5/test_noresm1_me.py index ab286d78bd..8e57166c85 100644 --- a/tests/integration/cmor/_fixes/cmip5/test_noresm1_me.py +++ b/tests/integration/cmor/_fixes/cmip5/test_noresm1_me.py @@ -1,10 +1,10 @@ """Tests for fixes of NorESM1-ME (CMIP5).""" -import pytest import iris +import pytest from iris.cube import CubeList -from esmvalcore.cmor.fix import Fix from esmvalcore.cmor._fixes.cmip5.noresm1_me import Tas +from esmvalcore.cmor.fix import Fix DIM_COORD_SHORT = iris.coords.DimCoord( [1.0, 2.0, 3.0], diff --git a/tests/integration/cmor/test_table.py b/tests/integration/cmor/test_table.py index 0580fad4dc..bf61a80994 100644 --- a/tests/integration/cmor/test_table.py +++ b/tests/integration/cmor/test_table.py @@ -44,6 +44,12 @@ def test_get_variable_tas(self): var = self.variables_info.get_variable('Amon', 'tas') self.assertEqual(var.short_name, 'tas') + def test_get_variable_different_out_name(self): + """Get tas variable.""" + var = self.variables_info.get_variable('6hrPlevPt', 'zg7h') + self.assertEqual(var.short_name, 'zg') + self.assertEqual(var.cmor_name, 'zg7h') + def test_get_variable_from_alt_names(self): """Get a variable from a known alt_names.""" var = self.variables_info.get_variable('SImon', 'sic') @@ -227,7 +233,7 @@ def test_aermon_ta_fail_if_strict(self): """Get ta fails with AERMonZ if strict.""" self.assertIsNone(self.variables_info.get_variable('Omon', 'ta')) - def test_aermon_ta_succes_if_strict(self): + def test_aermon_ta_succes_if_not_strict(self): """Get ta does not fail with Omon if not strict.""" self.variables_info.strict = False var = self.variables_info.get_variable('Omon', 'ta') diff --git a/tests/integration/preprocessor/_ancillary_vars/test_add_fx_variables.py b/tests/integration/preprocessor/_ancillary_vars/test_add_fx_variables.py index 7ac756d50a..25776a26a8 100644 --- a/tests/integration/preprocessor/_ancillary_vars/test_add_fx_variables.py +++ b/tests/integration/preprocessor/_ancillary_vars/test_add_fx_variables.py @@ -74,12 +74,14 @@ def test_add_cell_measure_area(self, tmp_path): """Test add area fx variables as cell measures.""" fx_vars = { 'areacella': { + 'cmor_name': 'areacella', 'short_name': 'areacella', 'project': 'CMIP6', 'dataset': 'EC-Earth3', 'mip': 'fx', 'frequency': 'fx'}, 'areacello': { + 'cmor_name': 'areacello', 'short_name': 'areacello', 'project': 'CMIP6', 'dataset': 'EC-Earth3', @@ -104,6 +106,7 @@ def test_add_cell_measure_volume(self, tmp_path): """Test add volume as cell measure.""" fx_vars = { 'volcello': { + 'cmor_name': 'volcello', 'short_name': 'volcello', 'project': 'CMIP6', 'dataset': 'EC-Earth3', @@ -143,6 +146,7 @@ def test_add_ancillary_vars(self, tmp_path): iris.save(self.fx_area, fx_file) fx_vars = { 'sftlf': { + 'cmor_name': 'sftlf', 'short_name': 'sftlf', 'project': 'CMIP6', 'dataset': 'EC-Earth3', @@ -174,6 +178,7 @@ def test_wrong_time_frequency(self, tmp_path): iris.save(volume_cube, fx_file) fx_vars = { 'volcello': { + 'cmor_name': 'volcello', 'short_name': 'volcello', 'project': 'CMIP6', 'dataset': 'EC-Earth3', diff --git a/tests/integration/preprocessor/_derive/test_interface.py b/tests/integration/preprocessor/_derive/test_interface.py index 14ea1d6c9a..c1aafb44be 100644 --- a/tests/integration/preprocessor/_derive/test_interface.py +++ b/tests/integration/preprocessor/_derive/test_interface.py @@ -47,7 +47,10 @@ def assert_derived_var_calc_called_once_with(*args): def test_check_units_none(mock_cubes): """Test units after derivation if derivation scripts returns None.""" mock_all_derived_variables(None) - cube = derive(mock_cubes, SHORT_NAME, mock.sentinel.long_name, + cube = derive(mock_cubes, + SHORT_NAME, + SHORT_NAME, + mock.sentinel.long_name, mock.sentinel.units, standard_name=mock.sentinel.standard_name) assert_derived_var_calc_called_once_with(mock_cubes) @@ -63,7 +66,11 @@ def test_check_units_none(mock_cubes): def test_check_units_equal(mock_cubes): """Test units after derivation if derivation scripts returns None.""" mock_all_derived_variables(Unit('kg m2 s-2')) - cube = derive(mock_cubes, SHORT_NAME, mock.sentinel.long_name, 'J', + cube = derive(mock_cubes, + SHORT_NAME, + SHORT_NAME, + mock.sentinel.long_name, + 'J', standard_name=mock.sentinel.standard_name) assert_derived_var_calc_called_once_with(mock_cubes) assert cube.units == Unit('J') @@ -78,7 +85,11 @@ def test_check_units_equal(mock_cubes): def test_check_units_nounit(mock_cubes): """Test units after derivation if derivation scripts returns None.""" mock_all_derived_variables(Unit('no unit')) - cube = derive(mock_cubes, SHORT_NAME, mock.sentinel.long_name, 'J', + cube = derive(mock_cubes, + SHORT_NAME, + SHORT_NAME, + mock.sentinel.long_name, + 'J', standard_name=mock.sentinel.standard_name) assert_derived_var_calc_called_once_with(mock_cubes) assert cube.units == Unit('J') @@ -96,7 +107,11 @@ def test_check_units_nounit(mock_cubes): def test_check_units_unknown(mock_cubes): """Test units after derivation if derivation scripts returns None.""" mock_all_derived_variables(Unit('unknown')) - cube = derive(mock_cubes, SHORT_NAME, mock.sentinel.long_name, 'J', + cube = derive(mock_cubes, + SHORT_NAME, + SHORT_NAME, + mock.sentinel.long_name, + 'J', standard_name=mock.sentinel.standard_name) assert_derived_var_calc_called_once_with(mock_cubes) assert cube.units == Unit('J') @@ -114,7 +129,11 @@ def test_check_units_unknown(mock_cubes): def test_check_units_convertible(mock_cubes): """Test units after derivation if derivation scripts returns None.""" mock_all_derived_variables(Unit('kg s-1')) - cube = derive(mock_cubes, SHORT_NAME, mock.sentinel.long_name, 'g yr-1', + cube = derive(mock_cubes, + SHORT_NAME, + SHORT_NAME, + mock.sentinel.long_name, + 'g yr-1', standard_name=mock.sentinel.standard_name) assert_derived_var_calc_called_once_with(mock_cubes) cube.convert_units.assert_called_once_with('g yr-1') @@ -129,12 +148,15 @@ def test_check_units_fail(mock_cubes): """Test units after derivation if derivation scripts returns None.""" mock_all_derived_variables(Unit('kg')) with pytest.raises(ValueError) as err: - derive(mock_cubes, SHORT_NAME, mock.sentinel.long_name, 'm', + derive(mock_cubes, + SHORT_NAME, + SHORT_NAME, + mock.sentinel.long_name, + 'm', standard_name=mock.sentinel.standard_name) assert str(err.value) == ( "Units 'kg' after executing derivation script of 'short_name' cannot " - "be converted to target units 'm'" - ) + "be converted to target units 'm'") _derive.logger.warning.assert_not_called() @@ -144,10 +166,10 @@ def test_get_required(): reference = [ { - 'short_name': 'rsdscs', + 'cmor_name': 'rsdscs', }, { - 'short_name': 'rsuscs', + 'cmor_name': 'rsuscs', }, ] @@ -159,8 +181,13 @@ def test_get_required_with_fx(): variables = get_required('ohc', 'CMIP5') reference = [ - {'short_name': 'thetao'}, - {'short_name': 'volcello', 'mip': 'fx'}, + { + 'cmor_name': 'thetao' + }, + { + 'cmor_name': 'volcello', + 'mip': 'fx' + }, ] assert variables == reference @@ -183,7 +210,8 @@ def test_derive_nonstandard_nofx(): cubes = CubeList([rsdscs, rsuscs]) - alb = derive(cubes, short_name, long_name, units, standard_name) + alb = derive(cubes, short_name, short_name, long_name, units, + standard_name) assert alb.var_name == short_name assert alb.long_name == long_name @@ -198,7 +226,7 @@ def test_derive_noop(): alb.long_name = 'albedo at the surface' alb.units = 1 - cube = derive([alb], alb.var_name, alb.long_name, alb.units) + cube = derive([alb], alb.var_name, alb.var_name, alb.long_name, alb.units) assert cube is alb @@ -221,6 +249,7 @@ def mock_calculate(_, cubes): derive( [ohc_cube], short_name, + short_name, long_name, units, ) diff --git a/tests/integration/preprocessor/_mask/test_mask.py b/tests/integration/preprocessor/_mask/test_mask.py index 4e2ef513f8..73f7c68201 100644 --- a/tests/integration/preprocessor/_mask/test_mask.py +++ b/tests/integration/preprocessor/_mask/test_mask.py @@ -62,6 +62,7 @@ def test_components_fx_var(self, tmp_path): iris.save(self.fx_mask, sftlf_file) fx_vars = { 'sftlf': { + 'cmor_name': 'sftlf', 'short_name': 'sftlf', 'project': 'CMIP6', 'dataset': 'EC-Earth3', @@ -85,6 +86,7 @@ def test_components_fx_var(self, tmp_path): iris.save(self.fx_mask, sftgif_file) fx_vars = { 'sftgif': { + 'cmor_name': 'sftgif', 'short_name': 'sftgif', 'project': 'CMIP6', 'dataset': 'EC-Earth3', @@ -110,6 +112,7 @@ def test_mask_landsea(self, tmp_path): iris.save(self.fx_mask, sftlf_file) fx_vars = { 'sftlf': { + 'cmor_name': 'sftlf', 'short_name': 'sftlf', 'project': 'CMIP6', 'dataset': 'EC-Earth3', @@ -200,6 +203,7 @@ def test_mask_landseaice(self, tmp_path): iris.save(self.fx_mask, sftgif_file) fx_vars = { 'sftgif': { + 'cmor_name': 'sftgif', 'short_name': 'sftgif', 'project': 'CMIP6', 'dataset': 'EC-Earth3', diff --git a/tests/integration/preprocessor/_regrid/test_get_file_levels.py b/tests/integration/preprocessor/_regrid/test_get_file_levels.py index 128a074453..81d199cb6d 100644 --- a/tests/integration/preprocessor/_regrid/test_get_file_levels.py +++ b/tests/integration/preprocessor/_regrid/test_get_file_levels.py @@ -49,7 +49,7 @@ def test_get_coord(self): filename=self.path, project='CMIP6', dataset='dataset', - short_name='short_name', + cmor_name='cmor_name', mip='mip', frequency='mon', fix_dir='output_dir', diff --git a/tests/integration/test_recipe.py b/tests/integration/test_recipe.py index 81e3ef7720..b1962ca137 100644 --- a/tests/integration/test_recipe.py +++ b/tests/integration/test_recipe.py @@ -61,6 +61,7 @@ 'modeling_realm', 'preprocessor', 'project', + 'cmor_name', 'short_name', 'standard_name', 'start_year', @@ -125,7 +126,7 @@ def _get_default_settings_for_chl(fix_dir, save_filename): 'fix_file': { 'project': 'CMIP5', 'dataset': 'CanESM2', - 'short_name': 'chl', + 'cmor_name': 'chl', 'mip': 'Oyr', 'output_dir': fix_dir, }, @@ -133,7 +134,7 @@ def _get_default_settings_for_chl(fix_dir, save_filename): 'check_level': CheckLevels.DEFAULT, 'project': 'CMIP5', 'dataset': 'CanESM2', - 'short_name': 'chl', + 'cmor_name': 'chl', 'mip': 'Oyr', 'frequency': 'yr', }, @@ -141,7 +142,7 @@ def _get_default_settings_for_chl(fix_dir, save_filename): 'check_level': CheckLevels.DEFAULT, 'project': 'CMIP5', 'dataset': 'CanESM2', - 'short_name': 'chl', + 'cmor_name': 'chl', 'mip': 'Oyr', 'frequency': 'yr', }, @@ -153,14 +154,14 @@ def _get_default_settings_for_chl(fix_dir, save_filename): 'check_level': CheckLevels.DEFAULT, 'cmor_table': 'CMIP5', 'mip': 'Oyr', - 'short_name': 'chl', + 'cmor_name': 'chl', 'frequency': 'yr', }, 'cmor_check_data': { 'check_level': CheckLevels.DEFAULT, 'cmor_table': 'CMIP5', 'mip': 'Oyr', - 'short_name': 'chl', + 'cmor_name': 'chl', 'frequency': 'yr', }, 'add_fx_variables': { @@ -251,15 +252,15 @@ def find_files(_, filenames): @pytest.fixture def patched_tas_derivation(monkeypatch): - def get_required(short_name, _): - if short_name != 'tas': + def get_required(cmor_name, _): + if cmor_name != 'tas': assert False required = [ { - 'short_name': 'pr' + 'cmor_name': 'pr' }, { - 'short_name': 'areacella', + 'cmor_name': 'areacella', 'mip': 'fx', 'optional': True }, @@ -320,7 +321,7 @@ def test_recipe_no_datasets(tmp_path, config_user): "{'preprocessor': 'preprocessor_name', 'project': 'CMIP5'," " 'mip': 'Amon', 'exp': 'historical', 'ensemble': 'r1i1p1'" ", 'start_year': 1999, 'end_year': 2002, 'variable_group':" - " 'ta', 'short_name': 'ta', 'diagnostic': " + " 'ta', 'cmor_name': 'ta', 'diagnostic': " "'diagnostic_name'} Exiting.") with pytest.raises(RecipeError) as exc: get_recipe(tmp_path, content, config_user) @@ -379,7 +380,7 @@ def test_simple_recipe(tmp_path, patched_datafinder, config_user): for variable in variables: for key in MANDATORY_DATASET_KEYS: assert key in variable and variable[key] - assert variable_name == variable['short_name'] + assert variable_name == variable['cmor_name'] # Check that the correct tasks have been created variables = recipe.diagnostics['diagnostic_name']['preprocessor_output'][ @@ -555,7 +556,7 @@ def test_default_fx_preprocessor(tmp_path, patched_datafinder, config_user): 'fix_file': { 'project': 'CMIP5', 'dataset': 'CanESM2', - 'short_name': 'sftlf', + 'cmor_name': 'sftlf', 'mip': 'fx', 'output_dir': fix_dir, }, @@ -563,7 +564,7 @@ def test_default_fx_preprocessor(tmp_path, patched_datafinder, config_user): 'check_level': CheckLevels.DEFAULT, 'project': 'CMIP5', 'dataset': 'CanESM2', - 'short_name': 'sftlf', + 'cmor_name': 'sftlf', 'mip': 'fx', 'frequency': 'fx', }, @@ -571,7 +572,7 @@ def test_default_fx_preprocessor(tmp_path, patched_datafinder, config_user): 'check_level': CheckLevels.DEFAULT, 'project': 'CMIP5', 'dataset': 'CanESM2', - 'short_name': 'sftlf', + 'cmor_name': 'sftlf', 'mip': 'fx', 'frequency': 'fx', }, @@ -579,14 +580,14 @@ def test_default_fx_preprocessor(tmp_path, patched_datafinder, config_user): 'check_level': CheckLevels.DEFAULT, 'cmor_table': 'CMIP5', 'mip': 'fx', - 'short_name': 'sftlf', + 'cmor_name': 'sftlf', 'frequency': 'fx', }, 'cmor_check_data': { 'check_level': CheckLevels.DEFAULT, 'cmor_table': 'CMIP5', 'mip': 'fx', - 'short_name': 'sftlf', + 'cmor_name': 'sftlf', 'frequency': 'fx', }, 'add_fx_variables': { @@ -628,7 +629,7 @@ def test_empty_variable(tmp_path, patched_datafinder, config_user): task = recipe.tasks.pop() assert len(task.products) == 1 product = task.products.pop() - assert product.attributes['short_name'] == 'pr' + assert product.attributes['cmor_name'] == 'pr' assert product.attributes['dataset'] == 'CanESM2' @@ -657,6 +658,7 @@ def test_cmip3_variable_autocomplete(tmp_path, patched_datafinder, variable = recipe.diagnostics['test']['preprocessor_output']['zg'][0] reference = { + 'cmor_name': 'zg', 'dataset': 'bccr_bcm2_0', 'diagnostic': 'test', 'end_year': 2001, @@ -701,6 +703,7 @@ def test_cmip5_variable_autocomplete(tmp_path, patched_datafinder, variable = recipe.diagnostics['test']['preprocessor_output']['pr'][0] reference = { + 'cmor_name': 'pr', 'dataset': 'CanESM2', 'diagnostic': 'test', 'end_year': 2001, @@ -713,7 +716,6 @@ def test_cmip5_variable_autocomplete(tmp_path, patched_datafinder, 'modeling_realm': ['atmos'], 'preprocessor': 'default', 'project': 'CMIP5', - 'short_name': 'pr', 'standard_name': 'precipitation_flux', 'start_year': 2000, 'units': 'kg m-2 s-1', @@ -747,6 +749,7 @@ def test_cmip6_variable_autocomplete(tmp_path, patched_datafinder, reference = { 'activity': 'CMIP', + 'cmor_name': 'pr', 'dataset': 'HadGEM3-GC31-LL', 'diagnostic': 'test', 'end_year': 2001, @@ -760,7 +763,6 @@ def test_cmip6_variable_autocomplete(tmp_path, patched_datafinder, 'modeling_realm': ['atmos'], 'preprocessor': 'default', 'project': 'CMIP6', - 'short_name': 'pr', 'standard_name': 'precipitation_flux', 'start_year': 2000, 'units': 'kg m-2 s-1', @@ -799,6 +801,7 @@ def test_simple_cordex_recipe(tmp_path, patched_datafinder, config_user): 'tas_MOHC-HadGEM3-RA_evaluation_r1i1p1_v1_mon_1991-1993.nc') reference = { 'alias': 'MOHC-HadGEM3-RA', + 'cmor_name': 'tas', 'dataset': 'MOHC-HadGEM3-RA', 'diagnostic': 'test', 'domain': 'AFR-44', @@ -899,7 +902,7 @@ def test_reference_dataset(tmp_path, patched_datafinder, config_user, filename=reference.files[0], project='CMIP5', dataset='MPI-ESM-LR', - short_name='ta', + cmor_name='ta', mip='Amon', frequency='mon', fix_dir=fix_dir, @@ -962,7 +965,7 @@ def test_custom_preproc_order(tmp_path, patched_datafinder, config_user): diagnostic_name: variables: chl_default: &chl - short_name: chl + cmor_name: chl preprocessor: default project: CMIP5 mip: Oyr @@ -1059,13 +1062,13 @@ def test_derive(tmp_path, patched_datafinder, config_user): assert len(task.products) == 1 product = task.products.pop() assert 'derive' in product.settings - assert product.attributes['short_name'] == 'toz' + assert product.attributes['cmor_name'] == 'toz' assert product.files ps_product = next(p for a in task.ancestors for p in a.products - if p.attributes['short_name'] == 'ps') + if p.attributes['cmor_name'] == 'ps') tro3_product = next(p for a in task.ancestors for p in a.products - if p.attributes['short_name'] == 'tro3') + if p.attributes['cmor_name'] == 'tro3') assert ps_product.filename in product.files assert tro3_product.filename in product.files @@ -1103,13 +1106,13 @@ def test_derive_not_needed(tmp_path, patched_datafinder, config_user): # Check product content of tasks assert len(task.products) == 1 product = task.products.pop() - assert product.attributes['short_name'] == 'toz' + assert product.attributes['cmor_name'] == 'toz' assert 'derive' in product.settings assert len(ancestor.products) == 1 ancestor_product = ancestor.products.pop() assert ancestor_product.filename in product.files - assert ancestor_product.attributes['short_name'] == 'toz' + assert ancestor_product.attributes['cmor_name'] == 'toz' assert 'derive' not in ancestor_product.settings # Check that fixes are applied just once @@ -1152,7 +1155,7 @@ def test_derive_with_fx_ohc(tmp_path, patched_datafinder, config_user): assert len(task.products) == 3 for product in task.products: assert 'derive' in product.settings - assert product.attributes['short_name'] == 'ohc' + assert product.attributes['cmor_name'] == 'ohc' all_product_files.extend(product.files) # Check ancestors @@ -1162,10 +1165,10 @@ def test_derive_with_fx_ohc(tmp_path, patched_datafinder, config_user): assert task.ancestors[1].name == ( 'diagnostic_name/ohc_derive_input_volcello') for ancestor_product in task.ancestors[0].products: - assert ancestor_product.attributes['short_name'] == 'thetao' + assert ancestor_product.attributes['cmor_name'] == 'thetao' assert ancestor_product.filename in all_product_files for ancestor_product in task.ancestors[1].products: - assert ancestor_product.attributes['short_name'] == 'volcello' + assert ancestor_product.attributes['cmor_name'] == 'volcello' if ancestor_product.attributes['project'] == 'CMIP6': assert ancestor_product.attributes['mip'] == 'Ofx' else: @@ -1233,7 +1236,7 @@ def test_derive_with_optional_var(tmp_path, patched_datafinder, assert len(task.products) == 3 for product in task.products: assert 'derive' in product.settings - assert product.attributes['short_name'] == 'tas' + assert product.attributes['cmor_name'] == 'tas' all_product_files.extend(product.files) # Check ancestors @@ -1242,10 +1245,10 @@ def test_derive_with_optional_var(tmp_path, patched_datafinder, assert task.ancestors[1].name == ( 'diagnostic_name/tas_derive_input_areacella') for ancestor_product in task.ancestors[0].products: - assert ancestor_product.attributes['short_name'] == 'pr' + assert ancestor_product.attributes['cmor_name'] == 'pr' assert ancestor_product.filename in all_product_files for ancestor_product in task.ancestors[1].products: - assert ancestor_product.attributes['short_name'] == 'areacella' + assert ancestor_product.attributes['cmor_name'] == 'areacella' assert ancestor_product.filename in all_product_files @@ -1283,14 +1286,14 @@ def test_derive_with_optional_var_nodata(tmp_path, patched_failing_datafinder, assert len(task.products) == 3 for product in task.products: assert 'derive' in product.settings - assert product.attributes['short_name'] == 'tas' + assert product.attributes['cmor_name'] == 'tas' all_product_files.extend(product.files) # Check ancestors assert len(task.ancestors) == 1 assert task.ancestors[0].name == ('diagnostic_name/tas_derive_input_pr') for ancestor_product in task.ancestors[0].products: - assert ancestor_product.attributes['short_name'] == 'pr' + assert ancestor_product.attributes['cmor_name'] == 'pr' assert ancestor_product.filename in all_product_files @@ -1936,15 +1939,15 @@ def test_user_defined_fxlist(tmp_path, patched_datafinder, config_user): landmask: mask_landsea: mask_out: sea - fx_variables: [{'short_name': 'sftlf', 'exp': 'piControl'}] + fx_variables: [{'cmor_name': 'sftlf', 'exp': 'piControl'}] mask_landseaice: mask_out: sea - fx_variables: [{'short_name': 'sftgif', 'exp': 'piControl'}] + fx_variables: [{'cmor_name': 'sftgif', 'exp': 'piControl'}] volume_statistics: operator: mean area_statistics: operator: mean - fx_variables: [{'short_name': 'areacello', 'mip': 'fx', + fx_variables: [{'cmor_name': 'areacello', 'mip': 'fx', 'exp': 'piControl'}] diagnostics: diagnostic_name: diff --git a/tests/unit/cmor/test_fix.py b/tests/unit/cmor/test_fix.py index 341f549b23..dc4a28dd30 100644 --- a/tests/unit/cmor/test_fix.py +++ b/tests/unit/cmor/test_fix.py @@ -21,7 +21,7 @@ def test_fix(self): return_value=[self.mock_fix]): file_returned = fix_file( file='filename', - short_name='short_name', + cmor_name='cmor_name', project='project', dataset='model', mip='mip', @@ -36,7 +36,7 @@ def test_nofix(self): return_value=[]): file_returned = fix_file( file='filename', - short_name='short_name', + cmor_name='cmor_name', project='project', dataset='model', mip='mip', @@ -93,9 +93,9 @@ def setUp(self): self.check_metadata = self.checker.return_value.check_metadata @staticmethod - def _create_mock_cube(var_name='short_name'): + def _create_mock_cube(short_name='short_name'): cube = Mock() - cube.var_name = var_name + cube.var_name = short_name cube.attributes = {'source_file': 'source_file'} return cube @@ -106,98 +106,118 @@ def test_fix(self): return_value=[self.mock_fix]): with patch('esmvalcore.cmor.fix._get_cmor_checker', return_value=self.checker): - cube_returned = fix_metadata( - cubes=[self.cube], - short_name='short_name', - project='project', - dataset='model', - mip='mip', - )[0] - self.checker.assert_called_once_with(self.intermediate_cube) - self.check_metadata.assert_called_once_with() - assert cube_returned is not self.cube - assert cube_returned is not self.intermediate_cube - assert cube_returned is self.fixed_cube + with patch('esmvalcore.cmor.fix.get_var_info', + return_value=Mock()): + cube_returned = fix_metadata( + cubes=[self.cube], + cmor_name='cmor_name', + project='project', + dataset='model', + mip='mip', + )[0] + self.checker.assert_called_once_with(self.intermediate_cube) + self.check_metadata.assert_called_once_with() + assert cube_returned is not self.cube + assert cube_returned is not self.intermediate_cube + assert cube_returned is self.fixed_cube def test_nofix(self): """Check that the same cube is returned if no fix is available.""" self.check_metadata.side_effect = lambda: self.cube + var_info = Mock() + var_info.short_name = 'short_name' with patch('esmvalcore.cmor._fixes.fix.Fix.get_fixes', return_value=[]): with patch('esmvalcore.cmor.fix._get_cmor_checker', return_value=self.checker): - cube_returned = fix_metadata( - cubes=[self.cube], - short_name='short_name', - project='project', - dataset='model', - mip='mip', - )[0] - self.checker.assert_called_once_with(self.cube) - self.check_metadata.assert_called_once_with() - assert cube_returned is self.cube - assert cube_returned is not self.intermediate_cube - assert cube_returned is not self.fixed_cube + with patch('esmvalcore.cmor.fix.get_var_info', + return_value=var_info): + cube_returned = fix_metadata( + cubes=[self.cube], + cmor_name='cmor_name', + project='project', + dataset='model', + mip='mip', + )[0] + self.checker.assert_called_once_with(self.cube) + self.check_metadata.assert_called_once_with() + assert cube_returned is self.cube + assert cube_returned is not self.intermediate_cube + assert cube_returned is not self.fixed_cube def test_select_var(self): """Check that the same cube is returned if no fix is available.""" self.check_metadata.side_effect = lambda: self.cube + var_info = Mock() + var_info.short_name = 'short_name' with patch('esmvalcore.cmor._fixes.fix.Fix.get_fixes', return_value=[]): with patch('esmvalcore.cmor.fix._get_cmor_checker', return_value=self.checker): - cube_returned = fix_metadata( - cubes=[self.cube, - self._create_mock_cube('extra')], - short_name='short_name', - project='CMIP6', - dataset='model', - mip='mip', - )[0] - self.checker.assert_called_once_with(self.cube) - self.check_metadata.assert_called_once_with() - assert cube_returned is self.cube + with patch('esmvalcore.cmor.fix.get_var_info', + return_value=var_info): + cube_returned = fix_metadata( + cubes=[self.cube, + self._create_mock_cube('extra')], + cmor_name='cmor_name', + project='CMIP6', + dataset='model', + mip='mip', + )[0] + self.checker.assert_called_once_with(self.cube) + self.check_metadata.assert_called_once_with() + assert cube_returned is self.cube def test_select_var_failed_if_bad_var_name(self): """Check that the same cube is returned if no fix is available.""" + var_info = Mock() + var_info.short_name = 'short_name' with patch('esmvalcore.cmor._fixes.fix.Fix.get_fixes', return_value=[]): - with self.assertRaises(ValueError): - fix_metadata( - cubes=[ - self._create_mock_cube('not_me'), - self._create_mock_cube('me_neither') - ], - short_name='short_name', - project='CMIP6', - dataset='model', - mip='mip', - ) + with patch('esmvalcore.cmor.fix.get_var_info', + return_value=var_info): + with self.assertRaises(ValueError): + fix_metadata( + cubes=[ + self._create_mock_cube('not_me'), + self._create_mock_cube('me_neither') + ], + cmor_name='cmor_name', + project='CMIP6', + dataset='model', + mip='mip', + ) def test_cmor_checker_called(self): """Check that the cmor check is done.""" checker = Mock() checker.return_value = Mock() + var_info = Mock() + var_info.cmor_name = 'cmor_name' + var_info.short_name = 'short_name' with patch('esmvalcore.cmor._fixes.fix.Fix.get_fixes', return_value=[]): with patch('esmvalcore.cmor.fix._get_cmor_checker', return_value=checker) as get_mock: - fix_metadata( - cubes=[self.cube], - short_name='short_name', - project='CMIP6', - dataset='dataset', - mip='mip', - frequency='frequency', - ) - get_mock.assert_called_once_with( - automatic_fixes=True, - fail_on_error=False, - frequency='frequency', - mip='mip', - short_name='short_name', - table='CMIP6', - check_level=CheckLevels.DEFAULT,) + with patch('esmvalcore.cmor.fix.get_var_info', + return_value=var_info): + fix_metadata( + cubes=[self.cube], + cmor_name='cmor_name', + project='CMIP6', + dataset='dataset', + mip='mip', + frequency='frequency', + ) + get_mock.assert_called_once_with( + automatic_fixes=True, + fail_on_error=False, + frequency='frequency', + mip='mip', + cmor_name='cmor_name', + table='CMIP6', + check_level=CheckLevels.DEFAULT, + ) checker.assert_called_once_with(self.cube) checker.return_value.check_metadata.assert_called_once_with() @@ -223,7 +243,7 @@ def test_fix(self): return_value=self.checker): cube_returned = fix_data( self.cube, - short_name='short_name', + cmor_name='cmor_name', project='project', dataset='model', mip='mip', @@ -243,16 +263,16 @@ def test_nofix(self): return_value=self.checker): cube_returned = fix_data( self.cube, - short_name='short_name', + cmor_name='cmor_name', project='CMIP6', dataset='model', mip='mip', ) - self.checker.assert_called_once_with(self.cube) - self.check_data.assert_called_once_with() - assert cube_returned is self.cube - assert cube_returned is not self.intermediate_cube - assert cube_returned is not self.fixed_cube + self.checker.assert_called_once_with(self.cube) + self.check_data.assert_called_once_with() + assert cube_returned is self.cube + assert cube_returned is not self.intermediate_cube + assert cube_returned is not self.fixed_cube def test_cmor_checker_called(self): """Check that the cmor check is done.""" @@ -262,7 +282,7 @@ def test_cmor_checker_called(self): return_value=[]): with patch('esmvalcore.cmor.fix._get_cmor_checker', return_value=checker) as get_mock: - fix_data(self.cube, 'short_name', 'CMIP6', 'model', 'mip', + fix_data(self.cube, 'cmor_name', 'CMIP6', 'model', 'mip', 'frequency') get_mock.assert_called_once_with( table='CMIP6', @@ -271,7 +291,7 @@ def test_cmor_checker_called(self): fail_on_error=False, frequency='frequency', mip='mip', - short_name='short_name', + cmor_name='cmor_name', ) checker.assert_called_once_with(self.cube) checker.return_value.check_data.assert_called_once_with() diff --git a/tests/unit/cmor/test_table.py b/tests/unit/cmor/test_table.py index 32239f7a96..424c25faf8 100644 --- a/tests/unit/cmor/test_table.py +++ b/tests/unit/cmor/test_table.py @@ -16,7 +16,7 @@ def test_constructor(self): """Test basic constructor.""" info = VariableInfo('table_type', 'var') self.assertEqual('table_type', info.table_type) - self.assertEqual('var', info.short_name) + self.assertEqual('var', info.cmor_name) def test_read_empty_dictionary(self): """Test read empty dict.""" @@ -24,6 +24,12 @@ def test_read_empty_dictionary(self): info.read_json({}, '') self.assertEqual('', info.standard_name) + def test_read_short_name(self): + """Test out_name.""" + info = VariableInfo('table_type', 'var') + info.read_json({'out_name': self.value}, '') + self.assertEqual(info.short_name, self.value) + def test_read_standard_name(self): """Test standard_name.""" info = VariableInfo('table_type', 'var') diff --git a/tests/unit/preprocessor/_derive/test_toz.py b/tests/unit/preprocessor/_derive/test_toz.py index 262deab1e0..931670571a 100644 --- a/tests/unit/preprocessor/_derive/test_toz.py +++ b/tests/unit/preprocessor/_derive/test_toz.py @@ -73,9 +73,9 @@ def test_toz_calculate_unmasked_cubes(unmasked_cubes): @pytest.mark.parametrize('project,out', [ - ('CMIP5', [{'short_name': 'tro3'}, {'short_name': 'ps'}]), - ('TEST', [{'short_name': 'tro3'}, {'short_name': 'ps'}]), - ('CMIP6', [{'short_name': 'o3'}, {'short_name': 'ps'}]), + ('CMIP5', [{'cmor_name': 'tro3'}, {'cmor_name': 'ps'}]), + ('TEST', [{'cmor_name': 'tro3'}, {'cmor_name': 'ps'}]), + ('CMIP6', [{'cmor_name': 'o3'}, {'cmor_name': 'ps'}]), ]) def test_toz_required(project, out): """Test function ``required``."""