Skip to content

Commit

Permalink
Drop uses of 'wave_forecast_after' missed in 3e332b2
Browse files Browse the repository at this point in the history
  • Loading branch information
douglatornell committed Nov 15, 2023
1 parent 3e332b2 commit c22ffb3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 94 deletions.
1 change: 0 additions & 1 deletion nowcast/next_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,6 @@ def after_watch_NEMO(msg, config, checklist):
race_condition_workers = {}
if msg.type.startswith("success"):
run_type = msg.type.split()[1]
wave_forecast_after = config["wave forecasts"]["run when"].split("after ")[1]
if run_type == "nowcast":
next_workers[msg.type].extend(
[
Expand Down
21 changes: 6 additions & 15 deletions nowcast/workers/make_ww3_current_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,13 @@ def make_ww3_current_file(parsed_args, config, *args):
mesh_mask = os.fspath(grid_dir / config["run types"]["nowcast"]["mesh mask"])
nemo_dir = Path(host_config["run types"]["nowcast"]["results"]).parent
nemo_file_tmpl = config["wave forecasts"]["NEMO file template"]
wave_forecast_after = config["wave forecasts"]["run when"].split("after ")[1]
dest_dir = Path(config["wave forecasts"]["run prep dir"], "current")
filepath_tmpl = config["wave forecasts"]["current file template"]
nc_filepath = dest_dir / filepath_tmpl.format(yyyymmdd=run_date.format("YYYYMMDD"))
if run_type in {"nowcast", "forecast"}:
datasets = _calc_nowcast_datasets(
run_date, nemo_dir, nemo_file_tmpl, wave_forecast_after
)
datasets = _calc_nowcast_datasets(run_date, nemo_dir, nemo_file_tmpl)
if run_type == "forecast":
datasets.update(
_calc_forecast_datasets(
run_date, nemo_dir, nemo_file_tmpl, wave_forecast_after
)
)
datasets.update(_calc_forecast_datasets(run_date, nemo_dir, nemo_file_tmpl))
if run_type == "forecast2":
datasets = _calc_forecast2_datasets(
run_date, nemo_dir, nemo_file_tmpl, dest_dir
Expand Down Expand Up @@ -185,15 +178,14 @@ def make_ww3_current_file(parsed_args, config, *args):
return checklist


def _calc_nowcast_datasets(run_date, nemo_dir, nemo_file_tmpl, wave_forecast_after):
def _calc_nowcast_datasets(run_date, nemo_dir, nemo_file_tmpl):
datasets = {"u": [], "v": []}
nemo_results = "nowcast" if wave_forecast_after == "forecast" else "nowcast-green"
dmy = run_date.format("DDMMMYY").lower()
s_yyyymmdd = e_yyyymmdd = run_date.format("YYYYMMDD")
for grid in datasets:
nowcast_file = (
nemo_dir
/ Path(nemo_results, dmy)
/ Path("nowcast", dmy)
/ nemo_file_tmpl.format(
s_yyyymmdd=s_yyyymmdd, e_yyyymmdd=e_yyyymmdd, grid=grid.upper()
)
Expand All @@ -203,15 +195,14 @@ def _calc_nowcast_datasets(run_date, nemo_dir, nemo_file_tmpl, wave_forecast_aft
return datasets


def _calc_forecast_datasets(run_date, nemo_dir, nemo_file_tmpl, wave_forecast_after):
def _calc_forecast_datasets(run_date, nemo_dir, nemo_file_tmpl):
datasets = {"u": [], "v": []}
nemo_results = "nowcast" if wave_forecast_after == "forecast" else "nowcast-green"
dmy = run_date.format("DDMMMYY").lower()
s_yyyymmdd = e_yyyymmdd = run_date.format("YYYYMMDD")
for grid in datasets:
nowcast_file = (
nemo_dir
/ Path(nemo_results, dmy)
/ Path("nowcast", dmy)
/ nemo_file_tmpl.format(
s_yyyymmdd=s_yyyymmdd, e_yyyymmdd=e_yyyymmdd, grid=grid.upper()
)
Expand Down
82 changes: 4 additions & 78 deletions tests/workers/test_make_ww3_current_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ def test_checklist(
arrow.get("2017-04-12"),
Path("/nemoShare/MEOPAR/SalishSea/"),
"SalishSea_1h_{s_yyyymmdd}_{e_yyyymmdd}_grid_{grid}.nc",
"nowcast-green",
),
),
(
Expand All @@ -273,7 +272,6 @@ def test_checklist(
arrow.get("2017-04-12"),
Path("/nemoShare/MEOPAR/SalishSea/"),
"SalishSea_1h_{s_yyyymmdd}_{e_yyyymmdd}_grid_{grid}.nc",
"nowcast-green",
),
),
],
Expand Down Expand Up @@ -348,46 +346,14 @@ def test_mesh_mask_dataset(
class TestCalcNowcastDatasets:
"""Unit tests for _calc_nowcast_datasets() function."""

def test_nowcast_datasets_after_nowcast_green(self, caplog):
def test_calc_nowcast_datasets(self, caplog):
run_date = arrow.get("2023-03-16")
nemo_dir = Path("/nemoShare/MEOPAR/SalishSea/")
nemo_file_tmpl = "SalishSea_1h_{s_yyyymmdd}_{e_yyyymmdd}_grid_{grid}.nc"
wave_forecast_after = "nowcast-green"
caplog.set_level("DEBUG")

datasets = make_ww3_current_file._calc_nowcast_datasets(
run_date, nemo_dir, nemo_file_tmpl, wave_forecast_after
)

assert datasets == {
"u": [
Path(
"/nemoShare/MEOPAR/SalishSea/nowcast-green/16mar23/SalishSea_1h_20230316_20230316_grid_U.nc"
)
],
"v": [
Path(
"/nemoShare/MEOPAR/SalishSea/nowcast-green/16mar23/SalishSea_1h_20230316_20230316_grid_V.nc"
)
],
}
expected = [
"u dataset: /nemoShare/MEOPAR/SalishSea/nowcast-green/16mar23/SalishSea_1h_20230316_20230316_grid_U.nc",
"v dataset: /nemoShare/MEOPAR/SalishSea/nowcast-green/16mar23/SalishSea_1h_20230316_20230316_grid_V.nc",
]
for i in range(len(expected)):
assert caplog.records[i].levelname == "DEBUG"
assert caplog.messages[i] == expected[i]

def test_nowcast_datasets_after_forecast(self, caplog):
run_date = arrow.get("2023-03-16")
nemo_dir = Path("/nemoShare/MEOPAR/SalishSea/")
nemo_file_tmpl = "SalishSea_1h_{s_yyyymmdd}_{e_yyyymmdd}_grid_{grid}.nc"
wave_forecast_after = "forecast"
caplog.set_level("DEBUG")

datasets = make_ww3_current_file._calc_nowcast_datasets(
run_date, nemo_dir, nemo_file_tmpl, wave_forecast_after
run_date, nemo_dir, nemo_file_tmpl
)

assert datasets == {
Expand All @@ -414,54 +380,14 @@ def test_nowcast_datasets_after_forecast(self, caplog):
class TestCalcForecastDatasets:
"""Unit tests for _calc_forecast_datasets() function."""

def test_forecast_datasets_after_nowcast_green(self, caplog):
run_date = arrow.get("2023-03-16")
nemo_dir = Path("/nemoShare/MEOPAR/SalishSea/")
nemo_file_tmpl = "SalishSea_1h_{s_yyyymmdd}_{e_yyyymmdd}_grid_{grid}.nc"
wave_forecast_after = "nowcast-green"
caplog.set_level("DEBUG")

datasets = make_ww3_current_file._calc_forecast_datasets(
run_date, nemo_dir, nemo_file_tmpl, wave_forecast_after
)

assert datasets == {
"u": [
Path(
"/nemoShare/MEOPAR/SalishSea/nowcast-green/16mar23/SalishSea_1h_20230316_20230316_grid_U.nc"
),
Path(
"/nemoShare/MEOPAR/SalishSea/forecast/16mar23/SalishSea_1h_20230317_20230318_grid_U.nc"
),
],
"v": [
Path(
"/nemoShare/MEOPAR/SalishSea/nowcast-green/16mar23/SalishSea_1h_20230316_20230316_grid_V.nc"
),
Path(
"/nemoShare/MEOPAR/SalishSea/forecast/16mar23/SalishSea_1h_20230317_20230318_grid_V.nc"
),
],
}
expected = [
"u dataset: /nemoShare/MEOPAR/SalishSea/nowcast-green/16mar23/SalishSea_1h_20230316_20230316_grid_U.nc",
"v dataset: /nemoShare/MEOPAR/SalishSea/nowcast-green/16mar23/SalishSea_1h_20230316_20230316_grid_V.nc",
"u dataset: /nemoShare/MEOPAR/SalishSea/forecast/16mar23/SalishSea_1h_20230317_20230318_grid_U.nc",
"v dataset: /nemoShare/MEOPAR/SalishSea/forecast/16mar23/SalishSea_1h_20230317_20230318_grid_V.nc",
]
for i in range(len(expected)):
assert caplog.records[i].levelname == "DEBUG"
assert caplog.messages[i] == expected[i]

def test_forecast_datasets_after_forecast(self, caplog):
def test_calc_forecast_datasets(self, caplog):
run_date = arrow.get("2023-03-16")
nemo_dir = Path("/nemoShare/MEOPAR/SalishSea/")
nemo_file_tmpl = "SalishSea_1h_{s_yyyymmdd}_{e_yyyymmdd}_grid_{grid}.nc"
wave_forecast_after = "forecast"
caplog.set_level("DEBUG")

datasets = make_ww3_current_file._calc_forecast_datasets(
run_date, nemo_dir, nemo_file_tmpl, wave_forecast_after
run_date, nemo_dir, nemo_file_tmpl
)

assert datasets == {
Expand Down

0 comments on commit c22ffb3

Please sign in to comment.