xoceanmodel / xroms

Work with ROMS ocean model output with xarray
https://xroms.readthedocs.io/
MIT License
62 stars 39 forks source link

xgcm attrs causing problems when saving to netcdf? #23

Closed nmalan closed 3 years ago

nmalan commented 3 years ago

Hi all,

Great package! In migrating some of my workflow across from home-cooked xarray/xgcm to xroms, I have come across an issue with saving a dataset opened with xroms.open_mfnetcdf to netcdf.

When I run ds.isel(ocean_time=0).to_netcdf('filename.nc')

I get the following error to do with attributes associated with the grid object:

`TypeError: Invalid value for attr 'grid': X Axis (not periodic, boundary=None):

Has anyone else encountered this behaviour? Unfortunately I was not able to access the files used in the example notebook, so this may be a function of my particular ROMS dataset.

claudiofgcardoso commented 3 years ago

Hi,

I had the same issue. The problem is related with the attribute 'grid' that is added to the xr.Dataset after xroms processing, which cannot be saved to a netCDF. Before you export your xr.Dataset "ds", you have to delete the 'grid' attribute in ds as follows: del varout.attrs['grid']

nmalan commented 3 years ago

Thanks @claudiofgcardoso! I thought it might have been something like that, but think I was trying to delete the wrong attributes. I will give it a try.