I can create variables and copy over attributes in netcdf4 like this:
out_var = hndl_out_nc.createVariable(name_var, var.datatype, var.dimensions)
out_var.setncatts({k: var.getncattr(k) for k in var.ncattrs()})
What is the corresponding version for xarray?
If var
is an xarray.DataArray
, you can put it (along with attributes) into a new xarray.Dataset
simply by writing ds[name_] = var
. Or you can construct a new DataArray piece by piece with xarray.DataArray(var.data, var.coords, var.dims, var.attrs)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.