Skip to content

Commit 9485c93

Browse files
Fix _assign_time_coord crash when lead_time is not 1D along forecast_step (#1897)
* Fix _assign_time_coord crash when lead_time is not 1D along forecast_step * Minor changing to better check what is wrong with the lead_time coordinate --------- Co-authored-by: Savvas Melidonis <s.melidonis@fz-juelich.de> Co-authored-by: Savvas Melidonis <79579567+SavvasMel@users.noreply.github.com>
1 parent a9ff488 commit 9485c93

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

packages/evaluate/src/weathergen/evaluate/plotting/plot_utils.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,21 @@ def _assign_time_coord(selected_data: list[xr.DataArray]) -> tuple[xr.DataArray,
178178
time_dim = "lead_time"
179179

180180
for i, data in enumerate(selected_data):
181-
if data.coords["lead_time"].shape == data.coords["forecast_step"].shape:
181+
lead_time = data.coords["lead_time"]
182+
forecast_step = data.coords["forecast_step"]
183+
184+
if (
185+
lead_time.dims == forecast_step.dims
186+
and lead_time.shape == forecast_step.shape
187+
and lead_time.ndim == 1
188+
):
182189
selected_data[i] = data.swap_dims({"forecast_step": "lead_time"})
183-
190+
else:
191+
_logger.warning(
192+
"lead_time coordinate is not compatible with forecast_step for all plotted data; "
193+
"using forecast_step as x-axis."
194+
)
195+
time_dim = "forecast_step"
184196
return selected_data, time_dim
185197

186198

0 commit comments

Comments
 (0)