Skip to content

Commit 111635f

Browse files
committed
Add forecast reference time and drop velocity in output dataset
1 parent e5dff56 commit 111635f

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

pysteps/xarray_helpers.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import pyproj
2020
import xarray as xr
2121

22-
2322
# TODO(converters): Write methods for converting Proj.4 projection definitions
2423
# into CF grid mapping attributes. Currently this has been implemented for
2524
# the stereographic projection.
@@ -330,17 +329,22 @@ def convert_output_to_xarray_dataset(
330329
precip_var = dataset.attrs["precip_var"]
331330
metadata = dataset[precip_var].attrs
332331

333-
last_timestamp = (
332+
forecast_reference_time = (
334333
dataset["time"][-1].values.astype("datetime64[us]").astype(datetime)
335334
)
336335
time_metadata = dataset["time"].attrs
337336
time_encoding = dataset["time"].encoding
338337
timestep_seconds = dataset["time"].attrs["stepsize"]
339338
dataset = dataset.drop_vars([precip_var]).drop_dims(["time"])
339+
if "velocity_x" in dataset:
340+
dataset = dataset.drop_vars(["velocity_x"])
341+
if "velocity_y" in dataset:
342+
dataset = dataset.drop_vars(["velocity_y"])
340343
if isinstance(timesteps, int):
341344
timesteps = list(range(1, timesteps + 1))
342345
next_timestamps = [
343-
last_timestamp + timedelta(seconds=timestep_seconds * i) for i in timesteps
346+
forecast_reference_time + timedelta(seconds=timestep_seconds * i)
347+
for i in timesteps
344348
]
345349
dataset = dataset.assign_coords(
346350
{"time": (["time"], next_timestamps, time_metadata, time_encoding)}
@@ -364,4 +368,15 @@ def convert_output_to_xarray_dataset(
364368
else:
365369
dataset[precip_var] = (["time", "y", "x"], output, metadata)
366370

371+
dataset = dataset.assign_coords(
372+
{
373+
"forecast_reference_time": (
374+
[],
375+
forecast_reference_time,
376+
{"long_name": "forecast reference time"},
377+
time_encoding,
378+
)
379+
}
380+
)
381+
367382
return dataset

0 commit comments

Comments
 (0)