Skip to content

Commit

Permalink
Add month-avg grazing and growth to automation
Browse files Browse the repository at this point in the history
Expanded the next_workers module to calculate month-average grazing and growth
datasets at month-end. Added corresponding test functions to ensure the new
make_averaged_dataset worker instances are launched correctly.
  • Loading branch information
douglatornell committed Sep 26, 2024
1 parent e8964c3 commit fd67210
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
31 changes: 31 additions & 0 deletions nowcast/next_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,8 @@ def after_make_averaged_dataset(msg, config, checklist):
"crash": [],
"failure day biology": [],
"failure day chemistry": [],
"failure day grazing": [],
"failure day growth": [],
"failure day physics": [],
"failure month biology": [],
"failure month chemistry": [],
Expand All @@ -1566,6 +1568,8 @@ def after_make_averaged_dataset(msg, config, checklist):
"success day physics": [],
"success month biology": [],
"success month chemistry": [],
"success month grazing": [],
"success month growth": [],
"success month physics": [],
}
if msg.type.startswith("success day"):
Expand All @@ -1580,6 +1584,33 @@ def after_make_averaged_dataset(msg, config, checklist):
host="localhost",
)
)
if msg.type.startswith("success month"):
*_, reshapr_var_group = msg.type.split()
match reshapr_var_group:
case "physics":
run_date = arrow.get(msg.payload["month physics"]["run date"]).format(
"YYYY-MM-DD"
)
next_workers[msg.type].append(
NextWorker(
"nowcast.workers.make_averaged_dataset",
args=["month", "grazing", "--run-date", run_date],
host="localhost",
)
)
case "grazing":
run_date = arrow.get(msg.payload["month grazing"]["run date"]).format(
"YYYY-MM-DD"
)
next_workers[msg.type].append(
NextWorker(
"nowcast.workers.make_averaged_dataset",
args=["month", "growth", "--run-date", run_date],
host="localhost",
)
)
case _:
pass
return next_workers[msg.type]


Expand Down
42 changes: 41 additions & 1 deletion tests/test_next_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2216,10 +2216,12 @@ class TestAfterMakeAveragedDataset:
"crash",
"failure day biology",
"failure day chemistry",
"failure day grazing",
"failure day growth",
"failure day physics",
"success month biology",
"success month chemistry",
"success month physics",
"success month growth",
"failure month biology",
"failure month chemistry",
"failure month physics",
Expand Down Expand Up @@ -2261,6 +2263,44 @@ def test_month_end_day_success_launch_month_average(
)
assert expected in workers

def test_month_physics_success_launch_month_grazing(self, config, checklist):
msg = Message(
"make_averaged_dataset",
"success month physics",
payload={
"month physics": {
"run date": "2024-09-01",
"file path": "SalishSea_1m_20240901_20240930_grid_T.nc",
}
},
)
workers = next_workers.after_make_averaged_dataset(msg, config, checklist)
expected = NextWorker(
"nowcast.workers.make_averaged_dataset",
args=["month", "grazing", "--run-date", "2024-09-01"],
host="localhost",
)
assert expected in workers

def test_month_grazing_success_launch_month_growth(self, config, checklist):
msg = Message(
"make_averaged_dataset",
"success month grazing",
payload={
"month grazing": {
"run date": "2024-09-01",
"file path": "SalishSea_1m_20240901_20240930_graz_T.nc",
}
},
)
workers = next_workers.after_make_averaged_dataset(msg, config, checklist)
expected = NextWorker(
"nowcast.workers.make_averaged_dataset",
args=["month", "growth", "--run-date", "2024-09-01"],
host="localhost",
)
assert expected in workers


class TestAfterArchiveTarball:
"""Unit tests for the after_archive_tarball function."""
Expand Down

0 comments on commit fd67210

Please sign in to comment.