Description
Stacking is loading the data into memory, which is unexpected, or at least undocumented, afaik.
MCVE Code Sample
import os
import psutil
import numpy as np
import xarray as xr
def main():
xr.DataArray(
np.random.randn(1024, 1024, 100),
dims=("x", "y", "z"),
).to_netcdf("da.nc")
da = xr.open_dataarray("da.nc")
print(f" da: {mb(da.nbytes)} MB")
print_ram_state()
mda = da.stack(px=("x", "y"))
print_ram_state()
def print_ram_state():
# https://stackoverflow.com/a/21632554
process = psutil.Process(os.getpid())
ram_state = process.memory_info().rss
print(f"RAM: {mb(ram_state) :.2f} MB")
def mb(nbytes):
return nbytes / (1024 * 1024)
if __name__ == "__main__":
main()
Problem Description
Using xarray.DataArray.stack
method is loading the data into memory, which is unexpected behavior, or at least undocumented afaik.
Versions
Output of xr.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.7.6 | packaged by conda-forge | (default, Mar 23 2020, 23:03:20)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 5.3.0-53-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.5
libnetcdf: None
xarray: 0.15.1
pandas: 1.0.3
numpy: 1.17.5
scipy: 1.4.1
netCDF4: None
pydap: None
h5netcdf: None
h5py: 2.10.0
Nio: None
zarr: None
cftime: None
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.3.2
dask: 2.16.0
distributed: 2.16.0
matplotlib: 3.2.1
cartopy: None
seaborn: 0.10.1
numbagg: None
setuptools: 46.4.0.post20200518
pip: 20.1.1
conda: 4.8.3
pytest: 5.4.2
IPython: 7.14.0
sphinx: 3.0.4