This is working well for me so far (much easier than using the netCDF4 module!), with two exceptions:
1) I'm unable to rename the variable of the deep copied Dataset using the rename() function. I call the rename() function and no error is raised, however the resulting variable in the output NetCDF still has the original variable's name. Also when I look at the variable in a debugger after the function has been called the old name is still shown. For example the original variable name is 'prcp', and I attempt to rename the variable in the copy (output_dataset) like so:
2) I can't update the '_FillValue' attribute of the variable, and when I try to do so I get a hard error which crashes my program. If I update the attributes without including '_FillValue' then all is well. Below is the stack trace:
ERROR:__main__:Failed to complete
Traceback (most recent call last):
File "C:\home\eclipse_workspaces\default\climate_indicators\src\monthly_nclimgrid.py", line 75, in <module>
dataset.to_netcdf(output_file)
File "C:\Anaconda\lib\site-packages\xray\core\dataset.py", line 881, in to_netcdf
engine=engine, encoding=encoding)
File "C:\Anaconda\lib\site-packages\xray\backends\api.py", line 352, in to_netcdf
dataset.dump_to_store(store, sync=sync, encoding=encoding)
File "C:\Anaconda\lib\site-packages\xray\core\dataset.py", line 827, in dump_to_store
store.store(variables, attrs, check_encoding)
File "C:\Anaconda\lib\site-packages\xray\backends\common.py", line 226, in store
cf_variables, cf_attrs = cf_encoder(variables, attributes)
File "C:\Anaconda\lib\site-packages\xray\conventions.py", line 1022, in cf_encoder
for k, v in iteritems(variables))
File "C:\Anaconda\lib\collections.py", line 57, in __init__
self.__update(*args, **kwds)
File "C:\Anaconda\lib\_abcoll.py", line 571, in update
for key, value in other:
File "C:\Anaconda\lib\site-packages\xray\conventions.py", line 1022, in <genexpr>
for k, v in iteritems(variables))
File "C:\Anaconda\lib\site-packages\xray\conventions.py", line 680, in encode_cf_variable
var, needs_copy = maybe_encode_fill_value(var, needs_copy)
File "C:\Anaconda\lib\site-packages\xray\conventions.py", line 580, in maybe_encode_fill_value
fill_value = pop_to(encoding, attrs, '_FillValue')
File "C:\Anaconda\lib\site-packages\xray\conventions.py", line 534, in pop_to
safe_setitem(dest, key, value)
File "C:\Anaconda\lib\site-packages\xray\conventions.py", line 522, in safe_setitem
raise ValueError('Failed hard to prevent overwriting key %r' % key)
ValueError: Failed hard to prevent overwriting key '_FillValue'