-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Can't re-save netCDF after opening it and modifying it? #2029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The problem is that xarray is that when you open up a dataset, xarray does lazy loading of the data from the source file. This lazy loading breaks when you override the source file. As a user, the work around is to always load files entirely from disk, e.g., by calling I'm not quite sure how we should improve this, but this does certainly come up with some frequency, especially for new users. A friendlier warning/error would be nice, but I'm not sure how to detect this behavior in general (this information is not currently very accessible). We could potentially always write to temporary files in |
Thanks @shoyer! Question: I'd wondered if maybe I |
That's right, xarray will never modify a file on disk unless you use to_netcdf(). |
I assumed that using a
However this does not load into memory entirely and so lazy loading is still in effect.
|
Code Sample, copy-pastable
Problem description
I encountered this problem when opening a netCDF file, modifying it, and trying to save it back. This is with
netCDF4==1.3.1
andscipy==1.0.1
. (Potentially related: #2019?)Expected Output
If instead of
to_netcdf
overwriting the just-opened file, I write to a new file and thenos.rename
(see the three commented lines above) the new file to the original location, all is well.ncdump
reports that my change took.Output of
xr.show_versions()
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Darwin
OS-release: 17.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
xarray: 0.10.2
pandas: 0.22.0
numpy: 1.14.2
scipy: 1.0.1
netCDF4: 1.3.1
h5netcdf: None
h5py: None
Nio: None
zarr: None
bottleneck: None
cyordereddict: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
setuptools: 39.0.1
pip: 9.0.3
conda: None
pytest: None
IPython: 6.2.1
sphinx: None
The text was updated successfully, but these errors were encountered: