Skip to content

Commit e241259

Browse files
committed
Fix clim steps for bc runs
1 parent 162e8c8 commit e241259

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

src/pproc/schema/deriver.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,17 @@ def _range(fc_request: dict, clim_steps: list[int]) -> str:
211211
def _instantaneous(fc_request: dict, clim_steps: list[int]) -> list[int]:
212212
time = int(fc_request["time"]) // 100
213213
steps = fc_request["step"]
214-
if time in [12, 18]:
215-
return [
216-
(step - 12) if step == clim_steps[-1] else step + 12 for step in steps
217-
]
218-
return steps
214+
# Match on valid time. Reforecast assumed to run at 00UTC only
215+
matched_steps = []
216+
for step in steps:
217+
valid_time = step + time
218+
if valid_time > clim_steps[-1] and time == 12:
219+
# This rule only applies to 12UTC runs
220+
valid_time = step - time
221+
if valid_time not in clim_steps:
222+
raise ValueError(f"Required step {valid_time} not in climatology steps")
223+
matched_steps.append(valid_time)
224+
return matched_steps
219225

220226
def derive(self, request: dict, clim_steps: list[str]) -> int | str:
221227
return getattr(ClimStepDeriver, f"_{self.type_}")(request, clim_steps)

tests/schema/test_deriver.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,31 @@ def test_forecast_step_deriver(config, output_request, fc_steps, expected):
162162
[
163163
[
164164
"instantaneous",
165-
["0000", "0600"],
166-
[12, 24, 360],
167-
list(range(0, 361, 12)),
168-
[12, 24, 360],
165+
["0000"],
166+
[0, 6, 12, 18, 24, 354, 360],
167+
list(range(0, 361, 6)),
168+
[0, 6, 12, 18, 24, 354, 360],
169169
],
170170
[
171171
"instantaneous",
172-
["1200", "1800"],
173-
[12, 24, 360],
174-
list(range(0, 361, 12)),
175-
[24, 36, 348],
172+
["0600"],
173+
[0, 6, 12, 18, 24, 138],
174+
list(range(0, 361, 6)),
175+
[6, 12, 18, 24, 30, 144],
176+
],
177+
[
178+
"instantaneous",
179+
["1200"],
180+
[0, 6, 12, 18, 24, 354, 360],
181+
list(range(0, 361, 6)),
182+
[12, 18, 24, 30, 36, 342, 348],
183+
],
184+
[
185+
"instantaneous",
186+
["1800"],
187+
[0, 6, 12, 18, 24, 138],
188+
list(range(0, 361, 6)),
189+
[18, 24, 30, 36, 42, 156],
176190
],
177191
[
178192
"range",

0 commit comments

Comments
 (0)