Skip to content

Commit 5523a8f

Browse files
authored
Fix bounds_to_vertices (#255)
1 parent 479ea5e commit 5523a8f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

cf_xarray/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _bounds_helper(values, n_core_dims, nbounds, order):
9090
top_left = values[..., -1:, :, 3]
9191
vertex_vals = np.block([[bot_left, bot_right], [top_left, top_right]])
9292
if order is None: # We verify if the ccw version works.
93-
calc_bnds = vertices_to_bounds(vertex_vals).values
93+
calc_bnds = np.moveaxis(vertices_to_bounds(vertex_vals).values, 0, -1)
9494
order = "counterclockwise" if np.all(calc_bnds == values) else "clockwise"
9595
if order == "clockwise":
9696
bot_left = values[..., :, :, 0]

cf_xarray/tests/test_helpers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ def test_bounds_to_vertices():
1818
assert_array_equal(ds.lat.values + 1.25, lat_c.values[:-1])
1919

2020
# 2D case, CF- order
21-
lat_c = cfxr.bounds_to_vertices(mollwds.lat_bounds, bounds_dim="bounds")
22-
assert_equal(mollwds.lat_vertices, lat_c)
21+
lat_ccw = cfxr.bounds_to_vertices(
22+
mollwds.lat_bounds, bounds_dim="bounds", order="counterclockwise"
23+
)
24+
lat_no = cfxr.bounds_to_vertices(
25+
mollwds.lat_bounds, bounds_dim="bounds", order=None
26+
)
27+
assert_equal(mollwds.lat_vertices, lat_ccw)
28+
assert_equal(lat_no, lat_ccw)
2329

2430
# Transposing the array changes the bounds direction
2531
ds = mollwds.transpose("bounds", "y", "x", "y_vertices", "x_vertices")

0 commit comments

Comments
 (0)