Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit be9cf18

Browse files
authored
Merge pull request #319 from openclimatefix/improvve_diff_sel
improve diff selection
2 parents 985f683 + aed3d60 commit be9cf18

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

ocf_datapipes/select/select_time_slice_nwp.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,8 @@ def __iter__(self) -> Union[xr.DataArray, xr.Dataset]:
110110
init_time_indexer = xr.DataArray(selected_init_times, coords=coords)
111111
step_indexer = xr.DataArray(steps, coords=coords)
112112

113-
# Slice out the data which does not need to be diffed
114-
xr_non_accum = xr_data.sel({self.channel_dim_name: non_accum_channels})
115-
xr_sel_non_accum = xr_non_accum.sel(step=step_indexer, init_time_utc=init_time_indexer)
116-
117113
if len(accum_channels) == 0:
118-
xr_sel = xr_sel_non_accum
114+
xr_sel = xr_data.sel(step=step_indexer, init_time_utc=init_time_indexer)
119115

120116
else:
121117
# First minimise the size of the dataset we are diffing
@@ -125,13 +121,21 @@ def __iter__(self) -> Union[xr.DataArray, xr.Dataset]:
125121
min_step = min(steps)
126122
max_step = max(steps) + (xr_data.step[1] - xr_data.step[0])
127123

128-
xr_accum = xr_data.sel(
124+
xr_min = xr_data.sel(
129125
{
130-
self.channel_dim_name: accum_channels,
131126
"init_time_utc": unique_init_times,
132127
"step": slice(min_step, max_step),
133128
}
134-
).compute()
129+
)
130+
131+
# Slice out the data which does not need to be diffed
132+
xr_non_accum = xr_min.sel({self.channel_dim_name: non_accum_channels})
133+
xr_sel_non_accum = xr_non_accum.sel(
134+
step=step_indexer, init_time_utc=init_time_indexer
135+
)
136+
137+
# Slice out the channels which need to be diffed
138+
xr_accum = xr_min.sel({self.channel_dim_name: accum_channels})
135139

136140
# Take the diff and slice requested data
137141
xr_accum = xr_accum.diff(dim="step", label="lower")

0 commit comments

Comments
 (0)