diff --git a/doc/quickstart/configure.rst b/doc/quickstart/configure.rst index d2d9b6498f..c95c62c55b 100644 --- a/doc/quickstart/configure.rst +++ b/doc/quickstart/configure.rst @@ -47,14 +47,6 @@ with explanations in a commented line above each option: .. code-block:: yaml - # Diagnostics create plots? [true]/false - # turning it off will turn off graphical output from diagnostic - write_plots: true - - # Diagnostics write NetCDF files? [true]/false - # turning it off will turn off netCDF output from diagnostic - write_netcdf: true - # Set the console log level debug, [info], warning, error # for much more information printed to screen set log_level: debug log_level: info @@ -117,19 +109,14 @@ with explanations in a commented line above each option: drs: CMIP5: default -Most of these settings are fairly self-explanatory, e.g.: - -.. code-block:: yaml - - # Diagnostics create plots? [true]/false - write_plots: true - # Diagnostics write NetCDF files? [true]/false - write_netcdf: true +.. + DEPRECATED: remove in v2.4 -The ``write_plots`` setting is used to inform ESMValTool diagnostics about your -preference for creating figures. Similarly, the ``write_netcdf`` setting is a -boolean which turns on or off the writing of netCDF files by the diagnostic -scripts. +There used to be a setting ``write_plots`` and ``write_netcdf`` +in the config user file, but these have been deprecated since ESMValCore v2.2 and +will be removed in v2.4, because only some diagnostic scripts supported these settings. +For those diagnostic scripts that do support these settings, they can now be configured +in the diagnostic script section of the recipe. .. code-block:: yaml diff --git a/doc/quickstart/output.rst b/doc/quickstart/output.rst index fbe55086c1..dbc62a1946 100644 --- a/doc/quickstart/output.rst +++ b/doc/quickstart/output.rst @@ -81,7 +81,7 @@ will produce a unique settings.yml file. The settings.yml file passes several global level keys to diagnostic scripts. This includes several flags from the config-user.yml file (such as -'write_netcdf', 'write_plots', etc...), several paths which are specific to the +'log_level'), several paths which are specific to the diagnostic being run (such as 'plot_dir' and 'run_dir') and the location on disk of the metadata.yml file (described below). @@ -97,8 +97,6 @@ disk of the metadata.yml file (described below). script: Scalar_timeseries version: 2.0a1 work_dir: [...]recipe_ocean_bgc_20190118_134855/work/diag_timeseries_scalars/Scalar_timeseries - write_netcdf: true - write_plots: true The first item in the settings file will be a list of `Metadata.yml`_ files. There is a metadata.yml file generated for each field in each diagnostic. @@ -146,5 +144,5 @@ As you can see, this is effectively a dictionary with several items including data paths, metadata and other information. There are several tools available in python which are built to read and parse -these files. The tools are avaialbe in the shared directory in the diagnostics +these files. The tools are available in the shared directory in the diagnostics directory. diff --git a/esmvalcore/_config.py b/esmvalcore/_config.py index 587552867a..c560777f35 100644 --- a/esmvalcore/_config.py +++ b/esmvalcore/_config.py @@ -2,6 +2,7 @@ import datetime import logging import os +import warnings from pathlib import Path import yaml @@ -42,15 +43,35 @@ def read_config_user_file(config_file, folder_name, options=None): with open(config_file, 'r') as file: cfg = yaml.safe_load(file) + # DEPRECATED: remove in v2.4 + for setting in ('write_plots', 'write_netcdf'): + if setting in cfg: + msg = ( + f"Using '{setting}' in {config_file} is deprecated and will " + "be removed in ESMValCore version 2.4. For diagnostics " + "that support this setting, it should be set in the " + "diagnostic script section of the recipe instead. " + f"Remove the setting from {config_file} to get rid of this " + "warning message.") + print(f"Warning: {msg}") + warnings.warn(DeprecationWarning(msg)) + if options is None: options = dict() for key, value in options.items(): cfg[key] = value + # DEPRECATED: remove in v2.4 + if key in ('write_plots', 'write_netcdf'): + msg = ( + f"Setting '{key}' from the command line is deprecated and " + "will be removed in ESMValCore version 2.4. For diagnostics " + "that support this setting, it should be set in the " + "diagnostic script section of the recipe instead.") + print(f"Warning: {msg}") + warnings.warn(DeprecationWarning(msg)) # set defaults defaults = { - 'write_plots': True, - 'write_netcdf': True, 'compress_netcdf': False, 'exit_on_warning': False, 'output_file_type': 'png', @@ -63,6 +84,9 @@ def read_config_user_file(config_file, folder_name, options=None): 'profile_diagnostic': False, 'config_developer_file': None, 'drs': {}, + # DEPRECATED: remove default settings below in v2.4 + 'write_plots': True, + 'write_netcdf': True, } for key in defaults: diff --git a/esmvalcore/_recipe.py b/esmvalcore/_recipe.py index 4d62299c4e..a368c123fe 100644 --- a/esmvalcore/_recipe.py +++ b/esmvalcore/_recipe.py @@ -1219,13 +1219,20 @@ def _initialize_scripts(self, diagnostic_name, raw_scripts, for key in ( 'output_file_type', 'log_level', - 'write_plots', - 'write_netcdf', 'profile_diagnostic', 'auxiliary_data_dir', ): settings[key] = self._cfg[key] + # Add deprecated settings from configuration file + # DEPRECATED: remove in v2.4 + for key in ( + 'write_plots', + 'write_netcdf', + ): + if key not in settings and key in self._cfg: + settings[key] = self._cfg[key] + scripts[script_name] = { 'script': script, 'output_dir': settings['work_dir'], diff --git a/esmvalcore/_task.py b/esmvalcore/_task.py index 8a306fdad8..2a10d00079 100644 --- a/esmvalcore/_task.py +++ b/esmvalcore/_task.py @@ -377,8 +377,6 @@ def _write_ncl_settings(self): 'work_dir', 'output_file_type', 'log_level', - 'write_plots', - 'write_netcdf', } settings = {'diag_script_info': {}, 'config_user_info': {}} for key, value in self.settings.items(): @@ -389,6 +387,13 @@ def _write_ncl_settings(self): else: settings[key] = value + # Still add deprecated keys to config_user_info to avoid + # crashing the diagnostic script that need this. + # DEPRECATED: remove in v2.4 + for key in ('write_plots', 'write_netcdf'): + if key in self.settings: + settings['config_user_info'][key] = self.settings[key] + write_ncl_settings(settings, filename) return filename @@ -560,9 +565,7 @@ def _collect_provenance(self): 'recipe', 'run_dir', 'version', - 'write_netcdf', 'write_ncl_interface', - 'write_plots', 'work_dir', ) attrs = { diff --git a/esmvalcore/config-user.yml b/esmvalcore/config-user.yml index 7974d8c0dd..79f3931014 100644 --- a/esmvalcore/config-user.yml +++ b/esmvalcore/config-user.yml @@ -3,11 +3,6 @@ ############################################################################### --- -# Diagnostics create plots? [true]/false -write_plots: true -# Diagnostics write NetCDF files? [true]/false -write_netcdf: true -# Set the console log level debug, [info], warning, error log_level: info # Exit on warning (only for NCL diagnostic scripts)? true/[false] exit_on_warning: false diff --git a/esmvalcore/experimental/config/_config_validators.py b/esmvalcore/experimental/config/_config_validators.py index 8910ef5e74..d83a26f331 100644 --- a/esmvalcore/experimental/config/_config_validators.py +++ b/esmvalcore/experimental/config/_config_validators.py @@ -251,10 +251,8 @@ def deprecate(func, variable, version: str = None): _validators = { # deprecate in 2.2.0 - 'write_plots': deprecate(validate_bool, 'write_plots', '2.2.0'), - 'write_netcdf': deprecate(validate_bool, 'write_netcdf', '2.2.0'), - 'output_file_type': deprecate(validate_string, 'output_file_type', - '2.2.0'), + 'write_plots': deprecate(validate_bool, 'write_plots', '2.4.0'), + 'write_netcdf': deprecate(validate_bool, 'write_netcdf', '2.4.0'), # From user config 'log_level': validate_string, @@ -268,6 +266,7 @@ def deprecate(func, variable, version: str = None): 'config_developer_file': validate_config_developer, 'profile_diagnostic': validate_bool, 'run_diagnostic': validate_bool, + 'output_file_type': validate_string, # From CLI "skip-nonexistent": validate_bool, diff --git a/tests/integration/test_recipe.py b/tests/integration/test_recipe.py index 7b1c04eb1b..082b264be5 100644 --- a/tests/integration/test_recipe.py +++ b/tests/integration/test_recipe.py @@ -65,7 +65,6 @@ def config_user(tmp_path): filename = write_config_user_file(tmp_path) cfg = esmvalcore._config.read_config_user_file(filename, 'recipe_test', {}) cfg['synda_download'] = False - cfg['output_file_type'] = 'png' cfg['check_level'] = CheckLevels.DEFAULT return cfg