Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions tests/test_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ def test_sections():
"reservation": "",
"qos": "regular",
"templateDir": "zppy/templates",
"ts_atm_grid": "180x360_aave",
"ts_atm_subsection": "",
"ts_grid": "180x360_aave",
"ts_land_grid": "180x360_aave",
"ts_land_subsection": "",
"ts_num_years": 5,
"ts_subsection": "",
"vars": "FSNTOA,FLUT,FSNT,FLNT,FSNS,FLNS,SHFLX,QFLX,TAUX,TAUY,PRECC,PRECL,PRECSC,PRECSL,TS,TREFHT,CLDTOT,CLDHGH,CLDMED,CLDLOW,U",
"walltime": "02:00:00",
"www": "WWWW",
Expand Down Expand Up @@ -149,7 +155,13 @@ def test_sections():
"subsection": None,
"templateDir": "zppy/templates",
"tpd": 1,
"ts_atm_grid": "180x360_aave",
"ts_atm_subsection": "",
"ts_grid": "180x360_aave",
"ts_land_grid": "180x360_aave",
"ts_land_subsection": "",
"ts_num_years": 5,
"ts_subsection": "",
"vars": "FSNTOA,FLUT,FSNT,FLNT,FSNS,FLNS,SHFLX,QFLX,PRECC,PRECL,PRECSC,PRECSL,TS,TREFHT",
"walltime": "02:00:00",
"www": "WWWW",
Expand Down Expand Up @@ -204,7 +216,13 @@ def test_sections():
"reservation": "",
"subsection": None,
"templateDir": "zppy/templates",
"ts_atm_grid": "180x360_aave",
"ts_atm_subsection": "",
"ts_grid": "180x360_aave",
"ts_land_grid": "180x360_aave",
"ts_land_subsection": "",
"ts_num_years": 5,
"ts_subsection": "",
"vars": "",
"walltime": "02:00:00",
"www": "WWWW",
Expand Down Expand Up @@ -259,7 +277,13 @@ def test_subsections():
"qos": "regular",
"reservation": "",
"templateDir": "zppy/templates",
"ts_atm_grid": "180x360_aave",
"ts_atm_subsection": "",
"ts_grid": "180x360_aave",
"ts_land_grid": "180x360_aave",
"ts_land_subsection": "",
"ts_num_years": 5,
"ts_subsection": "",
"vars": "FSNTOA,FLUT,FSNT,FLNT,FSNS,FLNS,SHFLX,QFLX,TAUX,TAUY,PRECC,PRECL,PRECSC,PRECSL,TS,TREFHT,CLDTOT,CLDHGH,CLDMED,CLDLOW,U",
"walltime": "02:00:00",
"www": "WWWW",
Expand Down Expand Up @@ -334,7 +358,13 @@ def test_subsections():
"subsection": "ts_grid1",
"templateDir": "zppy/templates",
"tpd": 1,
"ts_atm_grid": "180x360_aave",
"ts_atm_subsection": "",
"ts_grid": "180x360_aave",
"ts_land_grid": "180x360_aave",
"ts_land_subsection": "",
"ts_num_years": 5,
"ts_subsection": "",
"vars": "FSNTOA,FLUT,FSNT,FLNT,FSNS,FLNS,SHFLX,QFLX,PRECC,PRECL,PRECSC,PRECSL,TS,TREFHT",
"walltime": "02:00:00",
"www": "WWWW",
Expand Down Expand Up @@ -375,7 +405,13 @@ def test_subsections():
"subsection": "ts_grid2",
"templateDir": "zppy/templates",
"tpd": 1,
"ts_atm_grid": "180x360_aave",
"ts_atm_subsection": "",
"ts_grid": "180x360_aave",
"ts_land_grid": "180x360_aave",
"ts_land_subsection": "",
"ts_num_years": 5,
"ts_subsection": "",
"vars": "FSNTOA,FLUT,FSNT,FLNT,FSNS,FLNS,SHFLX,QFLX,PRECC,PRECL,PRECSC,PRECSL,TS,TREFHT",
"walltime": "02:00:00",
"www": "WWWW",
Expand Down Expand Up @@ -446,7 +482,13 @@ def test_subsections():
"reservation": "",
"subsection": "climo_grid1",
"templateDir": "zppy/templates",
"ts_atm_grid": "180x360_aave",
"ts_atm_subsection": "",
"ts_grid": "180x360_aave",
"ts_land_grid": "180x360_aave",
"ts_land_subsection": "",
"ts_num_years": 5,
"ts_subsection": "",
"vars": "",
"walltime": "02:00:00",
"www": "WWWW",
Expand Down Expand Up @@ -484,7 +526,13 @@ def test_subsections():
"qos": "regular",
"subsection": "climo_grid2",
"templateDir": "zppy/templates",
"ts_atm_grid": "180x360_aave",
"ts_atm_subsection": "",
"ts_grid": "180x360_aave",
"ts_land_grid": "180x360_aave",
"ts_land_subsection": "",
"ts_num_years": 5,
"ts_subsection": "",
"vars": "",
"walltime": "02:00:00",
"www": "WWWW",
Expand Down
194 changes: 194 additions & 0 deletions tests/test_zppy_e3sm_to_cmip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
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():

