Skip to content

Commit c048410

Browse files
committed
WIP
1 parent d33610e commit c048410

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

cf_xarray/geometry.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ def grid_to_polygons(ds: xr.Dataset) -> xr.DataArray:
462462

463463
grid = ds.cf[["latitude", "longitude"]].load()
464464
bounds = grid.cf.bounds
465+
coordinates = grid.cf.coordinates
465466
dims = grid.cf.dims
467+
bounds_dim = grid.cf.get_bounds_dim_name("latitude")
466468

467469
if "latitude" in dims or "longitude" in dims:
468470
# for 1D lat, lon, this allows them to be
@@ -471,13 +473,23 @@ def grid_to_polygons(ds: xr.Dataset) -> xr.DataArray:
471473

472474
assert "latitude" in bounds
473475
assert "longitude" in bounds
476+
(lon,) = coordinates["longitude"]
474477
(lon_bounds,) = bounds["longitude"]
478+
(lat,) = coordinates["latitude"]
475479
(lat_bounds,) = bounds["latitude"]
476480

477481
with xr.set_options(keep_attrs=True):
478-
(points,) = xr.broadcast(grid)
482+
broadcasted = xr.broadcast(
483+
grid[lon],
484+
grid[lat],
485+
grid[lon_bounds],
486+
grid[lat_bounds],
487+
exclude=bounds_dim,
488+
)
489+
asdict = dict(zip([lon, lat, lon_bounds, lat_bounds], broadcasted))
490+
# display(asdict)
491+
points = xr.Dataset(asdict)
479492

480-
bounds_dim = grid.cf.get_bounds_dim_name("latitude")
481493
points = points.transpose(..., bounds_dim)
482494
lonbnd = points[lon_bounds].data
483495
latbnd = points[lat_bounds].data

0 commit comments

Comments
 (0)