Skip to content

Commit

Permalink
Add support for month-avgs of grazing & growth var groups
Browse files Browse the repository at this point in the history
Extended the make_averaged_dataset worker and related test cases to include
grazing and growth dataset variable groups. Updated configuration files and
added parameter-specific validations for these new variable groups.
  • Loading branch information
douglatornell committed Sep 24, 2024
1 parent ed78ba0 commit ce694e2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
10 changes: 10 additions & 0 deletions config/nowcast.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ averaged datasets:
chemistry:
reshapr config: month-average_202111_chemistry.yaml
file pattern: "SalishSeaCast_1m_chem_T_{yyyymmdd}_{yyyymmdd}.nc"
grazing:
reshapr config: month-average_202111_grazing_mortality.yaml
file pattern: "SalishSeaCast_1m_graz_T_{yyyymmdd}_{yyyymmdd}.nc"
growth:
reshapr config: month-average_202111_bio_growth_rates.yaml
file pattern: "SalishSeaCast_1m_prod_T_{yyyymmdd}_{yyyymmdd}.nc"
physics:
reshapr config: month-average_202111_physics.yaml
file pattern: "SalishSeaCast_1m_grid_T_{yyyymmdd}_{yyyymmdd}.nc"
Expand Down Expand Up @@ -1587,6 +1593,10 @@ message registry:
failure month biology: biology dataset month-averaging failed
success month chemistry: chemistry dataset month-averaged
failure month chemistry: chemistry dataset month-averaging failed
success month grazing: grazing dataset month-averaged
failure month grazing: grazing dataset month-averaging failed
success month growth: biology growth rates dataset month-averaged
failure month growth: biology growth rates dataset month-averaging failed
success month physics: physics dataset month-averaged
failure month physics: physics dataset month-averaging failed
crash: make_averaged_dataset worker crashed
Expand Down
8 changes: 7 additions & 1 deletion nowcast/workers/make_averaged_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def main():
)
worker.cli.add_argument(
"reshapr_var_group",
choices={"biology", "chemistry", "physics"},
choices={"biology", "chemistry", "grazing", "growth", "physics"},
help="Dataset variable group to run extraction for",
)
worker.cli.add_date_option(
Expand Down Expand Up @@ -154,6 +154,12 @@ def make_averaged_dataset(parsed_args, config, *args):
f"run_date = {run_date.format('YYYY-MM-DD')}"
)
raise WorkerError
if avg_time_interval == "day" and reshapr_var_group in {"grazing", "growth"}:
logger.error(
f"Day-average {reshapr_var_group} datasets are calculated by NEMO; "
f"use this worker for month-averaging"
)
raise WorkerError
reshapr_config_dir = Path(config["averaged datasets"]["reshapr config dir"])
reshapr_config_yaml = config["averaged datasets"][avg_time_interval][
reshapr_var_group
Expand Down
49 changes: 48 additions & 1 deletion tests/workers/test_make_averaged_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def config(base_config):
chemistry:
reshapr config: month-average_202111_chemistry.yaml
file pattern: "SalishSeaCast_1m_chem_T_{yyyymmdd}_{yyyymmdd}.nc"
grazing:
reshapr config: month-average_202111_grazing_mortality.yaml
file pattern: "SalishSeaCast_1m_graz_T_{yyyymmdd}_{yyyymmdd}.nc"
growth:
reshapr config: month-average_202111_bio_growth_rates.yaml
file pattern: "SalishSeaCast_1m_prod_T_{yyyymmdd}_{yyyymmdd}.nc"
physics:
reshapr config: month-average_202111_physics.yaml
file pattern: "SalishSeaCast_1m_grid_T_{yyyymmdd}_{yyyymmdd}.nc"
Expand Down Expand Up @@ -100,6 +106,8 @@ def test_add_reshapr_var_group_arg(self, mock_worker):
assert worker.cli.parser._actions[4].choices == {
"biology",
"chemistry",
"grazing",
"growth",
"physics",
}
assert worker.cli.parser._actions[4].help
Expand Down Expand Up @@ -142,12 +150,16 @@ def test_message_registry_keys(self, prod_config):
"failure month biology",
"success month chemistry",
"failure month chemistry",
"success month grazing",
"failure month grazing",
"success month growth",
"failure month growth",
"success month physics",
"failure month physics",
"crash",
]

def test_averaged_datasets(self, prod_config):
def test_reshapr_configs(self, prod_config):
averaged_datasets = prod_config["averaged datasets"]
expected = "/SalishSeaCast/SalishSeaNowcast/config/reshapr/"

Expand Down Expand Up @@ -196,6 +208,16 @@ def test_day_averaged_datasets(
"month-average_202111_chemistry.yaml",
"SalishSeaCast_1m_chem_T_{yyyymmdd}_{yyyymmdd}.nc",
),
(
"grazing",
"month-average_202111_grazing_mortality.yaml",
"SalishSeaCast_1m_graz_T_{yyyymmdd}_{yyyymmdd}.nc",
),
(
"growth",
"month-average_202111_bio_growth_rates.yaml",
"SalishSeaCast_1m_prod_T_{yyyymmdd}_{yyyymmdd}.nc",
),
(
"physics",
"month-average_202111_physics.yaml",
Expand Down Expand Up @@ -247,6 +269,8 @@ def test_day_average_success(self, avg_time_interval, reshapr_var_group, caplog)
(
("month", "biology"),
("month", "chemistry"),
("month", "grazing"),
("month", "growth"),
("month", "physics"),
),
)
Expand Down Expand Up @@ -301,6 +325,8 @@ def test_day_average_failure(self, avg_time_interval, reshapr_var_group, caplog)
(
("month", "biology"),
("month", "chemistry"),
("month", "grazing"),
("month", "growth"),
("month", "physics"),
),
)
Expand Down Expand Up @@ -385,6 +411,8 @@ def mock_extract_netcdf(reshapr_config, reshapr_config_yaml):
(
("month", "biology"),
("month", "chemistry"),
("month", "grazing"),
("month", "growth"),
("month", "physics"),
),
)
Expand Down Expand Up @@ -446,3 +474,22 @@ def test_bad_month_avg_run_date(self, caplog, config):
assert caplog.records[0].levelname == "ERROR"
expected = f"Month-averaging must start on the first day of a month but run_date = 2022-11-10"
assert caplog.messages[0] == expected

@pytest.mark.parametrize("reshapr_var_group", ("grazing", "growth"))
def test_month_avg_only_var_groups(self, reshapr_var_group, caplog, config):
parsed_args = SimpleNamespace(
avg_time_interval="day",
run_date=arrow.get("2024-09-24"),
reshapr_var_group=reshapr_var_group,
)
caplog.set_level(logging.DEBUG)

with pytest.raises(WorkerError):
make_averaged_dataset.make_averaged_dataset(parsed_args, config)

assert caplog.records[0].levelname == "ERROR"
expected = (
f"Day-average {reshapr_var_group} datasets are calculated by NEMO; "
f"use this worker for month-averaging"
)
assert caplog.messages[0] == expected

0 comments on commit ce694e2

Please sign in to comment.