Add bounds fails with coordinates crossing the antimeridian or the Greenwich meridian.
@aulemahal is already working on this.
Since Dec 14, 2022.
Assessment
This issue has not been assessed yet.
Description
Yet another bug with .cf.add_bounds... This one was already present before the 2D addition, but it would have been quite infrequent with 1D coordinates.
The interpolation / extrapolation estimates are not aware of the cyclic nature of the longitude.
MWE:
import xarray as xr
import cf_xarray
ds = xr.Dataset(
{'data': (('x', 'y'), np.ones((3, 3)))},
coords={
'x': [1, 2, 3],
'y': [1, 2, 3],
'lon': (('x',), [170, -170, -150], {'units': 'degrees_east'}),
'lat': (('y',), [-10, 0, 10], {'units': 'degrees_north'}),
},
)
ds.cf.add_bounds(('lon', 'lat')).lon_bounds
yields:
array([[ 340., 0.],
[ 0., -340.],
[-160., -140.]])
but we would expect:
array([[ 160., 0.],
[ 0., -160.],
[-160., -140.]])
Sadly, a quick internet search hasn't given me any pointers towards tools that already take this into account, except for projection-based tools (like pyproj).
We could have a check for "longitude" that looks for jumps and wraps the coordinates, but that jump threshold would be arbitrary. It's nonetheless the simplest way out I see, before parsing grid_mapping into pyproj objects.
- Dominant language
- Python
- Stars
- 181
- Forks
- 49
- Avg merge
- 43m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from xarray-contrib/cf-xarray
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
xarray-contrib/cf-xarray#623 ·
-
Consider adding opt-in support for circular axes when calling `bounds_to_vertices` (related to #594) Open
Difficulty 5/5 Over a week Newbie friendliness 38/100
xarray-contrib/cf-xarray#596 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
xarray-contrib/cf-xarray#570 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 15/100
xarray-contrib/cf-xarray#568 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
xarray-contrib/cf-xarray#566 · 2 comments ·
All issues in xarray-contrib/cf-xarray
Similar issues
-
link-check link-check:sphinx-theme
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OpenHands/extensions#626 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
CSCfi/sd-search-api#39 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100