Closed morganeoneill closed 6 years ago
Hi @morganeoneill, welcome to the world of xarray!
It looks like when you create the xarray Dataset, the "projection" attribute on pvo
is being set as some sort of object, and the netCDF engine doesn't know how to write it to a file. I'm not familiar with wrf-python, so maybe it's a special map projection object that the package uses internally for some sort of plotting or other function?
Regardless, the easiest solution is just to drop that attribute. You can try something like
del dataset['pvo'].attrs['projection']
Since your dataset has 2D coordinates for longitude and latitude (XLONG
and XLAT
), you may not need that projection information for anything. If it's something you definitely need to keep, you may want to try to decode the wrf-python 'Mercator' object into a string or something else - strings are totally fine to save as attributes on Datasets or DataArrays, and should serialize to NetCDF without any problem.
Excellent, that's so simple! I don't know what I'd need it for, and I certainly don't need it for cursorily zooming around in ncview. Thanks a lot @darothen-cc, you're wicked fast!
Note that the XLAT XLON coordinates of WRF files are not sufficient to retrieve the WRF projection in the current format of your dataset.
wrf-python or salem need the original dataset attributes to parse the projection information (STAND_LON, TRUELAT1 & 2, etc). wrf-python should probably store their projection as a string rather than an object, though.
I'm brand new (TODAY) to xarray, so I'm not going to use the right lingo... I want to save a wrf diagnostic variable 'pvo' (https://wrf-python.readthedocs.io/en/latest/diagnostics.html#diagnostic-table) to its own new netcdf file.
Looks great, let's save it (am I doing this right?)
It breaks and complains about the projection attribute:
Do I have to chop up, rework or remove the projection attribute? Surely these diagnostic variables are immediately ready to save as complete netcdf variables, what am I doing wrong?
Thank you!