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

cube.intersection out of bounds point #3391

Closed
trexfeathers opened this issue Sep 6, 2019 · 7 comments · Fixed by #4059
Closed

cube.intersection out of bounds point #3391

trexfeathers opened this issue Sep 6, 2019 · 7 comments · Fixed by #4059
Assignees

Comments

@trexfeathers
Copy link
Contributor

Example: when the upper bound of a point_x is at 0, the following code returns point_x, instead of wrapping the point to 360-point_x:
target_grid.intersection(iris.coords.CoordExtent('longitude', 0, 360))

@valeriupredoi
Copy link

we have noticed this too, here is a minimal example that reproduces the problem hassle-free:

import iris
import numpy as np

lon_points = np.array([-8.75, -6.25, -3.75, -1.25,  1.25,  3.75,  6.25,  8.75, 11.25,
                       13.75, 16.25, 18.75, 21.25, 23.75, 26.25, 28.75, 31.25, 33.75,
                       36.25, 38.75])
lon_bounds = np.array([[ -2.5,   0. ], [  0. ,   2.5],
    [  2.5,   5. ], [  5. ,   7.5],
    [  7.5,  10. ], [ 10. ,  12.5],
    [ 12.5,  15. ], [ 15. ,  17.5],
    [ 17.5,  20. ], [ 20. ,  22.5],
    [ 22.5,  25. ], [ 25. ,  27.5],
    [ 27.5,  30. ], [ 30. ,  32.5],
    [ 32.5,  35. ], [ 35. ,  37.5],
    [ 37.5,  40. ], [350. , 352.5],
    [352.5, 355. ], [355. , 357.5]])
lons = iris.coords.DimCoord(lon_points, standard_name='longitude', bounds=lon_bounds,
                            units='degrees_east')
cube = iris.cube.Cube(np.zeros((20,)), dim_coords_and_dims=[(lons, 0)])
isect_with_bounds = cube.intersection(longitude=(0, 360))
print(isect_with_bounds.coord("longitude"))
cube.coord("longitude").bounds = None
isect_without_bounds = cube.intersection(longitude=(0, 360))
print(isect_without_bounds.coord("longitude"))
cube.coord("longitude").guess_bounds()
isect_guessbounds = cube.intersection(longitude=(0, 360))
print(isect_guessbounds.coord("longitude"))
  • with bounds I get a negative point where should be none;
  • removing the bounds I get the correct result;
  • reintroducing the bounds by guessing them, the undesired behavior is seen again

@bjlittle @pelson @lbdreyer what you guys reckon? Muchos cheers 🍺

@valeriupredoi
Copy link

just a heads up that the behavior is exactly the same as described above for iris=3.0.1 too so the issue still stands, friendly ping to @bjlittle @lbdreyer 👍 🍺

@rcomer rcomer self-assigned this Mar 2, 2021
@rcomer
Copy link
Member

rcomer commented Mar 2, 2021

I think I can see how to fix this. Will unassign myself if I'm wrong!

@valeriupredoi
Copy link

cheers muchly @rcomer 🍺

@rcomer
Copy link
Member

rcomer commented May 13, 2021

Now fixed in v3.0.x by #4059

@rcomer rcomer closed this as completed May 13, 2021
@valeriupredoi
Copy link

thank you very much @rcomer - just tested it and with iris=3.0.2 all works a treat (unlike 3.0.1 which is still displaying the unwanted behavior!) 🍺

@rcomer
Copy link
Member

rcomer commented Jul 1, 2021

Thanks for the feedback @valeriupredoi 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants