Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bounds fails with coordinates crossing the antimeridian or the Greenwich meridian. #384

Open
aulemahal opened this issue Dec 14, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@aulemahal
Copy link
Contributor

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.

@aulemahal aulemahal self-assigned this Dec 14, 2022
@aulemahal aulemahal added the bug Something isn't working label Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant