diff --git a/config/nowcast.yaml b/config/nowcast.yaml index 0a1e52df..85475389 100644 --- a/config/nowcast.yaml +++ b/config/nowcast.yaml @@ -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" @@ -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 diff --git a/nowcast/workers/make_averaged_dataset.py b/nowcast/workers/make_averaged_dataset.py index eb1c8018..e9c5a470 100644 --- a/nowcast/workers/make_averaged_dataset.py +++ b/nowcast/workers/make_averaged_dataset.py @@ -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( @@ -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 diff --git a/tests/workers/test_make_averaged_dataset.py b/tests/workers/test_make_averaged_dataset.py index 55bec617..3bd3efbb 100644 --- a/tests/workers/test_make_averaged_dataset.py +++ b/tests/workers/test_make_averaged_dataset.py @@ -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" @@ -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 @@ -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/" @@ -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", @@ -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"), ), ) @@ -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"), ), ) @@ -385,6 +411,8 @@ def mock_extract_netcdf(reshapr_config, reshapr_config_yaml): ( ("month", "biology"), ("month", "chemistry"), + ("month", "grazing"), + ("month", "growth"), ("month", "physics"), ), ) @@ -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