xarray-contrib / cf-xarray

an accessor for xarray objects that interprets CF attributes
https://cf-xarray.readthedocs.io/
Apache License 2.0
152 stars 39 forks source link

Add grid_bounds_to_polygons #478

Open dcherian opened 8 months ago

dcherian commented 8 months ago

This converts "bounds" in the 2-element form to an array of shapely polygons, one per grid cell. A step towards nicely packaging conservative regridding for the ecosystem. It could easily be generalized to the 4-element "vertex" form

Modified from https://notebooksharing.space/view/c6c1f3a7d0c260724115eaa2bf78f3738b275f7f633c1558639e7bbd75b31456#displayOptions=

cc @martinfleis @benbovy @aulemahal for awareness. I'm not sure if this is at all useful for xvec but on the off-chance that it is..

codecov[bot] commented 8 months ago

Codecov Report

Attention: Patch coverage is 10.34483% with 26 lines in your changes missing coverage. Please review.

Project coverage is 83.06%. Comparing base (a9cebee) to head (d33610e). Report is 14 commits behind head on main.

:exclamation: Current head d33610e differs from pull request most recent head 0291802

Please upload reports for the commit 0291802 to get more accurate results.

Files Patch % Lines
cf_xarray/geometry.py 7.14% 26 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #478 +/- ## ========================================== - Coverage 85.78% 83.06% -2.73% ========================================== Files 13 14 +1 Lines 2364 2799 +435 Branches 183 208 +25 ========================================== + Hits 2028 2325 +297 - Misses 303 423 +120 - Partials 33 51 +18 ``` | [Flag](https://app.codecov.io/gh/xarray-contrib/cf-xarray/pull/478/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xarray-contrib) | Coverage Δ | | |---|---|---| | [mypy](https://app.codecov.io/gh/xarray-contrib/cf-xarray/pull/478/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xarray-contrib) | `43.75% <10.34%> (+5.22%)` | :arrow_up: | | [unittests](https://app.codecov.io/gh/xarray-contrib/cf-xarray/pull/478/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xarray-contrib) | `92.89% <7.14%> (-1.10%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xarray-contrib#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

martinfleis commented 8 months ago

In Xvec we could flatten the array and use it as an index instead of latitude and longitude coordinates if there's a use case for that.