Reputation: 11
Can xarray append or rewrite an existing NetCDF file? I need to update my data (NetCDF format) every year. I want to rewrite or append an existing NetCDF file by using xarray. However, I need to read all data into the memory and concatenate them, then overwrite the NC file. It consumes too much memory and less efficient. Is there any possibility that rewrites the file just like python library of NETCDF4?
Upvotes: 1
Views: 4269
Reputation: 481
The xarray documentation here: https://xarray.pydata.org/en/stable/io.html#reading-and-writing-files
States the following:
It is possible to append or overwrite netCDF variables using the mode='a' argument. When using this option, all variables in the dataset will be written to the original netCDF file, regardless if they exist in the original dataset.
You can add a new variable, but you cannot add data to an existing variable without re-creating it.
See also this (duplicate) question: Is it possible to append to an xarray.Dataset?
It's from a few years back, but things haven't changed. Unfortunately, you'd have to use the netCDF4 package directly instead.
Upvotes: 1