Skip to content

Commit 336a21d

Browse files
committed
Fix guess_bounds precision for circular coords at numpy v2
1 parent c794e8e commit 336a21d

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

docs/src/whatsnew/latest.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ This document explains the changes made to Iris for this release
3636
🐛 Bugs Fixed
3737
=============
3838

39-
#. N/A
40-
39+
#. `@rcomer`_ ensured that :meth:`~iris.coords.Coord.guess_bounds` calculates at
40+
double precision for circular coordinates so the bounds span the full circle
41+
(:issue:`6738`, :pull:`6793`)
4142

4243
💣 Incompatible Changes
4344
=======================

lib/iris/coords.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,8 +2402,9 @@ def _guess_bounds(self, bound_position=0.5, monthly=False, yearly=False):
24022402
points = np.empty(self.shape[0] + 2)
24032403
points[1:-1] = self.points
24042404
direction = 1 if self.points[-1] > self.points[0] else -1
2405-
points[0] = self.points[-1] - (self.units.modulus * direction)
2406-
points[-1] = self.points[0] + (self.units.modulus * direction)
2405+
modulus = np.float64(self.units.modulus)
2406+
points[0] = self.points[-1] - (modulus * direction)
2407+
points[-1] = self.points[0] + (modulus * direction)
24072408
diffs = np.diff(points)
24082409
else:
24092410
diffs = np.diff(self.points)

lib/iris/tests/unit/coords/test_Coord.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ def test_circular_decreasing_alt_range(self):
194194
)
195195
_shared_utils.assert_array_equal(target, self.coord.bounds)
196196

197+
def test_circular_n216_float32(self):
198+
# Values represent longitude taken from an N216 pp-file.
199+
coord = DimCoord.from_regular(
200+
-0.41666666, 0.8333333, 432, units="degrees", circular=True
201+
)
202+
coord.guess_bounds()
203+
# The last bound should match up to the first.
204+
assert coord.bounds[-1, -1] - coord.bounds[0, 0] == 360
205+
197206

198207
class Test_guess_bounds__default_enabled_latitude_clipping:
199208
def test_all_inside(self):

0 commit comments

Comments
 (0)