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

Using iris.util.reverse flips coordinate bounds #4078

Closed
sloosvel opened this issue Mar 29, 2021 · 1 comment · Fixed by #4466
Closed

Using iris.util.reverse flips coordinate bounds #4078

sloosvel opened this issue Mar 29, 2021 · 1 comment · Fixed by #4466

Comments

@sloosvel
Copy link
Contributor

🐛 Bug Report

When using iris.util.reverse along an axis, the cube that is returned is reversed properly. But the coordinate along which it has been reversed, has the bounds flipped and they become noncontiguous. This can cause issues when doing area-related operations.

How To Reproduce

Steps to reproduce the behaviour:

An example for the latitudes would be

  1. cube = iris.util.reverse(cube, (1,))
  2. cube.coord(var_name='lat').bounds

This is the current behaviour when we want to reverse a cube with a decreasing latitude coordinate to make it increasing instead.

Latitudes in a cube before reversing:

DimCoord(array([ 90.        ,  80.52631579,  71.05263158,  61.57894737,
        52.10526316,  42.63157895,  33.15789474,  23.68421053,
        14.21052632,   4.73684211,  -4.73684211, -14.21052632,
       -23.68421053, -33.15789474, -42.63157895, -52.10526316,
       -61.57894737, -71.05263158, -80.52631579, -90.        ]), bounds=array([[ 9.00000000e+01,  8.52631579e+01],
       [ 8.52631579e+01,  7.57894737e+01],
       [ 7.57894737e+01,  6.63157895e+01],
       [ 6.63157895e+01,  5.68421053e+01],
       [ 5.68421053e+01,  4.73684211e+01],
       [ 4.73684211e+01,  3.78947368e+01],
       [ 3.78947368e+01,  2.84210526e+01],
       [ 2.84210526e+01,  1.89473684e+01],
       [ 1.89473684e+01,  9.47368421e+00],
       [ 9.47368421e+00,  7.10542736e-15],
       [ 7.10542736e-15, -9.47368421e+00],
       [-9.47368421e+00, -1.89473684e+01],
       [-1.89473684e+01, -2.84210526e+01],
       [-2.84210526e+01, -3.78947368e+01],
       [-3.78947368e+01, -4.73684211e+01],
       [-4.73684211e+01, -5.68421053e+01],
       [-5.68421053e+01, -6.63157895e+01],
       [-6.63157895e+01, -7.57894737e+01],
       [-7.57894737e+01, -8.52631579e+01],
       [-8.52631579e+01, -9.00000000e+01]]), standard_name='latitude', units=Unit('degrees_north'), long_name='Long name', var_name='lat')

Latitudes after reversing:

DimCoord(array([-90.        , -80.52631579, -71.05263158, -61.57894737,
       -52.10526316, -42.63157895, -33.15789474, -23.68421053,
       -14.21052632,  -4.73684211,   4.73684211,  14.21052632,
        23.68421053,  33.15789474,  42.63157895,  52.10526316,
        61.57894737,  71.05263158,  80.52631579,  90.        ]), bounds=array([[-8.52631579e+01, -9.00000000e+01],
       [-7.57894737e+01, -8.52631579e+01],
       [-6.63157895e+01, -7.57894737e+01],
       [-5.68421053e+01, -6.63157895e+01],
       [-4.73684211e+01, -5.68421053e+01],
       [-3.78947368e+01, -4.73684211e+01],
       [-2.84210526e+01, -3.78947368e+01],
       [-1.89473684e+01, -2.84210526e+01],
       [-9.47368421e+00, -1.89473684e+01],
       [ 7.10542736e-15, -9.47368421e+00],
       [ 9.47368421e+00,  7.10542736e-15],
       [ 1.89473684e+01,  9.47368421e+00],
       [ 2.84210526e+01,  1.89473684e+01],
       [ 3.78947368e+01,  2.84210526e+01],
       [ 4.73684211e+01,  3.78947368e+01],
       [ 5.68421053e+01,  4.73684211e+01],
       [ 6.63157895e+01,  5.68421053e+01],
       [ 7.57894737e+01,  6.63157895e+01],
       [ 8.52631579e+01,  7.57894737e+01],
       [ 9.00000000e+01,  8.52631579e+01]]), standard_name='latitude', units=Unit('degrees_north'), long_name='Long name', var_name='lat')

Expected behaviour

The expected behaviour would be to have a coordinate that even though it has been reversed, the bounds are still contiguous:

DimCoord(array([-90.        , -80.52631579, -71.05263158, -61.57894737,
       -52.10526316, -42.63157895, -33.15789474, -23.68421053,
       -14.21052632,  -4.73684211,   4.73684211,  14.21052632,
        23.68421053,  33.15789474,  42.63157895,  52.10526316,
        61.57894737,  71.05263158,  80.52631579,  90.        ]), bounds=array([[-9.00000000e+01, -8.52631579e+01],
       [-8.52631579e+01, -7.57894737e+01],
       [-7.57894737e+01, -6.63157895e+01],
       [-6.63157895e+01, -5.68421053e+01],
       [-5.68421053e+01, -4.73684211e+01],
       [-4.73684211e+01, -3.78947368e+01],
       [-3.78947368e+01, -2.84210526e+01],
       [-2.84210526e+01, -1.89473684e+01],
       [-1.89473684e+01, -9.47368421e+00],
       [-9.47368421e+00,  7.10542736e-15],
       [ 7.10542736e-15,  9.47368421e+00],
       [ 9.47368421e+00,  1.89473684e+01],
       [ 1.89473684e+01,  2.84210526e+01],
       [ 2.84210526e+01,  3.78947368e+01],
       [ 3.78947368e+01,  4.73684211e+01],
       [ 4.73684211e+01,  5.68421053e+01],
       [ 5.68421053e+01,  6.63157895e+01],
       [ 6.63157895e+01,  7.57894737e+01],
       [ 7.57894737e+01,  8.52631579e+01],
       [ 8.52631579e+01,  9.00000000e+01]]), standard_name='latitude', units=Unit('degrees_north'), long_name='Long name', var_name='lat')

Screenshots

Environment

  • OS & Version: [e.g., Ubuntu 20.04 LTS]
  • Iris Version: '3.0.1'

Additional context

Click to expand this section...

Related to ESMValGroup/ESMValCore#1060

Add additional verbose information in a collapsible section.

See here for further details.

@rcomer
Copy link
Member

rcomer commented Apr 7, 2021

This looks to be a duplicate of #3756, which we hope to look at ready for v3.1.

@rcomer rcomer added this to the v3.1.0 milestone Apr 7, 2021
@bjlittle bjlittle modified the milestones: v3.1.0, v3.3.0 Nov 1, 2021
@rcomer rcomer self-assigned this Nov 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants