2

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?

1 Answer 1

4

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.