diff --git a/docs/source/parameters.rst b/docs/source/parameters.rst index e204f310..738e09f1 100644 --- a/docs/source/parameters.rst +++ b/docs/source/parameters.rst @@ -15,3 +15,80 @@ See `this release's parameter defaults `_. + +Deprecated parameters +===================== + +The following parameters no longer perform any function: + :: + + "e3sm_to_cmip_environment_commands" + "ts_fmt" + "scratch" + "atmosphere_only" + "plot_names" + +Parameter checking & inferring -- for users +=========================================== + +There are two types of inferences, each with their own parameter in ``default.ini``: + +* ``infer_path_parameters``: infer paths that are not explicitly provided in the configuraiton file. Default is ``True``. +* ``infer_section_parameters``: infer subtask dependency names that are not explicitly provided in the configuration file. Default is ``True``. + +**Section inferences** + +For the ``climo``, ``ts``, ``e3sm_to_cmip``, and ``e3sm_diags`` tasks: + +* If ``subsection`` (the name of the subtask) is undefined, just use the value of ``grid``. + +For the ``e3sm_to_cmip`` task: + +* If ``ts_subsection`` (the name of the ``ts`` subtask that this ``e3sm_to_cmip`` subtask is dependent on) is undefined, assume it had the same name as this ``e3sm_to_cmip`` subtask. + +For the ``ilamb`` task: + +* If ``ts_land_subsection`` (the name of the ``ts`` land-specific subtask that this ``ilamb`` task is dependent on), assume it is ``land_monthly``. +* If ``e3sm_to_cmip_land_subsection`` (the name of the ``e3sm_to_cmip`` land-specific subtask that this ``ilamb`` task is dependent on), again assume it is ``land_monthly``. +* If we are not doing a ``land_only`` run and ``ts_atm_subsection`` (the name of the ``ts`` atm-specific subtask that this ``ilamb`` task is dependent on), assume it is ``atm_monthly_180x360_aave``. +* If we are not doing a ``land_only`` run and ``e3sm_to_cmip_atm_subsection`` (the name of the ``e3sm_to_cmip`` atm-specific subtask that this ``ilamb`` task is dependent on), again assume it is ``atm_monthly_180x360_aave``. + + +**Path inferences** + +For the ``e3sm_diags`` task: + +* If ``reference_data_path`` (the path to the reference data) is undefined, assume it is the ``diagnostics_base_path`` from Mache plus ``/observations/Atm/climatology/``. (So, it is important to change this for model-vs-model runs). + + +For the ``ilamb`` task: + +* If ``ilamb_obs`` (the path to observation data for ``ilamb``) is undefined, assume it is the ``diagnostics_base_path`` from Mache plus ``/ilamb_data``. + +**Required parameters, by e3sm_diags set** + +TODO: Insert main table from Confluence + +These parameters are required for all model-vs-model runs: ``diff_title``, ``ref_name``, ``short_ref_name``. + +TODO: Insert model-vs-model table from Confluence + +Parameter checking & inferring -- for developers +================================================ + +There are many parameter-handling functions. + +In ``utils.py``: + +* ``get_value_from_parameter``: check if parameter is in the configuration dictionary. If not, if inference is turned on (the default), then just use the value of ``second_choice_parameter``. If inferenceis turned off, raise a ``ParameterNotProvidedError``. Use this function if the backup option +* ``set_value_of_parameter_if_undefined``: check if parameter is in the configuration dictionary. If not, if inferenceis turned on (the default), then just set the parameter's value to the ``backup_option``. If inferenceis turned off, raise a ``ParameterNotProvidedError``. + +In ``e3sm_diags.py``: + +* ``check_parameter_defined``: check if parameter is in the configuration dictionary, and if not raise a ``ParameterNotProvidedError``. +* ``check_set_specific_parameter``: if any requested ``e3sm_diags`` sets require this parameter, make sure it is present. If not, raise a ``ParameterNotProvidedError``. +* ``check_parameters_for_bash``: use ``check_set_specific_parameter`` to check the existence of parameters that aren't used until the bash script. +* ``check_mvm_only_parameters_for_bash``: similar, but these are specifically parameters used for model-vs-model runs. Uses ``check_parameter_defined`` in addition to ``check_set_specific_parameter``. +* ``check_and_define_parameters``: make sure all parameters are defined, using ``utils.py get_value_from_parameter``, ``utils.py set_value_of_parameter_if_undefined``, and ``check_mvm_only_parameters_for_bash``. + +``check_parameters_for_bash`` can be run immediately for each subtask because it has very few conditions. Other checks are included in ``check_and_define_parameters`` later on in the code. \ No newline at end of file diff --git a/tests/integration/generated/test_min_case_deprecated_parameters_chrysalis.cfg b/tests/integration/generated/test_min_case_deprecated_parameters_chrysalis.cfg index 1d829d8c..77da5bd9 100644 --- a/tests/integration/generated/test_min_case_deprecated_parameters_chrysalis.cfg +++ b/tests/integration/generated/test_min_case_deprecated_parameters_chrysalis.cfg @@ -4,8 +4,8 @@ constraint = "" dry_run = True # Exlcusively testing with dry_run environment_commands = "" fail_on_dependency_skip = True -guess_path_parameters = False -guess_section_parameters = False +infer_path_parameters = False +infer_section_parameters = False input = /lcrc/group/e3sm2/ac.wlin//E3SMv3/v3.LR.historical_0051 input_subdir = archive/atm/hist mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc" diff --git a/tests/integration/generated/test_min_case_global_time_series_comprehensive_v3_setup_only_chrysalis.cfg b/tests/integration/generated/test_min_case_global_time_series_comprehensive_v3_setup_only_chrysalis.cfg index 5b0acf38..c7dbe1eb 100644 --- a/tests/integration/generated/test_min_case_global_time_series_comprehensive_v3_setup_only_chrysalis.cfg +++ b/tests/integration/generated/test_min_case_global_time_series_comprehensive_v3_setup_only_chrysalis.cfg @@ -4,8 +4,8 @@ constraint = "" dry_run = "False" environment_commands = "" fail_on_dependency_skip = True -guess_path_parameters = False -guess_section_parameters = False +infer_path_parameters = False +infer_section_parameters = False input = /lcrc/group/e3sm2/ac.wlin//E3SMv3/v3.LR.historical_0051 input_subdir = archive/atm/hist mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc" diff --git a/tests/integration/generated/test_min_case_nco_chrysalis.cfg b/tests/integration/generated/test_min_case_nco_chrysalis.cfg index db62c7ec..64010a9f 100644 --- a/tests/integration/generated/test_min_case_nco_chrysalis.cfg +++ b/tests/integration/generated/test_min_case_nco_chrysalis.cfg @@ -4,8 +4,8 @@ constraint = "" dry_run = "False" environment_commands = "" fail_on_dependency_skip = True -guess_path_parameters = False -guess_section_parameters = False +infer_path_parameters = False +infer_section_parameters = False input = /lcrc/group/e3sm2/ac.wlin//E3SMv3/v3.LR.historical_0051 input_subdir = archive/atm/hist mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc" diff --git a/tests/integration/generated/test_weekly_comprehensive_v3_chrysalis.cfg b/tests/integration/generated/test_weekly_comprehensive_v3_chrysalis.cfg index 8a9bda50..f7103d1b 100644 --- a/tests/integration/generated/test_weekly_comprehensive_v3_chrysalis.cfg +++ b/tests/integration/generated/test_weekly_comprehensive_v3_chrysalis.cfg @@ -4,8 +4,8 @@ constraint = "" dry_run = "False" environment_commands = "" fail_on_dependency_skip = True -guess_path_parameters = False -guess_section_parameters = False +infer_path_parameters = False +infer_section_parameters = False input = /lcrc/group/e3sm2/ac.wlin//E3SMv3/v3.LR.historical_0051 input_subdir = archive/atm/hist mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc" @@ -144,7 +144,7 @@ tc_obs = "/lcrc/group/e3sm/diagnostics/observations/Atm/tc-analysis/" # Reference paths reference_data_path = "/lcrc/group/e3sm/diagnostics/observations/Atm/climatology/" # mvo diurnal_cycle only - # NOTE: This is NOT the guess zppy would have made! + # NOTE: This is NOT the inference zppy would have made! dc_obs_climo = '/lcrc/group/e3sm/public_html/e3sm_diags_test_data/unit_test_complete_run/obs/climatology' # mvo streamflow only streamflow_obs_ts = "/lcrc/group/e3sm/diagnostics/observations/Atm/time-series/" diff --git a/tests/integration/template_min_case_deprecated_parameters.cfg b/tests/integration/template_min_case_deprecated_parameters.cfg index 16ff87e7..78ebf16c 100644 --- a/tests/integration/template_min_case_deprecated_parameters.cfg +++ b/tests/integration/template_min_case_deprecated_parameters.cfg @@ -4,8 +4,8 @@ constraint = "#expand constraint#" dry_run = True # Exlcusively testing with dry_run environment_commands = "#expand environment_commands#" fail_on_dependency_skip = True -guess_path_parameters = False -guess_section_parameters = False +infer_path_parameters = False +infer_section_parameters = False input = #expand user_input_v3#/E3SMv3/#expand case_name# input_subdir = archive/atm/hist mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc" diff --git a/tests/integration/template_min_case_global_time_series_comprehensive_v3_setup_only.cfg b/tests/integration/template_min_case_global_time_series_comprehensive_v3_setup_only.cfg index 0d8d9941..1bf1cc01 100644 --- a/tests/integration/template_min_case_global_time_series_comprehensive_v3_setup_only.cfg +++ b/tests/integration/template_min_case_global_time_series_comprehensive_v3_setup_only.cfg @@ -4,8 +4,8 @@ constraint = "#expand constraint#" dry_run = "#expand dry_run#" environment_commands = "#expand environment_commands#" fail_on_dependency_skip = True -guess_path_parameters = False -guess_section_parameters = False +infer_path_parameters = False +infer_section_parameters = False input = #expand user_input_v3#/E3SMv3/#expand case_name# input_subdir = archive/atm/hist mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc" diff --git a/tests/integration/template_min_case_nco.cfg b/tests/integration/template_min_case_nco.cfg index 8f224e7b..13057faa 100644 --- a/tests/integration/template_min_case_nco.cfg +++ b/tests/integration/template_min_case_nco.cfg @@ -4,8 +4,8 @@ constraint = "#expand constraint#" dry_run = "#expand dry_run#" environment_commands = "#expand environment_commands#" fail_on_dependency_skip = True -guess_path_parameters = False -guess_section_parameters = False +infer_path_parameters = False +infer_section_parameters = False input = #expand user_input_v3#/E3SMv3/#expand case_name# input_subdir = archive/atm/hist mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc" diff --git a/tests/integration/template_weekly_comprehensive_v3.cfg b/tests/integration/template_weekly_comprehensive_v3.cfg index 6127e601..3b4cc7ae 100644 --- a/tests/integration/template_weekly_comprehensive_v3.cfg +++ b/tests/integration/template_weekly_comprehensive_v3.cfg @@ -4,8 +4,8 @@ constraint = "#expand constraint#" dry_run = "#expand dry_run#" environment_commands = "#expand environment_commands#" fail_on_dependency_skip = True -guess_path_parameters = False -guess_section_parameters = False +infer_path_parameters = False +infer_section_parameters = False input = #expand user_input_v3#/E3SMv3/#expand case_name# input_subdir = archive/atm/hist mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc" @@ -144,7 +144,7 @@ tc_obs = "#expand diagnostics_base_path#/observations/Atm/tc-analysis/" # Reference paths reference_data_path = "#expand diagnostics_base_path#/observations/Atm/climatology/" # mvo diurnal_cycle only - # NOTE: This is NOT the guess zppy would have made! + # NOTE: This is NOT the inference zppy would have made! dc_obs_climo = '/lcrc/group/e3sm/public_html/e3sm_diags_test_data/unit_test_complete_run/obs/climatology' # mvo streamflow only streamflow_obs_ts = "#expand diagnostics_base_path#/observations/Atm/time-series/" diff --git a/tests/test_sections.py b/tests/test_sections.py index df49f4a9..9e50dd0d 100644 --- a/tests/test_sections.py +++ b/tests/test_sections.py @@ -76,8 +76,8 @@ def test_sections(): "fail_on_dependency_skip": False, "frequency": "monthly", "grid": "", - "guess_section_parameters": True, - "guess_path_parameters": True, + "infer_section_parameters": True, + "infer_path_parameters": True, "input": "INPUT", "input_files": "eam.h0", "input_subdir": "INPUT_SUBDIR", @@ -132,8 +132,8 @@ def test_sections(): "fail_on_dependency_skip": False, "frequency": "monthly", "grid": "", - "guess_section_parameters": True, - "guess_path_parameters": True, + "infer_section_parameters": True, + "infer_path_parameters": True, "input": "INPUT", "input_component": "", "input_files": "eam.h0", @@ -188,8 +188,8 @@ def test_sections(): "fail_on_dependency_skip": False, "frequency": "monthly", "grid": "", - "guess_section_parameters": True, - "guess_path_parameters": True, + "infer_section_parameters": True, + "infer_path_parameters": True, "input": "INPUT", "input_component": "", "input_files": "eam.h0", @@ -245,8 +245,8 @@ def test_subsections(): "fail_on_dependency_skip": False, "frequency": "monthly", "grid": "", - "guess_section_parameters": True, - "guess_path_parameters": True, + "infer_section_parameters": True, + "infer_path_parameters": True, "input": "INPUT", "input_files": "eam.h0", "input_subdir": "INPUT_SUBDIR", @@ -317,8 +317,8 @@ def test_subsections(): "fail_on_dependency_skip": False, "frequency": "monthly", "grid": "", - "guess_section_parameters": True, - "guess_path_parameters": True, + "infer_section_parameters": True, + "infer_path_parameters": True, "input": "INPUT", "input_component": "", "input_files": "eam.h0", @@ -358,8 +358,8 @@ def test_subsections(): "fail_on_dependency_skip": False, "frequency": "monthly", "grid": "", - "guess_section_parameters": True, - "guess_path_parameters": True, + "infer_section_parameters": True, + "infer_path_parameters": True, "input": "INPUT", "input_component": "", "input_files": "eam.h0", @@ -430,8 +430,8 @@ def test_subsections(): "fail_on_dependency_skip": False, "frequency": "monthly", "grid": "", - "guess_section_parameters": True, - "guess_path_parameters": True, + "infer_section_parameters": True, + "infer_path_parameters": True, "input": "INPUT", "input_component": "", "input_files": "eam.h0", @@ -468,8 +468,8 @@ def test_subsections(): "fail_on_dependency_skip": False, "frequency": "monthly", "grid": "", - "guess_section_parameters": True, - "guess_path_parameters": True, + "infer_section_parameters": True, + "infer_path_parameters": True, "input": "INPUT", "input_component": "", "input_files": "eam.h0", diff --git a/tests/test_zppy_e3sm_diags.py b/tests/test_zppy_e3sm_diags.py index e35c6a4d..f69f7cc4 100644 --- a/tests/test_zppy_e3sm_diags.py +++ b/tests/test_zppy_e3sm_diags.py @@ -7,11 +7,40 @@ add_ts_dependencies, check_and_define_parameters, check_mvm_only_parameters_for_bash, + check_parameter_defined, check_parameters_for_bash, + check_set_specific_parameter, ) from zppy.utils import ParameterNotProvidedError +def test_check_parameter_defined(): + c = {"a": 1, "b": 2, "c": ""} + check_parameter_defined(c, "a") + with pytest.raises(ParameterNotProvidedError): + check_parameter_defined(c, "c") + with pytest.raises(ParameterNotProvidedError): + check_parameter_defined(c, "d") + + +def test_check_set_specific_parameter(): + # Parameter is required + # a, b need parameter p, and we want sets a, b, c + c = {"sets": ["a", "b", "c"], "p": "exists"} + check_set_specific_parameter(c, set(["a", "b"]), "p") + + # Parameter isn't required based on the sets we want + # z needs parameter p, but we only want sets a, b, c + c = {"sets": ["a", "b", "c"], "p": ""} + check_set_specific_parameter(c, set(["z"]), "p") + + # Parameter is required + # a, b need parameter p, and we want sets a, b, c + c = {"sets": ["a", "b", "c"], "p": ""} + with pytest.raises(ParameterNotProvidedError): + check_set_specific_parameter(c, set(["a", "b"]), "p") + + def test_check_parameters_for_bash(): # diurnal_cycle c = {"sets": ["diurnal_cycle"], "climo_diurnal_frequency": "diurnal_8xdaily"} @@ -191,9 +220,9 @@ def test_check_mvm_only_parameters_for_bash(): def test_check_and_define_parameters(): - # test_zppy_utils.py tests the guessing functionality turned off. + # test_zppy_utils.py tests the inference functionality turned off. # So, we'll only test it turned on here. - guesses = {"guess_path_parameters": True, "guess_section_parameters": True} + inferences = {"infer_path_parameters": True, "infer_section_parameters": True} prefix_requirements = { "subsection": "sub", "tag": "tag", @@ -203,7 +232,7 @@ def test_check_and_define_parameters(): "ref_year2": 1990, } base: Dict[str, Any] = {"diagnostics_base_path": "diags/post"} - base.update(guesses) + base.update(inferences) base.update(prefix_requirements) mvm_base = dict() diff --git a/tests/test_zppy_ilamb.py b/tests/test_zppy_ilamb.py index a130ba7b..2af558c5 100644 --- a/tests/test_zppy_ilamb.py +++ b/tests/test_zppy_ilamb.py @@ -22,7 +22,7 @@ def test_determine_and_add_dependencies(): ] assert dependencies == expected - # Have zppy guess the subsection names + # Have zppy infer the subsection names c = { "e3sm_to_cmip_atm_subsection": "", "e3sm_to_cmip_land_subsection": "", @@ -32,8 +32,8 @@ def test_determine_and_add_dependencies(): "year1": 1980, "year2": 1990, "ts_num_years": 5, - "guess_path_parameters": True, - "guess_section_parameters": True, + "infer_path_parameters": True, + "infer_section_parameters": True, } dependencies = [] determine_and_add_dependencies(c, dependencies, "script_dir") diff --git a/tests/test_zppy_utils.py b/tests/test_zppy_utils.py index e2d76d5e..1e67ca8e 100644 --- a/tests/test_zppy_utils.py +++ b/tests/test_zppy_utils.py @@ -3,21 +3,19 @@ import pytest from zppy.utils import ( - ParameterGuessType, + ParameterInferenceType, ParameterNotProvidedError, add_dependencies, - check_parameter_defined, - check_required_parameters, - define_or_guess, - define_or_guess2, get_active_status, get_file_names, - get_guess_type_parameter, + get_inference_type_parameter, get_url_message, + get_value_from_parameter, get_years, set_component_and_prc_typ, set_grid, set_mapping_file, + set_value_of_parameter_if_undefined, ) @@ -45,14 +43,14 @@ def test_get_active_status(): get_active_status(task) -def test_get_guess_type_parameter(): +def test_get_inference_type_parameter(): assert ( - get_guess_type_parameter(ParameterGuessType.SECTION_GUESS) - == "guess_section_parameters" + get_inference_type_parameter(ParameterInferenceType.SECTION_INFERENCE) + == "infer_section_parameters" ) assert ( - get_guess_type_parameter(ParameterGuessType.PATH_GUESS) - == "guess_path_parameters" + get_inference_type_parameter(ParameterInferenceType.PATH_INFERENCE) + == "infer_path_parameters" ) @@ -189,24 +187,6 @@ def test_set_component_and_prc_typ(): set_component_and_prc_typ(c) -def test_check_required_parameters(): - # Parameter is required - # a, b need parameter p, and we want sets a, b, c - c = {"sets": ["a", "b", "c"], "p": "exists"} - check_required_parameters(c, set(["a", "b"]), "p") - - # Parameter isn't required based on the sets we want - # z needs parameter p, but we only want sets a, b, c - c = {"sets": ["a", "b", "c"], "p": ""} - check_required_parameters(c, set(["z"]), "p") - - # Parameter is required - # a, b need parameter p, and we want sets a, b, c - c = {"sets": ["a", "b", "c"], "p": ""} - with pytest.raises(ParameterNotProvidedError): - check_required_parameters(c, set(["a", "b"]), "p") - - def test_get_years(): assert get_years("1980:1990:05") == [(1980, 1984), (1985, 1989)] assert get_years("1980-1990") == [(1980, 1990)] @@ -245,23 +225,23 @@ def test_get_years(): get_years("1980-1990:05:03") -def test_define_or_guess(): +def test_get_value_from_parameter(): # First choice is defined c = { "first_choice": "a", "second_choice": "b", - "guess_path_parameters": True, - "guess_section_parameters": True, + "infer_path_parameters": True, + "infer_section_parameters": True, } assert ( - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.PATH_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.PATH_INFERENCE ) == "a" ) assert ( - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.SECTION_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.SECTION_INFERENCE ) == "a" ) @@ -269,18 +249,18 @@ def test_define_or_guess(): c = { "first_choice": "a", "second_choice": "b", - "guess_path_parameters": True, - "guess_section_parameters": False, + "infer_path_parameters": True, + "infer_section_parameters": False, } assert ( - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.PATH_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.PATH_INFERENCE ) == "a" ) assert ( - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.SECTION_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.SECTION_INFERENCE ) == "a" ) @@ -288,18 +268,18 @@ def test_define_or_guess(): c = { "first_choice": "a", "second_choice": "b", - "guess_path_parameters": False, - "guess_section_parameters": True, + "infer_path_parameters": False, + "infer_section_parameters": True, } assert ( - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.PATH_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.PATH_INFERENCE ) == "a" ) assert ( - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.SECTION_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.SECTION_INFERENCE ) == "a" ) @@ -308,18 +288,18 @@ def test_define_or_guess(): c = { "first_choice": "", "second_choice": "b", - "guess_path_parameters": True, - "guess_section_parameters": True, + "infer_path_parameters": True, + "infer_section_parameters": True, } assert ( - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.PATH_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.PATH_INFERENCE ) == "b" ) assert ( - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.SECTION_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.SECTION_INFERENCE ) == "b" ) @@ -327,165 +307,177 @@ def test_define_or_guess(): c = { "first_choice": "", "second_choice": "b", - "guess_path_parameters": True, - "guess_section_parameters": False, + "infer_path_parameters": True, + "infer_section_parameters": False, } assert ( - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.PATH_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.PATH_INFERENCE ) == "b" ) with pytest.raises(ParameterNotProvidedError): - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.SECTION_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.SECTION_INFERENCE ) c = { "first_choice": "", "second_choice": "b", - "guess_path_parameters": False, - "guess_section_parameters": True, + "infer_path_parameters": False, + "infer_section_parameters": True, } with pytest.raises(ParameterNotProvidedError): - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.PATH_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.PATH_INFERENCE ) assert ( - define_or_guess( - c, "first_choice", "second_choice", ParameterGuessType.SECTION_GUESS + get_value_from_parameter( + c, "first_choice", "second_choice", ParameterInferenceType.SECTION_INFERENCE ) == "b" ) -def test_define_or_guess2(): +def test_set_value_of_parameter_if_undefined(): # The required parameter has a value c = { "required_parameter": "a", - "guess_path_parameters": True, - "guess_section_parameters": True, + "infer_path_parameters": True, + "infer_section_parameters": True, } - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.PATH_GUESS + set_value_of_parameter_if_undefined( + c, "required_parameter", "backup_option", ParameterInferenceType.PATH_INFERENCE ) assert c["required_parameter"] == "a" c = { "required_parameter": "a", - "guess_path_parameters": True, - "guess_section_parameters": True, + "infer_path_parameters": True, + "infer_section_parameters": True, } - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.SECTION_GUESS + set_value_of_parameter_if_undefined( + c, + "required_parameter", + "backup_option", + ParameterInferenceType.SECTION_INFERENCE, ) assert c["required_parameter"] == "a" c = { "required_parameter": "a", - "guess_path_parameters": True, - "guess_section_parameters": False, + "infer_path_parameters": True, + "infer_section_parameters": False, } - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.PATH_GUESS + set_value_of_parameter_if_undefined( + c, "required_parameter", "backup_option", ParameterInferenceType.PATH_INFERENCE ) assert c["required_parameter"] == "a" c = { "required_parameter": "a", - "guess_path_parameters": True, - "guess_section_parameters": False, + "infer_path_parameters": True, + "infer_section_parameters": False, } - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.SECTION_GUESS + set_value_of_parameter_if_undefined( + c, + "required_parameter", + "backup_option", + ParameterInferenceType.SECTION_INFERENCE, ) assert c["required_parameter"] == "a" c = { "required_parameter": "a", - "guess_path_parameters": False, - "guess_section_parameters": True, + "infer_path_parameters": False, + "infer_section_parameters": True, } - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.PATH_GUESS + set_value_of_parameter_if_undefined( + c, "required_parameter", "backup_option", ParameterInferenceType.PATH_INFERENCE ) assert c["required_parameter"] == "a" c = { "required_parameter": "a", - "guess_path_parameters": False, - "guess_section_parameters": True, + "infer_path_parameters": False, + "infer_section_parameters": True, } - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.SECTION_GUESS + set_value_of_parameter_if_undefined( + c, + "required_parameter", + "backup_option", + ParameterInferenceType.SECTION_INFERENCE, ) assert c["required_parameter"] == "a" # The required parameter is undefined c = { "required_parameter": "", - "guess_path_parameters": True, - "guess_section_parameters": True, + "infer_path_parameters": True, + "infer_section_parameters": True, } - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.PATH_GUESS + set_value_of_parameter_if_undefined( + c, "required_parameter", "backup_option", ParameterInferenceType.PATH_INFERENCE ) assert c["required_parameter"] == "backup_option" c = { "required_parameter": "", - "guess_path_parameters": True, - "guess_section_parameters": True, + "infer_path_parameters": True, + "infer_section_parameters": True, } - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.SECTION_GUESS + set_value_of_parameter_if_undefined( + c, + "required_parameter", + "backup_option", + ParameterInferenceType.SECTION_INFERENCE, ) assert c["required_parameter"] == "backup_option" c = { "required_parameter": "", - "guess_path_parameters": True, - "guess_section_parameters": False, + "infer_path_parameters": True, + "infer_section_parameters": False, } - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.PATH_GUESS + set_value_of_parameter_if_undefined( + c, "required_parameter", "backup_option", ParameterInferenceType.PATH_INFERENCE ) assert c["required_parameter"] == "backup_option" c = { "required_parameter": "", - "guess_path_parameters": True, - "guess_section_parameters": False, + "infer_path_parameters": True, + "infer_section_parameters": False, } with pytest.raises(ParameterNotProvidedError): - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.SECTION_GUESS + set_value_of_parameter_if_undefined( + c, + "required_parameter", + "backup_option", + ParameterInferenceType.SECTION_INFERENCE, ) c = { "required_parameter": "", - "guess_path_parameters": False, - "guess_section_parameters": True, + "infer_path_parameters": False, + "infer_section_parameters": True, } with pytest.raises(ParameterNotProvidedError): - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.PATH_GUESS + set_value_of_parameter_if_undefined( + c, + "required_parameter", + "backup_option", + ParameterInferenceType.PATH_INFERENCE, ) c = { "required_parameter": "", - "guess_path_parameters": False, - "guess_section_parameters": True, + "infer_path_parameters": False, + "infer_section_parameters": True, } - define_or_guess2( - c, "required_parameter", "backup_option", ParameterGuessType.SECTION_GUESS + set_value_of_parameter_if_undefined( + c, + "required_parameter", + "backup_option", + ParameterInferenceType.SECTION_INFERENCE, ) assert c["required_parameter"] == "backup_option" -def test_check_parameter_defined(): - c = {"a": 1, "b": 2, "c": ""} - check_parameter_defined(c, "a") - with pytest.raises(ParameterNotProvidedError): - check_parameter_defined(c, "c") - with pytest.raises(ParameterNotProvidedError): - check_parameter_defined(c, "d") - - def test_get_file_names(): bash, settings, status = get_file_names("script_dir", "prefix") assert bash == "script_dir/prefix.bash" diff --git a/zppy/climo.py b/zppy/climo.py index 716d4ace..1a4e768b 100644 --- a/zppy/climo.py +++ b/zppy/climo.py @@ -4,11 +4,11 @@ from zppy.bundle import handle_bundles from zppy.utils import ( - ParameterGuessType, + ParameterInferenceType, check_status, - define_or_guess, get_file_names, get_tasks, + get_value_from_parameter, get_years, initialize_template, make_executable, @@ -43,8 +43,8 @@ def climo(config: ConfigObj, script_dir: str, existing_bundles, job_ids_file): if ("last_year" in c.keys()) and (c["yr_end"] > c["last_year"]): continue # Skip this year set c["scriptDir"] = script_dir - sub: str = define_or_guess( - c, "subsection", "grid", ParameterGuessType.SECTION_GUESS + sub: str = get_value_from_parameter( + c, "subsection", "grid", ParameterInferenceType.SECTION_INFERENCE ) prefix: str = f"climo_{sub}_{c['yr_start']:04d}-{c['yr_end']:04d}" print(prefix) diff --git a/zppy/defaults/default.ini b/zppy/defaults/default.ini index 9cb8dd7b..ff997e5a 100644 --- a/zppy/defaults/default.ini +++ b/zppy/defaults/default.ini @@ -27,11 +27,11 @@ fail_on_dependency_skip = boolean(default=False) frequency = string(default="monthly") # The grid to use grid = string(default="") -# These two parameters enable zppy to guess path or section parameters. +# These two parameters enable zppy to infer path or section parameters. # This allows users to set fewer parameters, but with the risk of zppy choosing incorrect values for them. # Set to False for more transparency in path or section defintions. -guess_path_parameters = boolean(default=True) -guess_section_parameters = boolean(default=True) +infer_path_parameters = boolean(default=True) +infer_section_parameters = boolean(default=True) # The directory to be post-processed # NOTE: no default, must be provided by user input = string diff --git a/zppy/e3sm_diags.py b/zppy/e3sm_diags.py index 2a611636..a1239909 100644 --- a/zppy/e3sm_diags.py +++ b/zppy/e3sm_diags.py @@ -5,19 +5,18 @@ from zppy.bundle import handle_bundles from zppy.utils import ( - ParameterGuessType, + ParameterInferenceType, + ParameterNotProvidedError, add_dependencies, - check_parameter_defined, - check_required_parameters, check_status, - define_or_guess, - define_or_guess2, get_file_names, get_tasks, + get_value_from_parameter, get_years, initialize_template, make_executable, print_url, + set_value_of_parameter_if_undefined, submit_script, write_settings_file, ) @@ -101,11 +100,37 @@ def e3sm_diags(config: ConfigObj, script_dir: str, existing_bundles, job_ids_fil return existing_bundles +def check_parameter_defined( + c: Dict[str, Any], relevant_parameter: str, explanation: str = "" +) -> None: + if (relevant_parameter not in c.keys()) or (c[relevant_parameter] == ""): + if explanation: + message = f"{relevant_parameter} is needed because {explanation}" + else: + message = f"{relevant_parameter} is not defined." + raise ParameterNotProvidedError(message) + + +def check_set_specific_parameter( + c: Dict[str, Any], sets_with_requirement: Set[str], relevant_parameter: str +) -> None: + requested_sets = set(c["sets"]) + intersection = sets_with_requirement & requested_sets + if ( + intersection + and (relevant_parameter in c.keys()) + and (c[relevant_parameter] == "") + ): + raise ParameterNotProvidedError( + f"{relevant_parameter} is required because the sets {intersection} were requested." + ) + + def check_parameters_for_bash(c: Dict[str, Any]) -> None: # Check parameters that aren't used until e3sm_diags.bash is run - check_required_parameters(c, set(["qbo"]), "ref_final_yr") - check_required_parameters(c, set(["enso_diags", "qbo"]), "ref_start_yr") - check_required_parameters(c, set(["diurnal_cycle"]), "climo_diurnal_frequency") + check_set_specific_parameter(c, set(["qbo"]), "ref_final_yr") + check_set_specific_parameter(c, set(["enso_diags", "qbo"]), "ref_start_yr") + check_set_specific_parameter(c, set(["diurnal_cycle"]), "climo_diurnal_frequency") def check_mvm_only_parameters_for_bash(c: Dict[str, Any]) -> None: @@ -114,12 +139,12 @@ def check_mvm_only_parameters_for_bash(c: Dict[str, Any]) -> None: check_parameter_defined(c, "ref_name", "mvm requires it.") check_parameter_defined(c, "short_ref_name", "mvm requires it.") - check_required_parameters( + check_set_specific_parameter( c, set(["enso_diags", "tropical_subseasonal", "streamflow", "tc_analysis"]), "ref_final_yr", ) - check_required_parameters( + check_set_specific_parameter( c, set(["tropical_subseasonal", "streamflow", "tc_analysis"]), "ref_start_yr" ) ts_sets = set( @@ -131,95 +156,98 @@ def check_mvm_only_parameters_for_bash(c: Dict[str, Any]) -> None: "streamflow", ] ) - check_required_parameters(c, ts_sets, "ts_num_years_ref") - check_required_parameters(c, ts_sets, "ts_subsection") + check_set_specific_parameter(c, ts_sets, "ts_num_years_ref") + check_set_specific_parameter(c, ts_sets, "ts_subsection") def check_and_define_parameters(c: Dict[str, Any]) -> None: - c["sub"] = define_or_guess( - c, "subsection", "grid", ParameterGuessType.SECTION_GUESS + c["sub"] = get_value_from_parameter( + c, "subsection", "grid", ParameterInferenceType.SECTION_INFERENCE ) - define_or_guess2( + set_value_of_parameter_if_undefined( c, "reference_data_path", f"{c['diagnostics_base_path']}/observations/Atm/climatology/", - ParameterGuessType.PATH_GUESS, + ParameterInferenceType.PATH_INFERENCE, ) if "tc_analysis" in c["sets"]: - define_or_guess2( + set_value_of_parameter_if_undefined( c, "tc_obs", f"{c['diagnostics_base_path']}/observations/Atm/tc-analysis/", - ParameterGuessType.PATH_GUESS, + ParameterInferenceType.PATH_INFERENCE, ) # TODO: do this based on sets, rather than by relying on the user setting ts_num_years if "ts_num_years" in c.keys(): - define_or_guess2( + set_value_of_parameter_if_undefined( c, "obs_ts", f"{c['diagnostics_base_path']}/observations/Atm/time-series/", - ParameterGuessType.PATH_GUESS, + ParameterInferenceType.PATH_INFERENCE, ) prefix: str if c["run_type"] == "model_vs_obs": prefix = f"e3sm_diags_{c['sub']}_{c['tag']}_{c['year1']:04d}-{c['year2']:04d}" if "diurnal_cycle" in c["sets"]: - define_or_guess2( + set_value_of_parameter_if_undefined( c, "dc_obs_climo", c["reference_data_path"], - ParameterGuessType.PATH_GUESS, + ParameterInferenceType.PATH_INFERENCE, ) if "streamflow" in c["sets"]: - define_or_guess2( - c, "streamflow_obs_ts", c["obs_ts"], ParameterGuessType.PATH_GUESS + set_value_of_parameter_if_undefined( + c, + "streamflow_obs_ts", + c["obs_ts"], + ParameterInferenceType.PATH_INFERENCE, ) elif c["run_type"] == "model_vs_model": check_mvm_only_parameters_for_bash(c) prefix = f"e3sm_diags_{c['sub']}_{c['tag']}_{c['year1']:04d}-{c['year2']:04d}_vs_{c['ref_year1']:04d}-{c['ref_year2']:04d}" reference_data_path = c["reference_data_path"].split("/post")[0] + "/post" if "diurnal_cycle" in c["sets"]: - define_or_guess2( + set_value_of_parameter_if_undefined( c, "reference_data_path_climo_diurnal", f"{reference_data_path}/atm/{c['grid']}/clim_diurnal_8xdaily", - ParameterGuessType.PATH_GUESS, + ParameterInferenceType.PATH_INFERENCE, ) if ("tc_analysis" in c["sets"]) and (c["reference_data_path_tc"] == ""): - # We have to guess parameters here, + # We have to infer parameters here, # because multiple year sets are defined in a single subtask. c["reference_data_path_tc"] = ( f"{reference_data_path}/atm/tc-analysis_{c['ref_year1']}_{c['ref_year2']}" ) if set(["enso_diags", "qbo", "area_mean_time_series"]) & set(c["sets"]): - define_or_guess2( + set_value_of_parameter_if_undefined( c, "reference_data_path_ts", f"{reference_data_path}/atm/{c['grid']}/ts/monthly", - ParameterGuessType.PATH_GUESS, + ParameterInferenceType.PATH_INFERENCE, ) if "tropical_subseasonal" in c["sets"]: - define_or_guess2( + set_value_of_parameter_if_undefined( c, "reference_data_path_ts_daily", f"{reference_data_path}/atm/{c['grid']}/ts/daily", - ParameterGuessType.PATH_GUESS, + ParameterInferenceType.PATH_INFERENCE, ) if "streamflow" in c["sets"]: - define_or_guess2( + set_value_of_parameter_if_undefined( c, "reference_data_path_ts_rof", f"{reference_data_path}/rof/native/ts/monthly", - ParameterGuessType.PATH_GUESS, + ParameterInferenceType.PATH_INFERENCE, ) - define_or_guess2( + set_value_of_parameter_if_undefined( c, "gauges_path", os.path.join( c["diagnostics_base_path"], "observations/Atm/time-series/GSIM/GSIM_catchment_characteristics_all_1km2.csv", ), - ParameterGuessType.PATH_GUESS, + ParameterInferenceType.PATH_INFERENCE, ) else: raise ValueError(f"Invalid run_type={c['run_type']}") @@ -251,8 +279,8 @@ def add_climo_dependencies( # Check if any requested sets depend on climo: status_suffix: str = f"_{c['year1']:04d}-{c['year2']:04d}.status" if depend_on_climo & set(c["sets"]): - climo_sub = define_or_guess( - c, "climo_subsection", "sub", ParameterGuessType.SECTION_GUESS + climo_sub = get_value_from_parameter( + c, "climo_subsection", "sub", ParameterInferenceType.SECTION_INFERENCE ) dependencies.append( os.path.join(script_dir, f"climo_{climo_sub}{status_suffix}"), @@ -275,11 +303,11 @@ def add_ts_dependencies( ): start_yr = yr end_yr = yr + c["ts_num_years"] - 1 - ts_sub = define_or_guess( - c, "ts_subsection", "sub", ParameterGuessType.SECTION_GUESS + ts_sub = get_value_from_parameter( + c, "ts_subsection", "sub", ParameterInferenceType.SECTION_INFERENCE ) - ts_daily_sub = define_or_guess( - c, "ts_daily_subsection", "sub", ParameterGuessType.SECTION_GUESS + ts_daily_sub = get_value_from_parameter( + c, "ts_daily_subsection", "sub", ParameterInferenceType.SECTION_INFERENCE ) depend_on_ts: Set[str] = set(["enso_diags", "qbo", "area_mean_time_series"]) if depend_on_ts & set(c["sets"]): diff --git a/zppy/e3sm_to_cmip.py b/zppy/e3sm_to_cmip.py index 38decbe5..61590278 100644 --- a/zppy/e3sm_to_cmip.py +++ b/zppy/e3sm_to_cmip.py @@ -4,17 +4,17 @@ from zppy.bundle import handle_bundles from zppy.utils import ( - ParameterGuessType, + ParameterInferenceType, add_dependencies, check_status, - define_or_guess, - define_or_guess2, get_file_names, get_tasks, + get_value_from_parameter, get_years, initialize_template, make_executable, set_component_and_prc_typ, + set_value_of_parameter_if_undefined, submit_script, write_settings_file, ) @@ -46,8 +46,8 @@ def e3sm_to_cmip(config: ConfigObj, script_dir: str, existing_bundles, job_ids_f c["scriptDir"] = script_dir if "ts_num_years" in c.keys(): c["ts_num_years"] = int(c["ts_num_years"]) - sub: str = define_or_guess( - c, "subsection", "grid", ParameterGuessType.SECTION_GUESS + sub: str = get_value_from_parameter( + c, "subsection", "grid", ParameterInferenceType.SECTION_INFERENCE ) # Run default variables if none are specified if c["cmip_vars"] == "": @@ -69,7 +69,9 @@ def e3sm_to_cmip(config: ConfigObj, script_dir: str, existing_bundles, job_ids_f f.write(template.render(**c)) make_executable(bash_file) # Default to the name of this task if ts_subsection is not defined - define_or_guess2(c, "ts_subsection", sub, ParameterGuessType.SECTION_GUESS) + set_value_of_parameter_if_undefined( + c, "ts_subsection", sub, ParameterInferenceType.SECTION_INFERENCE + ) add_dependencies( dependencies, script_dir, diff --git a/zppy/ilamb.py b/zppy/ilamb.py index c4a159d7..c7cb6139 100644 --- a/zppy/ilamb.py +++ b/zppy/ilamb.py @@ -5,16 +5,16 @@ from zppy.bundle import handle_bundles from zppy.utils import ( - ParameterGuessType, + ParameterInferenceType, add_dependencies, check_status, - define_or_guess2, get_file_names, get_tasks, get_years, initialize_template, make_executable, print_url, + set_value_of_parameter_if_undefined, submit_script, write_settings_file, ) @@ -43,11 +43,11 @@ def ilamb(config: ConfigObj, script_dir: str, existing_bundles, job_ids_file): c["year1"] = s[0] c["year2"] = s[1] c["scriptDir"] = script_dir - define_or_guess2( + set_value_of_parameter_if_undefined( c, "ilamb_obs", os.path.join(c["diagnostics_base_path"], "ilamb_data"), - ParameterGuessType.PATH_GUESS, + ParameterInferenceType.PATH_INFERENCE, ) # List of dependencies determine_and_add_dependencies(c, dependencies, script_dir) @@ -97,8 +97,11 @@ def ilamb(config: ConfigObj, script_dir: str, existing_bundles, job_ids_file): def determine_and_add_dependencies( c: Dict[str, Any], dependencies: List[str], script_dir: str ) -> None: - define_or_guess2( - c, "ts_land_subsection", "land_monthly", ParameterGuessType.SECTION_GUESS + set_value_of_parameter_if_undefined( + c, + "ts_land_subsection", + "land_monthly", + ParameterInferenceType.SECTION_INFERENCE, ) add_dependencies( dependencies, @@ -109,11 +112,11 @@ def determine_and_add_dependencies( c["year2"], c["ts_num_years"], ) - define_or_guess2( + set_value_of_parameter_if_undefined( c, "e3sm_to_cmip_land_subsection", "land_monthly", - ParameterGuessType.SECTION_GUESS, + ParameterInferenceType.SECTION_INFERENCE, ) add_dependencies( dependencies, @@ -125,11 +128,11 @@ def determine_and_add_dependencies( c["ts_num_years"], ) if not c["land_only"]: - define_or_guess2( + set_value_of_parameter_if_undefined( c, "ts_atm_subsection", "atm_monthly_180x360_aave", - ParameterGuessType.SECTION_GUESS, + ParameterInferenceType.SECTION_INFERENCE, ) add_dependencies( dependencies, @@ -140,11 +143,11 @@ def determine_and_add_dependencies( c["year2"], c["ts_num_years"], ) - define_or_guess2( + set_value_of_parameter_if_undefined( c, "e3sm_to_cmip_atm_subsection", "atm_monthly_180x360_aave", - ParameterGuessType.SECTION_GUESS, + ParameterInferenceType.SECTION_INFERENCE, ) add_dependencies( dependencies, diff --git a/zppy/ts.py b/zppy/ts.py index b9976057..249de9dd 100644 --- a/zppy/ts.py +++ b/zppy/ts.py @@ -4,11 +4,11 @@ from zppy.bundle import handle_bundles from zppy.utils import ( - ParameterGuessType, + ParameterInferenceType, check_status, - define_or_guess, get_file_names, get_tasks, + get_value_from_parameter, get_years, initialize_template, make_executable, @@ -44,8 +44,8 @@ def ts(config: ConfigObj, script_dir: str, existing_bundles, job_ids_file): continue # Skip this year set c["ypf"] = s[1] - s[0] + 1 c["scriptDir"] = script_dir - sub: str = define_or_guess( - c, "subsection", "grid", ParameterGuessType.SECTION_GUESS + sub: str = get_value_from_parameter( + c, "subsection", "grid", ParameterInferenceType.SECTION_INFERENCE ) prefix = f"ts_{sub}_{c['yr_start']:04d}-{c['yr_end']:04d}-{c['ypf']:04d}" print(prefix) diff --git a/zppy/utils.py b/zppy/utils.py index e7cd2aa3..132af902 100644 --- a/zppy/utils.py +++ b/zppy/utils.py @@ -7,7 +7,7 @@ import time from enum import Enum from subprocess import PIPE, Popen -from typing import Any, Dict, List, Set, Tuple +from typing import Any, Dict, List, Tuple import jinja2 from configobj import ConfigObj @@ -18,9 +18,9 @@ # Classes ##################################################################### -class ParameterGuessType(Enum): - PATH_GUESS = 1 - SECTION_GUESS = 2 +class ParameterInferenceType(Enum): + PATH_INFERENCE = 1 + SECTION_INFERENCE = 2 class ParameterNotProvidedError(RuntimeError): @@ -48,15 +48,15 @@ def get_active_status(task: Dict[str, Any]) -> bool: raise TypeError(f"Invalid type {type(active)} for 'active'") -def get_guess_type_parameter(guess_type: ParameterGuessType) -> str: - guess_type_parameter: str - if guess_type == ParameterGuessType.PATH_GUESS: - guess_type_parameter = "guess_path_parameters" - elif guess_type == ParameterGuessType.SECTION_GUESS: - guess_type_parameter = "guess_section_parameters" +def get_inference_type_parameter(inference_type: ParameterInferenceType) -> str: + inference_type_parameter: str + if inference_type == ParameterInferenceType.PATH_INFERENCE: + inference_type_parameter = "infer_path_parameters" + elif inference_type == ParameterInferenceType.SECTION_INFERENCE: + inference_type_parameter = "infer_section_parameters" else: - raise ValueError(f"Invalid guess_type: {guess_type}") - return guess_type_parameter + raise ValueError(f"Invalid inference_type: {inference_type}") + return inference_type_parameter def get_url_message(c: Dict[str, Any], task: str) -> str: @@ -229,21 +229,6 @@ def set_component_and_prc_typ(c: Dict[str, Any]) -> None: c["prc_typ"] = prc_typ -def check_required_parameters( - c: Dict[str, Any], sets_with_requirement: Set[str], relevant_parameter: str -) -> None: - requested_sets = set(c["sets"]) - intersection = sets_with_requirement & requested_sets - if ( - intersection - and (relevant_parameter in c.keys()) - and (c[relevant_parameter] == "") - ): - raise ParameterNotProvidedError( - f"{relevant_parameter} is required because the sets {intersection} were requested." - ) - - # Return all year sets from a configuration given by a list of strings # "year_begin:year_end:year_freq" # "year_begin-year_end" @@ -283,59 +268,48 @@ def get_years(years_input) -> List[Tuple[int, int]]: # This returns a value -def define_or_guess( +def get_value_from_parameter( c: Dict[str, Any], first_choice_parameter: str, second_choice_parameter: str, - guess_type: ParameterGuessType, + inference_type: ParameterInferenceType, ) -> Any: - # Determine which type of guess to use. - guess_type_parameter: str = get_guess_type_parameter(guess_type) + # Determine which type of inference to use. + inference_type_parameter: str = get_inference_type_parameter(inference_type) # Define a value, if possible. value: Any if (first_choice_parameter in c.keys()) and c[first_choice_parameter]: value = c[first_choice_parameter] - elif c[guess_type_parameter]: + elif c[inference_type_parameter]: # first_choice_parameter isn't defined, - # so let's make a guess for the value. + # so let's make an inference for the value. value = c[second_choice_parameter] else: raise ParameterNotProvidedError( - f"{first_choice_parameter} was not provided, and guessing is turned off. Turn on guessing by setting {guess_type_parameter} to True." + f"{first_choice_parameter} was not provided, and inferring is turned off. Turn on inferring by setting {inference_type_parameter} to True." ) return value # This updates the dict c -def define_or_guess2( +def set_value_of_parameter_if_undefined( c: Dict[str, Any], parameter: str, backup_option: str, - guess_type: ParameterGuessType, + inference_type: ParameterInferenceType, ) -> None: - # Determine which type of guess to use. - guess_type_parameter: str = get_guess_type_parameter(guess_type) + # Determine which type of inference to use. + inference_type_parameter: str = get_inference_type_parameter(inference_type) # Define a value, if possible. if (parameter in c.keys()) and (c[parameter] == ""): - if c[guess_type_parameter]: + if c[inference_type_parameter]: c[parameter] = backup_option else: raise ParameterNotProvidedError( - f"{parameter} was not provided, and guessing is turned off. Turn on guessing by setting {guess_type_parameter} to True." + f"{parameter} was not provided, and inferring is turned off. Turn on inferring by setting {inference_type_parameter} to True." ) -def check_parameter_defined( - c: Dict[str, Any], relevant_parameter: str, explanation: str = "" -) -> None: - if (relevant_parameter not in c.keys()) or (c[relevant_parameter] == ""): - if explanation: - message = f"{relevant_parameter} is needed because {explanation}" - else: - message = f"{relevant_parameter} is not defined." - raise ParameterNotProvidedError(message) - - def get_file_names(script_dir: str, prefix: str): return tuple( [