Skip to content

Using iris.util.reverse flips coordinate bounds #4078

Description

@sloosvel

🐛 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions