Skip to content

Commit ce694e2

Browse files
committed
Add support for month-avgs of grazing & growth var groups
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.
1 parent ed78ba0 commit ce694e2

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

config/nowcast.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,12 @@ averaged datasets:
442442
chemistry:
443443
reshapr config: month-average_202111_chemistry.yaml
444444
file pattern: "SalishSeaCast_1m_chem_T_{yyyymmdd}_{yyyymmdd}.nc"
445+
grazing:
446+
reshapr config: month-average_202111_grazing_mortality.yaml
447+
file pattern: "SalishSeaCast_1m_graz_T_{yyyymmdd}_{yyyymmdd}.nc"
448+
growth:
449+
reshapr config: month-average_202111_bio_growth_rates.yaml
450+
file pattern: "SalishSeaCast_1m_prod_T_{yyyymmdd}_{yyyymmdd}.nc"
445451
physics:
446452
reshapr config: month-average_202111_physics.yaml
447453
file pattern: "SalishSeaCast_1m_grid_T_{yyyymmdd}_{yyyymmdd}.nc"
@@ -1587,6 +1593,10 @@ message registry:
15871593
failure month biology: biology dataset month-averaging failed
15881594
success month chemistry: chemistry dataset month-averaged
15891595
failure month chemistry: chemistry dataset month-averaging failed
1596+
success month grazing: grazing dataset month-averaged
1597+
failure month grazing: grazing dataset month-averaging failed
1598+
success month growth: biology growth rates dataset month-averaged
1599+
failure month growth: biology growth rates dataset month-averaging failed
15901600
success month physics: physics dataset month-averaged
15911601
failure month physics: physics dataset month-averaging failed
15921602
crash: make_averaged_dataset worker crashed

nowcast/workers/make_averaged_dataset.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def main():
5454
)
5555
worker.cli.add_argument(
5656
"reshapr_var_group",
57-
choices={"biology", "chemistry", "physics"},
57+
choices={"biology", "chemistry", "grazing", "growth", "physics"},
5858
help="Dataset variable group to run extraction for",
5959
)
6060
worker.cli.add_date_option(
@@ -154,6 +154,12 @@ def make_averaged_dataset(parsed_args, config, *args):
154154
f"run_date = {run_date.format('YYYY-MM-DD')}"
155155
)
156156
raise WorkerError
157+
if avg_time_interval == "day" and reshapr_var_group in {"grazing", "growth"}:
158+
logger.error(
159+
f"Day-average {reshapr_var_group} datasets are calculated by NEMO; "
160+
f"use this worker for month-averaging"
161+
)
162+
raise WorkerError
157163
reshapr_config_dir = Path(config["averaged datasets"]["reshapr config dir"])
158164
reshapr_config_yaml = config["averaged datasets"][avg_time_interval][
159165
reshapr_var_group

tests/workers/test_make_averaged_dataset.py

+48-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ def config(base_config):
5959
chemistry:
6060
reshapr config: month-average_202111_chemistry.yaml
6161
file pattern: "SalishSeaCast_1m_chem_T_{yyyymmdd}_{yyyymmdd}.nc"
62+
grazing:
63+
reshapr config: month-average_202111_grazing_mortality.yaml
64+
file pattern: "SalishSeaCast_1m_graz_T_{yyyymmdd}_{yyyymmdd}.nc"
65+
growth:
66+
reshapr config: month-average_202111_bio_growth_rates.yaml
67+
file pattern: "SalishSeaCast_1m_prod_T_{yyyymmdd}_{yyyymmdd}.nc"
6268
physics:
6369
reshapr config: month-average_202111_physics.yaml
6470
file pattern: "SalishSeaCast_1m_grid_T_{yyyymmdd}_{yyyymmdd}.nc"
@@ -100,6 +106,8 @@ def test_add_reshapr_var_group_arg(self, mock_worker):
100106
assert worker.cli.parser._actions[4].choices == {
101107
"biology",
102108
"chemistry",
109+
"grazing",
110+
"growth",
103111
"physics",
104112
}
105113
assert worker.cli.parser._actions[4].help
@@ -142,12 +150,16 @@ def test_message_registry_keys(self, prod_config):
142150
"failure month biology",
143151
"success month chemistry",
144152
"failure month chemistry",
153+
"success month grazing",
154+
"failure month grazing",
155+
"success month growth",
156+
"failure month growth",
145157
"success month physics",
146158
"failure month physics",
147159
"crash",
148160
]
149161

150-
def test_averaged_datasets(self, prod_config):
162+
def test_reshapr_configs(self, prod_config):
151163
averaged_datasets = prod_config["averaged datasets"]
152164
expected = "/SalishSeaCast/SalishSeaNowcast/config/reshapr/"
153165

@@ -196,6 +208,16 @@ def test_day_averaged_datasets(
196208
"month-average_202111_chemistry.yaml",
197209
"SalishSeaCast_1m_chem_T_{yyyymmdd}_{yyyymmdd}.nc",
198210
),
211+
(
212+
"grazing",
213+
"month-average_202111_grazing_mortality.yaml",
214+
"SalishSeaCast_1m_graz_T_{yyyymmdd}_{yyyymmdd}.nc",
215+
),
216+
(
217+
"growth",
218+
"month-average_202111_bio_growth_rates.yaml",
219+
"SalishSeaCast_1m_prod_T_{yyyymmdd}_{yyyymmdd}.nc",
220+
),
199221
(
200222
"physics",
201223
"month-average_202111_physics.yaml",
@@ -247,6 +269,8 @@ def test_day_average_success(self, avg_time_interval, reshapr_var_group, caplog)
247269
(
248270
("month", "biology"),
249271
("month", "chemistry"),
272+
("month", "grazing"),
273+
("month", "growth"),
250274
("month", "physics"),
251275
),
252276
)
@@ -301,6 +325,8 @@ def test_day_average_failure(self, avg_time_interval, reshapr_var_group, caplog)
301325
(
302326
("month", "biology"),
303327
("month", "chemistry"),
328+
("month", "grazing"),
329+
("month", "growth"),
304330
("month", "physics"),
305331
),
306332
)
@@ -385,6 +411,8 @@ def mock_extract_netcdf(reshapr_config, reshapr_config_yaml):
385411
(
386412
("month", "biology"),
387413
("month", "chemistry"),
414+
("month", "grazing"),
415+
("month", "growth"),
388416
("month", "physics"),
389417
),
390418
)
@@ -446,3 +474,22 @@ def test_bad_month_avg_run_date(self, caplog, config):
446474
assert caplog.records[0].levelname == "ERROR"
447475
expected = f"Month-averaging must start on the first day of a month but run_date = 2022-11-10"
448476
assert caplog.messages[0] == expected
477+
478+
@pytest.mark.parametrize("reshapr_var_group", ("grazing", "growth"))
479+
def test_month_avg_only_var_groups(self, reshapr_var_group, caplog, config):
480+
parsed_args = SimpleNamespace(
481+
avg_time_interval="day",
482+
run_date=arrow.get("2024-09-24"),
483+
reshapr_var_group=reshapr_var_group,
484+
)
485+
caplog.set_level(logging.DEBUG)
486+
487+
with pytest.raises(WorkerError):
488+
make_averaged_dataset.make_averaged_dataset(parsed_args, config)
489+
490+
assert caplog.records[0].levelname == "ERROR"
491+
expected = (
492+
f"Day-average {reshapr_var_group} datasets are calculated by NEMO; "
493+
f"use this worker for month-averaging"
494+
)
495+
assert caplog.messages[0] == expected

0 commit comments

Comments
 (0)