Skip to content

Commit

Permalink
Add checks for lat_lon_land
Browse files Browse the repository at this point in the history
  • Loading branch information
forsyth2 committed Oct 16, 2024
1 parent f759fdc commit c3bbb5b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ short_name = "#expand case_name#"
walltime = "#expand diags_walltime#"

[[ lnd_monthly_mvm_lnd ]]
climo_subsection = "land_monthly_climo"
climo_land_subsection = "land_monthly_climo"
diff_title = "Difference"
ref_final_yr = 1988
ref_name = "#expand case_name#"
Expand Down
26 changes: 26 additions & 0 deletions tests/test_zppy_e3sm_diags.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,32 @@ def test_add_climo_dependencies(self):
dependencies = []
add_climo_dependencies(c, dependencies, "script_dir")
self.assertEqual(dependencies, ["script_dir/climo_cdsub_1980-1990.status"])
c = {"sets": ["diurnal_cycle"]}
c.update(base)
dependencies = []
self.assertRaises(
ParameterNotProvidedError,
add_climo_dependencies,
c,
dependencies,
"script_dir",
)

c = {"sets": ["lat_lon_land"], "climo_land_subsection": "lndsub"}
c.update(base)
dependencies = []
add_climo_dependencies(c, dependencies, "script_dir")
self.assertEqual(dependencies, ["script_dir/climo_lndsub_1980-1990.status"])
c = {"sets": ["lat_lon_land"]}
c.update(base)
dependencies = []
self.assertRaises(
ParameterNotProvidedError,
add_climo_dependencies,
c,
dependencies,
"script_dir",
)

c = {"sets": ["tc_analysis"]}
c.update(base)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_zppy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ParameterGuessType,
ParameterNotProvidedError,
add_dependencies,
check_parameter_defined,
check_required_parameters,
define_or_guess,
define_or_guess2,
Expand Down Expand Up @@ -460,6 +461,12 @@ def test_define_or_guess2(self):
)
self.assertEqual(c["required_parameter"], "backup_option")

def test_check_parameter_defined(self):
c = {"a": 1, "b": 2, "c": ""}
check_parameter_defined(c, "a")
self.assertRaises(ParameterNotProvidedError, check_parameter_defined, c, "c")
self.assertRaises(ParameterNotProvidedError, check_parameter_defined, c, "d")

def test_get_file_names(self):
bash, settings, status = get_file_names("script_dir", "prefix")
self.assertEqual(bash, "script_dir/prefix.bash")
Expand Down
19 changes: 12 additions & 7 deletions zppy/e3sm_diags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from zppy.bundle import handle_bundles
from zppy.utils import (
ParameterGuessType,
ParameterNotProvidedError,
add_dependencies,
check_parameter_defined,
check_required_parameters,
check_status,
define_or_guess,
Expand Down Expand Up @@ -111,12 +111,9 @@ def check_parameters_for_bash(c: Dict[str, Any]) -> None:

def check_mvm_only_parameters_for_bash(c: Dict[str, Any]) -> None:
# Check mvm-specific parameters that aren't used until e3sm_diags.bash is run.
if c["diff_title"] == "":
raise ParameterNotProvidedError("diff_title")
if c["ref_name"] == "":
raise ParameterNotProvidedError("ref_name")
if c["short_ref_name"] == "":
raise ParameterNotProvidedError("short_ref_name")
check_parameter_defined(c, "diff_title")
check_parameter_defined(c, "ref_name")
check_parameter_defined(c, "short_ref_name")

check_required_parameters(
c,
Expand Down Expand Up @@ -256,11 +253,19 @@ def add_climo_dependencies(
os.path.join(script_dir, f"climo_{climo_sub}{status_suffix}"),
)
if "diurnal_cycle" in c["sets"]:
check_parameter_defined(c, "climo_diurnal_subsection")
dependencies.append(
os.path.join(
script_dir, f"climo_{c['climo_diurnal_subsection']}{status_suffix}"
)
)
if "lat_lon_land" in c["sets"]:
check_parameter_defined(c, "climo_land_subsection")
dependencies.append(
os.path.join(
script_dir, f"climo_{c['climo_land_subsection']}{status_suffix}"
)
)
if "tc_analysis" in c["sets"]:
dependencies.append(os.path.join(script_dir, f"tc_analysis{status_suffix}"))

Expand Down
5 changes: 5 additions & 0 deletions zppy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ def define_or_guess2(
raise ParameterNotProvidedError(parameter)


def check_parameter_defined(c: Dict[str, Any], relevant_parameter: str) -> None:
if (relevant_parameter not in c.keys()) or (c[relevant_parameter] == ""):
raise ParameterNotProvidedError(relevant_parameter)


def get_file_names(script_dir: str, prefix: str):
return tuple(
[
Expand Down

0 comments on commit c3bbb5b

Please sign in to comment.