Skip to content

Commit

Permalink
Fix bounds_to_vertices (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
aulemahal authored Aug 10, 2021
1 parent 479ea5e commit 5523a8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cf_xarray/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _bounds_helper(values, n_core_dims, nbounds, order):
top_left = values[..., -1:, :, 3]
vertex_vals = np.block([[bot_left, bot_right], [top_left, top_right]])
if order is None: # We verify if the ccw version works.
calc_bnds = vertices_to_bounds(vertex_vals).values
calc_bnds = np.moveaxis(vertices_to_bounds(vertex_vals).values, 0, -1)
order = "counterclockwise" if np.all(calc_bnds == values) else "clockwise"
if order == "clockwise":
bot_left = values[..., :, :, 0]
Expand Down
10 changes: 8 additions & 2 deletions cf_xarray/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ def test_bounds_to_vertices():
assert_array_equal(ds.lat.values + 1.25, lat_c.values[:-1])

# 2D case, CF- order
lat_c = cfxr.bounds_to_vertices(mollwds.lat_bounds, bounds_dim="bounds")
assert_equal(mollwds.lat_vertices, lat_c)
lat_ccw = cfxr.bounds_to_vertices(
mollwds.lat_bounds, bounds_dim="bounds", order="counterclockwise"
)
lat_no = cfxr.bounds_to_vertices(
mollwds.lat_bounds, bounds_dim="bounds", order=None
)
assert_equal(mollwds.lat_vertices, lat_ccw)
assert_equal(lat_no, lat_ccw)

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

0 comments on commit 5523a8f

Please sign in to comment.