Found this while fixing a similar bug in Iris itself : https://github.com/SciTools/iris/issues/5753
The way it was using Dask was making impossible to stream large data (or some sorts) to disk without fetching everything.
It seemed that using ncdata to save via xarray instead would be a reasonable workaround.
However, in ncdata, there was another problem :
I had believed that np.ones etc created a placeholder object that did not allocate space immediately (as noted in the previous comments on this code).
This was plain wrong !
This replaces the all-missing initial values array with a lazy one.
That means we can not do a createVariable on a Nc4DatasetLike, and then a partial write to the variable, as this originally envisaged (for compatibility with an actual file variable).
However, Iris at least, never actually does that. And in fact, there is no Nc4VariableLike.__setitem__, and never was.
Basically just fixes performance.
Could add a peak-memory test, e.g. with tracemalloc (see notes in https://github.com/SciTools/iris/issues/5753)
But I don't think it's worth adding that kind of testing just now.
This allows larger-than-memory saves.
Found this while fixing a similar bug in Iris itself : https://github.com/SciTools/iris/issues/5753 The way it was using Dask was making impossible to stream large data (or some sorts) to disk without fetching everything. It seemed that using ncdata to save via xarray instead would be a reasonable workaround.
However, in ncdata, there was another problem : I had believed that
np.ones
etc created a placeholder object that did not allocate space immediately (as noted in the previous comments on this code). This was plain wrong !This replaces the all-missing initial values array with a lazy one. That means we can not do a
createVariable
on a Nc4DatasetLike, and then a partial write to the variable, as this originally envisaged (for compatibility with an actual file variable). However, Iris at least, never actually does that. And in fact, there is noNc4VariableLike.__setitem__
, and never was.