Skip to content

iris.util.reverse does not flip coordinate bounds correctly #3756

@schlunma

Description

@schlunma

I found an issue in iris.util.reverse:

import iris
print(iris.__version__)
print()

lat_coord = iris.coords.DimCoord([10, 20], bounds=[[5, 15], [15, 25]],
                                 standard_name='latitude')
cube = iris.cube.Cube([0.0, 1.0], dim_coords_and_dims=[(lat_coord, 0)])
reversed_cube = iris.util.reverse(cube, lat_coord)

print("Old lat coord:", cube.coord('latitude'))
print("Reversed lat coord:", reversed_cube.coord('latitude'))
print()
print("Old lat contiguous:", cube.coord('latitude').is_contiguous())
print("Reversed lat contiguous:", reversed_cube.coord('latitude').is_contiguous())

gives

2.4.0

Old lat coord: DimCoord(array([10, 20]), bounds=array([[ 5, 15],
       [15, 25]]), standard_name='latitude', units=Unit('1'))
Reversed lat coord: DimCoord(array([20, 10]), bounds=array([[15, 25],
       [ 5, 15]]), standard_name='latitude', units=Unit('1'))

Old lat contiguous: True
Reversed lat contiguous: False

As you can see, the bounds of the coordinate have not been reversed correctly: Instead of [[15, 25], [5, 15]], they should be [[25, 15], [15, 5]]. As a side effect, coord.is_contiguous() fails now (that's how I discovered this issue).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions