Concatenating DataArray objects lazily? #7384
-
As part of training a neural network with climate data as input, stored as netCDF files, each one containing a time series covering the same time period, I need to be able to load an arbitrary time point from each netCDF file (the same time point for each file) and concatenate those into one NumPy array. If I use iris, I can just load the netCDF files into cubes, extract a Dask array from each of those cubes, and concatenate those Dask arrays into a single, large Dask array, and since this doesn't load any of the actual data (only the metadata) into memory (RAM), it goes almost instantly. I can then extract a slice corresponding to the time point I want from the concatenated Dask array, and call compute to get the time slice as a NumPy array. Is there any similar way to do this in xarray? That is, can I load the same netCDF files and concatenate those into one xarray object of some kind, without loading anything else than metadata into memory, and then just extract a single time slice from that xarray object and first then read it to memory by requesting to get it as a NumPy array? Or do I have to load the netCDF files into separate xarray objects, extract time slices from those as separate NumPy arrays, and thus read them to memory, and then concatenate those? I have tried doing |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @krikru , you'll want to read #4628. Basically if you ensure your xarray variables are backed by dask arrays then concat should be lazy, but right now if your variables are backed by numpy arrays (i.e. they have been .load()-ed into memory) then xarray will do a lot of things lazily, but not |
Beta Was this translation helpful? Give feedback.
Hey @krikru , you'll want to read #4628. Basically if you ensure your xarray variables are backed by dask arrays then concat should be lazy, but right now if your variables are backed by numpy arrays (i.e. they have been .load()-ed into memory) then xarray will do a lot of things lazily, but not
concat
(yet).