Hi all, I'm looking for suggestions for a cleaner way of changing the coordinate axis of a DataArray I compute from NetCDF data.
I have a netCDF dataset with lat and latb coordinate labels. lat is cell centres (the coordinate axis of my data variables), latb is cell edges. len(latb) = len(lat)+1. To calculate finite differences I need the difference across a cell which is given by the diff of the latb values, the result of which will be centered on lat points.
The problem is dlat = data.latb.diff('latb') has coordinate latb, but this latb is inconsistent with my original data as it is now 1 shorter. I want to remap it to lat which has the correct length and positional alignment with my dataset. The solution I came up with is:
dlat = xarray.DataArray(data.latb.diff('latb').values*np.pi/180, coords=[('lat', data.lat)])*a
but this is ugly, and fragile, as it assumes only one dimensional input.
Essentially, I want to wholesale replace the name and values of a coordinate axis in-place. Is there a better way to do this?