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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersection bounds when requested minimum is negative #4221

Closed
rcomer opened this issue Jul 2, 2021 · 0 comments 路 Fixed by #4278
Closed

Intersection bounds when requested minimum is negative #4221

rcomer opened this issue Jul 2, 2021 · 0 comments 路 Fixed by #4278
Assignees

Comments

@rcomer
Copy link
Member

rcomer commented Jul 2, 2021

馃悰 Bug Report

#4059 aimed to fix cube.intersection so if a cell's bounds align with the requested maximum and minimum, the new bounds exactly span that range. This does not work if the requested minimum is negative.

How To Reproduce

import iris
import iris.coords
import iris.cube
import numpy as np

lon = iris.coords.DimCoord(
    np.arange(0.5, 360.5, 1), standard_name="longitude", units='degrees', circular=True)
lon.guess_bounds()
cube = iris.cube.Cube(range(360))
cube.add_dim_coord(lon, 0)

new_cube = cube.intersection(longitude=(-180, 180))
print(new_cube.coord("longitude")[0])
print(new_cube.coord("longitude")[-1])

Output:

DimCoord(array([-180.5]), bounds=array([[-181., -180.]]), standard_name='longitude', units=Unit('degrees'))
DimCoord(array([178.5]), bounds=array([[178., 179.]]), standard_name='longitude', units=Unit('degrees'))

Expected behaviour

Above code should produce:

DimCoord(array([-179.5]), bounds=array([[-180., -179.]]), standard_name='longitude', units=Unit('degrees'))
DimCoord(array([179.5]), bounds=array([[179., 180.]]), standard_name='longitude', units=Unit('degrees'))

Proposed fix

I think this line

if maximum % modulus not in cells:

should have been

if maximum - modulus not in cells:

though I have not checked this fix.

Had it been written this way, I do not think it would have triggered the bug highlighted at #4220.

Environment

  • OS & Version: RHEL 7.9
  • Iris Version: 3.0.2
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.

1 participant