# 1. ts_grid is set explictily
c = {"ts_grid": "grid"}
check_parameters_for_bash(c)

# 2. ts_grid can't be set because an empty string is provided
c = {"ts_grid": ""}
with pytest.raises(ParameterNotProvidedError):
check_parameters_for_bash(c)

# 3. ts_grid is set via ts_atm_grid
c = {"component": "atm", "ts_atm_grid": "atm_grid"}
check_parameters_for_bash(c)
# 4. ts_grid is set via ts_land_grid
c = {"component": "lnd", "ts_land_grid": "land_grid"}
check_parameters_for_bash(c)

# 5. ts_grid can't be set via ts_land_grid since component is atm
c = {"component": "atm", "ts_land_grid": "land_grid"}
with pytest.raises(ParameterNotProvidedError):
check_parameters_for_bash(c)
# 6. ts_grid can't be set via ts_atm_grid since component is lnd
c = {"component": "lnd", "ts_atm_grid": "atm_grid"}
with pytest.raises(ParameterNotProvidedError):
check_parameters_for_bash(c)

# 7. ts_grid can't be set via ts_atm_grid since component isn't specified
c = {"ts_atm_grid": "atm_grid"}
with pytest.raises(ParameterNotProvidedError):
check_parameters_for_bash(c)
# 8. ts_grid can't be set via ts_land_grid since component isn't specified
c = {"ts_land_grid": "land_grid"}
with pytest.raises(ParameterNotProvidedError):
check_parameters_for_bash(c)

