Skip to content

Commit 228abd4

Browse files
committed
cf.indices wo fix
1 parent 5e57272 commit 228abd4

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

cf/mixin/fielddomain.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ def _indices(self, config, data_axes, ancillary_mask, kwargs):
472472
stop = start - n.size
473473
else:
474474
start = size - parameters["shift"]
475-
stop = start
475+
stop = start + size
476+
if stop > size:
477+
stop -= size
476478

477479
index = slice(start, stop, 1)
478480

cf/test/test_Field.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,34 @@ def test_Field_indices(self):
13611361
x = g.dimension_coordinate("X").array
13621362
self.assertTrue((x == [-200, -160, -120, -80, -40, 0, 40]).all())
13631363

1364+
indices = f.indices(grid_longitude=cf.wo(1, 5))
1365+
g = f[indices]
1366+
self.assertEqual(g.shape, (1, 10, 9))
1367+
x = g.dimension_coordinate("X").array
1368+
self.assertTrue(
1369+
(x == [-320, -280, -240, -200, -160, -120, -80, -40, 0]).all()
1370+
)
1371+
1372+
indices = f.indices(grid_longitude=cf.wo(41, 45))
1373+
g = f[indices]
1374+
self.assertEqual(g.shape, (1, 10, 9))
1375+
x = g.dimension_coordinate("X").array
1376+
self.assertTrue(
1377+
(x == [-280, -240, -200, -160, -120, -80, -40, 0, 40]).all()
1378+
)
1379+
1380+
indices = f.indices(grid_longitude=cf.wo(-5, -1))
1381+
g = f[indices]
1382+
self.assertEqual(g.shape, (1, 10, 9))
1383+
x = g.dimension_coordinate("X").array
1384+
self.assertTrue((x == [0, 40, 80, 120, 160, 200, 240, 280, 320]).all())
1385+
1386+
indices = f.indices(grid_longitude=cf.wo(-45, -41))
1387+
g = f[indices]
1388+
self.assertEqual(g.shape, (1, 10, 9))
1389+
x = g.dimension_coordinate("X").array
1390+
self.assertTrue((x == [-40, 0, 40, 80, 120, 160, 200, 240, 280]).all())
1391+
13641392
with self.assertRaises(ValueError):
13651393
# No X coordinate values lie outside the range [-90, 370]
13661394
f.indices(grid_longitude=cf.wo(-90, 370))

0 commit comments

Comments
 (0)