Is it also possible to create an out-of-core DataArray, and write it chunk-by-chunk to a NetCDF4 file using xarray?
For example, I want to be able to do this in an out-of-core fashion when the dimensions are much bigger and I thus cannot store the whole array in memory:
num_steps = 20
num_times = 100
#Create DataArray
d = xr.DataArray(np.zeros([num_steps, num_times], np.float32),
{'Step': np.arange(num_steps),
'Time': np.arange(num_times)},
('Step', 'Time'))
#Computatation
for i in range(num_steps):
d[i, :] = i
#Write to file
d.to_netcdf('test.nc')
So I don't want to have to create the whole NumPy array in memory, and I want the Computation and Write to file stages to be done one chunk at a time (chunked over the Step dimension in this example).
Update: It seems (from @jhamman's answer) that it may not be possible to implement my example above using xarray. I am mainly interested in developing a greater understanding of out-of-core computation with xarray, so I do not have a specific computation that I am asking about, but, since I have been asked for a more complicated example, one potential application I have is:
for i in range(num_steps):
u[:] = f(u)
s[:] = g(s)
d[i, :] = u[:] * s[:]
where u and s are xr.DataArrays of dimension Time, and f and g are PDE solvers that only depend on the input array from the previous step. Let's say there are 1000 steps, but the Time dimension is so big that I can only store one or two in memory, so assignments to d must be written to disk and then the associated memory freed.