# 9. ts_grid can't be set because ts_atm_grid is set to the empty string
c = {"component": "atm", "ts_atm_grid": ""}
with pytest.raises(ParameterNotProvidedError):
check_parameters_for_bash(c)
# 10. ts_grid can't be set because ts_land_grid is set to the empty string
c = {"component": "lnd", "ts_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 ####################################################
# 1. ts_subsection is set explictily
c = {"ts_subsection": "subsection", "guess_section_parameters": True}
check_and_define_parameters(c, sub)
assert c["ts_subsection"] == "subsection"

# 2. ts_subsection is set via sub because it is initially set to the empty string
c = {"ts_subsection": "", "guess_section_parameters": True}
check_and_define_parameters(c, sub)
assert c["ts_subsection"] == "name_of_this_subsection"

# 3. ts_subsection is set via ts_atm_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"
# 4. ts_subsection is set via ts_land_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"

# 5. ts_subsection can't be set via ts_land_subsection since component is atm
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"
# 6. ts_subsection can't be set via ts_atm_subsection since component is lnd
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"

# 7. ts_subsection can't be set via ts_atm_subsection since component isn't specified
c = {"ts_atm_subsection": "atm_subsection", "guess_section_parameters": True}
check_and_define_parameters(c, sub)
assert c["ts_subsection"] == "name_of_this_subsection"
# 8. ts_subsection can't be set via ts_atm_subsection since component isn't specified
c = {"ts_land_subsection": "land_subsection", "guess_section_parameters": True}
check_and_define_parameters(c, sub)
assert c["ts_subsection"] == "name_of_this_subsection"

# 9. ts_subsection is set via sub because it is initially not provided
c = {"guess_section_parameters": True}
check_and_define_parameters(c, sub)
assert c["ts_subsection"] == "name_of_this_subsection"

# 10. ts_subsection is set via sub because it is initially not provided and component isn't specified (required to use ts_atm_subsection)
c = {"ts_atm_subsection": "", "guess_section_parameters": True}
check_and_define_parameters(c, sub)
assert c["ts_subsection"] == "name_of_this_subsection"

# 11. ts_subsection is set via sub because it is initially not provided and component isn't specified (required to use ts_land_subsection)
c = {"ts_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 ##############################################
# Repeat above cases, but with guess_section_parameters set to False

# 1
c = {"ts_subsection": "subsection", "guess_section_parameters": False}
check_and_define_parameters(c, sub)
assert c["ts_subsection"] == "subsection"

# 2
c = {"ts_subsection": "", "guess_section_parameters": False}
with pytest.raises(ParameterNotProvidedError):
check_and_define_parameters(c, sub)

# 3
c = {
"component": "atm",
"ts_atm_subsection": "atm_subsection",
"guess_section_parameters": False,
}
with pytest.raises(ParameterNotProvidedError):
check_and_define_parameters(c, sub)
# 4
c = {
"component": "lnd",
"ts_land_subsection": "land_subsection",
"guess_section_parameters": False,
}
with pytest.raises(ParameterNotProvidedError):
check_and_define_parameters(c, sub)

# 5
c = {
"component": "atm",
"ts_land_subsection": "land_subsection",
"guess_section_parameters": False,
}
with pytest.raises(ParameterNotProvidedError):
check_and_define_parameters(c, sub)
# 6
c = {
"component": "lnd",
"ts_atm_subsection": "atm_subsection",
"guess_section_parameters": False,
}
with pytest.raises(ParameterNotProvidedError):
check_and_define_parameters(c, sub)

# 7
c = {"ts_atm_subsection": "atm_subsection", "guess_section_parameters": False}
with pytest.raises(ParameterNotProvidedError):
check_and_define_parameters(c, sub)
# 8
c = {"ts_land_subsection": "land_subsection", "guess_section_parameters": False}
with pytest.raises(ParameterNotProvidedError):
check_and_define_parameters(c, sub)

# 9
c = {"guess_section_parameters": False}
with pytest.raises(ParameterNotProvidedError):
check_and_define_parameters(c, sub)

# 10
c = {"ts_atm_subsection": "", "guess_section_parameters": False}
with pytest.raises(ParameterNotProvidedError):
check_and_define_parameters(c, sub)

# 11
c = {"ts_land_subsection": "", "guess_section_parameters": False}
with pytest.raises(ParameterNotProvidedError):
check_and_define_parameters(c, sub)
34 changes: 20 additions & 14 deletions zppy/defaults/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,28 @@ plugins = force_list(default=list())
qos = string(default="regular")
# Reservation -- if you have access to a node reservation, specify it with this parameter.
reservation = string(default="")
# Use for e3sm_to_cmip and/or ilamb tasks.
# Name of the grid used by the relevant `[ts]` atm subtask
ts_atm_grid = string(default="180x360_aave")
# Use for e3sm_to_cmip and/or ilamb tasks.
# Name of the `[ts]` atm subtask to depend on
ts_atm_subsection = string(default="")
# Use for e3sm_to_cmip task (but NOT the ilamb task) -- you can either set this, or
# both ts_atm_grid and ts_land_grid
# Name of the grid used by the relevant `[ts]` task
ts_grid = string(default="180x360_aave")
# Use for e3sm_to_cmip and/or ilamb tasks.
# Name of the grid used by the relevant `[ts]` land subtask
ts_land_grid = string(default="180x360_aave")
# Use for e3sm_to_cmip and/or ilamb tasks.
# Name of the `[ts]` land subtask to depend on
ts_land_subsection = string(default="")
Comment on lines +60 to +75
Copy link
Copy Markdown
Collaborator

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_cmip subtask, rather than configuring ts_grid differently for each subtask. The intention is to eliminate redundant code/configuration.

Is this correct? If so, it sounds reasonable to me.

# The years increment from `years` in `[ts]`
ts_num_years = integer(default=5)
# Use for e3sm_to_cmip task (but NOT the ilamb task) -- you can either set this, or
# both ts_atm_subsection and ts_land_subsection
# Name of the `[ts]` subtask to depend on
ts_subsection = string(default="")
# scriptDir -- NOTE: this parameter is created internally
# templateDir -- NOTE: this parameter is created internally
# The variables to process
Expand Down Expand Up @@ -123,17 +143,11 @@ cmip_metadata = string(default="inclusions/e3sm_to_cmip/default_metadata.json")
cmip_vars = string(default="")
# Model component having generated input files (eam, eamxx, elm, mosart, ...)
input_component = string(default="")
# Name of the grid used by the relevant `[ts]` task
ts_grid = string(default="180x360_aave")
# Name of the `[ts]` subtask to depend on
ts_subsection = string(default="")

[[__many__]]
cmip_metadata = string(default=None)
cmip_vars = string(default=None)
input_component = string(default=None)
ts_grid = string(default=None)
ts_subsection = string(default=None)

[tc_analysis]
# NOTE: always overrides value in [default]
Expand Down Expand Up @@ -339,11 +353,3 @@ e3sm_to_cmip_land_subsection = string(default="")
ilamb_obs = string(default="")
# for land_only run
land_only = boolean(default=False)
# Name of the grid used by the relevant `[ts]` atm subtask
ts_atm_grid = string(default="180x360_aave")
# Name of the `[ts]` atm subtask to depend on
ts_atm_subsection = string(default="")
# Name of the grid used by the relevant `[ts]` land subtask
ts_land_grid = string(default="180x360_aave")
# Name of the `[ts]` land subtask to depend on
ts_land_subsection = string(default="")
Loading
Loading