Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing wraparound issue #60

Merged
merged 3 commits into from
Feb 13, 2024
Merged

Fixing wraparound issue #60

merged 3 commits into from
Feb 13, 2024

Conversation

ks905383
Copy link
Owner

@ks905383 ks905383 commented Feb 13, 2024

Major changes

Closes #51 by:

  • Updating create_raster_polygons() such that it splits antimeridian-crossing grid cells into two components of a MultiPolygon, to be in line with GeoJSON conventions (inspired by the solution in https://github.com/gadomski/antimeridian). shapely does not see any CRS information and therefore treats -180:180 as a number line; splitting Polygons at the antimeridian is a workaround for this.
  • Updating get_bnds() to correctly produce lat/lon bounds for pixels close to the antimeridian, with a handful of new tests for edge cases

Minor changes

  • Adds NoOverlapError for when polygons do not overlap with any grid cells in the sample
  • xa.fix_ds() now only sorts values when a check sees them to be unsorted - this is to avoid loading into memory when not needed (since xa.fix_ds() is used outside of xagg as well)
  • Changes ds.dims.keys() to ds.sizes() references to avoid warnings

Identified several sources of errors:
- in `create_raster_polygons`, since shapely Polygons don't have .crs information, following GeoJSON conventions pixels crossing the antimeridian now are split into a MultiPolygon with separate Polygons on either side of the antimeridian.
- _however_, `xa.aux.get_bnds()` has a bug in it in which incorrect bounds are created, this will be the next step to look at

There are a bunch of random fixes as well, including:
- switching `.dims()` to `.sizes()` to silence the depreciation warning
Fixes #51, which is related to pixels incorrectly splitting at the
antimeridian. This required two fixes:

1) `create_raster_polygons()` updated to GeoJSON standards of splitting pixels that cross the antimeridian *at* the antimerdiain, forming a MultiPolygon
2) `get_bnds()` updated to correctly set bounds of grids that cross the antimeridian

This commit also adds or updates many tests to make sure this process works correctly, including `get_bnds()` tests checking

- partial grids
- grids crossing the antimeridian
- grids with individual grid cells on both sides of the antimeridian

Further, adds a `NoOverlapError` raised when the polygons and input rasters don't overlap at all.
Workaround for issues stemming from pydata/xarray#8743

By replicating the source_grid dataset from scratch / from .values before exporting it.
@ks905383 ks905383 merged commit 69516b3 into main Feb 13, 2024
5 checks passed
@ks905383 ks905383 deleted the fixing_wraparound_Issue branch February 13, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Longitude -180 pixels included in weightmap
1 participant