You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A very common operation performed with global data is to convert the longitude convention from/to [0,360] to/from [-180, 180]. This was available in NCL as lonFlip.
There are probably many ways this could be implemented. I've written this function a bunch of times. My current version assumes global data and that the data is an xarray object, and it at least seems to work:
deflonFlip(data, lonname=None):
# NOTE: this assumes global valuesiflonnameisNone:
lonname='lon'tmplon=data[lonname]
tmpdata=data.roll( {lonname: (len(tmplon) //2)}, roll_coords=True)
lonroll=tmpdata[lonname].valuesiftmplon.min() >=0:
# flip to -180:180tmpdata[lonname] =xr.DataArray(np.where(lonroll>=180, lonroll-360, lonroll), dims=[lonname], attrs=data[lonname].attrs)
else:
# flip from -180:180 to 0:360tmpdata[lonname] =xr.DataArray(((lonroll+360) %360), dims=[lonname], attrs=data[lonname].attrs)
returntmpdata
The text was updated successfully, but these errors were encountered:
This issue (pydata/xarray#7031) regarding a periodic boundary index and a related conversation on the Pangeo Discourse might be worth a look. It's a different solution and relies on some work currently under development, but may be worth keeping an eye on.
I think something using roll and updating coordinates could make sense though and while there may be overlap with the periodic boundary index option there are probably cases where one or the other might make more sense.
From a design perspective, we might also consider something a little more flexible like lonPivot which covers the lonFlip case as well.
A very common operation performed with global data is to convert the longitude convention from/to [0,360] to/from [-180, 180]. This was available in NCL as lonFlip.
There are probably many ways this could be implemented. I've written this function a bunch of times. My current version assumes global data and that the data is an xarray object, and it at least seems to work:
The text was updated successfully, but these errors were encountered: