-
Notifications
You must be signed in to change notification settings - Fork 16
Allow e3sm_to_cmip to use ilamb parameter names #672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
1cf4fa2
45dc2c6
31e2f15
3384fc4
44992bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import pytest | ||
|
|
||
| from zppy.e3sm_to_cmip import check_and_define_parameters, check_parameters_for_bash | ||
| from zppy.utils import ParameterNotProvidedError | ||
|
|
||
|
|
||
| def test_check_parameters_for_bash(): | ||
| c = {"ts_grid": "grid"} | ||
| check_parameters_for_bash(c) | ||
|
|
||
| c = {"ts_grid": ""} | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_parameters_for_bash(c) | ||
|
|
||
| c = {"component": "atm", "ts_atm_grid": "atm_grid"} | ||
| check_parameters_for_bash(c) | ||
| c = {"component": "lnd", "ts_land_grid": "land_grid"} | ||
| check_parameters_for_bash(c) | ||
|
|
||
| c = {"component": "atm", "ts_land_grid": "land_grid"} | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_parameters_for_bash(c) | ||
| c = {"component": "lnd", "ts_atm_grid": "atm_grid"} | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_parameters_for_bash(c) | ||
|
|
||
| c = {"ts_atm_grid": "atm_grid"} | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_parameters_for_bash(c) | ||
| c = {"ts_land_grid": "land_grid"} | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_parameters_for_bash(c) | ||
|
|
||
|
|
||
| def test_check_and_define_parameters(): | ||
| sub = "name_of_this_subsection" | ||
|
|
||
| # Guess the subsection | ||
| c = {"ts_subsection": "subsection", "guess_section_parameters": True} | ||
| check_and_define_parameters(c, sub) | ||
| assert c["ts_subsection"] == "subsection" | ||
|
|
||
| c = {"ts_subsection": "", "guess_section_parameters": True} | ||
| check_and_define_parameters(c, sub) | ||
| assert c["ts_subsection"] == "name_of_this_subsection" | ||
|
|
||
| c = { | ||
| "component": "atm", | ||
| "ts_atm_subsection": "atm_subsection", | ||
| "guess_section_parameters": True, | ||
| } | ||
| check_and_define_parameters(c, sub) | ||
| assert c["ts_subsection"] == "atm_subsection" | ||
| c = { | ||
| "component": "lnd", | ||
| "ts_land_subsection": "land_subsection", | ||
| "guess_section_parameters": True, | ||
| } | ||
| check_and_define_parameters(c, sub) | ||
| assert c["ts_subsection"] == "land_subsection" | ||
|
|
||
| c = { | ||
| "component": "atm", | ||
| "ts_land_subsection": "land_subsection", | ||
| "guess_section_parameters": True, | ||
| } | ||
| check_and_define_parameters(c, sub) | ||
| assert c["ts_subsection"] == "name_of_this_subsection" | ||
| c = { | ||
| "component": "lnd", | ||
| "ts_atm_subsection": "atm_subsection", | ||
| "guess_section_parameters": True, | ||
| } | ||
| check_and_define_parameters(c, sub) | ||
| assert c["ts_subsection"] == "name_of_this_subsection" | ||
|
|
||
| c = {"ts_atm_subsection": "atm_subsection", "guess_section_parameters": True} | ||
| check_and_define_parameters(c, sub) | ||
| assert c["ts_subsection"] == "name_of_this_subsection" | ||
| c = {"ts_land_subsection": "land_subsection", "guess_section_parameters": True} | ||
| check_and_define_parameters(c, sub) | ||
| assert c["ts_subsection"] == "name_of_this_subsection" | ||
|
|
||
| # Don't guess the subsection | ||
| c = {"ts_subsection": "subsection", "guess_section_parameters": False} | ||
| check_and_define_parameters(c, sub) | ||
| assert c["ts_subsection"] == "subsection" | ||
|
|
||
| c = {"ts_subsection": "", "guess_section_parameters": False} | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_and_define_parameters(c, sub) | ||
|
|
||
| c = { | ||
| "component": "atm", | ||
| "ts_atm_subsection": "atm_subsection", | ||
| "guess_section_parameters": False, | ||
| } | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_and_define_parameters(c, sub) | ||
| c = { | ||
| "component": "lnd", | ||
| "ts_land_subsection": "land_subsection", | ||
| "guess_section_parameters": False, | ||
| } | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_and_define_parameters(c, sub) | ||
|
|
||
| c = { | ||
| "component": "atm", | ||
| "ts_land_subsection": "land_subsection", | ||
| "guess_section_parameters": False, | ||
| } | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_and_define_parameters(c, sub) | ||
| c = { | ||
| "component": "lnd", | ||
| "ts_atm_subsection": "atm_subsection", | ||
| "guess_section_parameters": False, | ||
| } | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_and_define_parameters(c, sub) | ||
|
|
||
| c = {"ts_atm_subsection": "atm_subsection", "guess_section_parameters": False} | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_and_define_parameters(c, sub) | ||
| c = {"ts_land_subsection": "land_subsection", "guess_section_parameters": False} | ||
| with pytest.raises(ParameterNotProvidedError): | ||
| check_and_define_parameters(c, sub) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,11 +5,12 @@ | |
| from zppy.bundle import handle_bundles | ||
| from zppy.utils import ( | ||
| ParameterGuessType, | ||
| ParameterNotProvidedError, | ||
| add_dependencies, | ||
| check_status, | ||
| define_or_guess, | ||
| define_or_guess2, | ||
| get_file_names, | ||
| get_guess_type_parameter, | ||
| get_tasks, | ||
| get_years, | ||
| initialize_template, | ||
|
|
@@ -34,6 +35,7 @@ def e3sm_to_cmip(config: ConfigObj, script_dir: str, existing_bundles, job_ids_f | |
| for c in tasks: | ||
| dependencies: List[str] = [] | ||
| set_component_and_prc_typ(c) | ||
| check_parameters_for_bash(c) | ||
| c["cmor_tables_prefix"] = c["diagnostics_base_path"] | ||
| year_sets: List[Tuple[int, int]] = get_years(c["years"]) | ||
| # Loop over year sets | ||
|
|
@@ -68,8 +70,7 @@ def e3sm_to_cmip(config: ConfigObj, script_dir: str, existing_bundles, job_ids_f | |
| with open(bash_file, "w") as 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) | ||
| check_and_define_parameters(c, sub) | ||
| add_dependencies( | ||
| dependencies, | ||
| script_dir, | ||
|
|
@@ -106,3 +107,38 @@ def e3sm_to_cmip(config: ConfigObj, script_dir: str, existing_bundles, job_ids_f | |
| print(f" environment_commands={c['environment_commands']}") | ||
|
|
||
| return existing_bundles | ||
|
|
||
|
|
||
| def check_parameters_for_bash(c: Dict[str, Any]) -> None: | ||
| # Check parameters that aren't used until e3sm_diags.bash is run | ||
| parameter = "ts_grid" | ||
| if (parameter not in c.keys()) or (c[parameter] == ""): | ||
| if "component" in c.keys(): | ||
| if (c["component"] == "atm") and ("ts_atm_grid" in c.keys()): | ||
| c[parameter] = c["ts_atm_grid"] | ||
| elif (c["component"] == "lnd") and ("ts_land_grid" in c.keys()): | ||
| c[parameter] = c["ts_land_grid"] | ||
| else: | ||
| raise ParameterNotProvidedError(parameter) | ||
| else: | ||
| raise ParameterNotProvidedError(parameter) | ||
|
|
||
|
|
||
| def check_and_define_parameters(c: Dict[str, Any], sub: str) -> None: | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reasons for the different function are:
|
||
| parameter = "ts_subsection" | ||
| if (parameter not in c.keys()) or (c[parameter] == ""): | ||
| guess_type_parameter: str = get_guess_type_parameter( | ||
| ParameterGuessType.SECTION_GUESS | ||
| ) | ||
| if c[guess_type_parameter]: | ||
| if "component" in c.keys(): | ||
| if (c["component"] == "atm") and ("ts_atm_subsection" in c.keys()): | ||
| c[parameter] = c["ts_atm_subsection"] | ||
| elif (c["component"] == "lnd") and ("ts_land_subsection" in c.keys()): | ||
| c[parameter] = c["ts_land_subsection"] | ||
| else: | ||
| c[parameter] = sub | ||
| else: | ||
| c[parameter] = sub | ||
| else: | ||
| raise ParameterNotProvidedError(parameter) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand, you're moving these parameters up a level in the configuration hierarchy so that they can be reused across each
e3sm_to_cmipsubtask, rather than configuringts_griddifferently for each subtask. The intention is to eliminate redundant code/configuration.Is this correct? If so, it sounds reasonable to me.