You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Found myself writing this just to use it.
It's pretty simple ...
slicedim_name = "time"
slicedim_len = 2
ncds.dimensions[slicedim_name].size = slicedim_len
for var in ncds.variables.values():
if slicedim_name in var.dimensions:
(i_slicedim,) = [
i for i, name in enumerate(var.dimensions)
if name == slicedim_name
]
slices = [slice(None) for dim in var.dimensions]
slices[i_slicedim] = slice(0, slicedim_len)
var.data = var.data[tuple(slices)]
Probably wants to be slightly generalised.
Maybe control with a map dim_name: dim_slice
Then new dim length can be deduced for any-old input slice something like dim.size = da.zeros(dim.size)[dim_slice].shape[0]
(using dask to avoid actually making an array)
Found myself writing this just to use it.
It's pretty simple ...
Probably wants to be slightly generalised.
Maybe control with a map
dim_name: dim_slice
Then new dim length can be deduced for any-old input slice something like
dim.size = da.zeros(dim.size)[dim_slice].shape[0]
(using dask to avoid actually making an array)
N.B. goes in a 'utilities' space : cf #64
The text was updated successfully, but these errors were encountered: