roocs / clisops

Climate Simulation Operations
https://clisops.readthedocs.io/en/latest/
Other
21 stars 9 forks source link

Spatial averaging over polygons #38

Closed aulemahal closed 3 years ago

aulemahal commented 4 years ago

[This issue is a migration of Ouranosinc/xclim#422]

The goal would be to compute spatial averages over a polygon. It would need to account for non-uniform grid area and partial overlap, holes in polygons. The best would be to compute a weight mask for the array representing the area of each gridcell covered by the polygon (of the fractional area).

As mentioned on the original thread, a first way to do this would be to generate a grid of higher resolution and use the existing create_mask. Or, we could iterate over all gridcells and generate Polygons for them, either using provided lat_bnds and lon_bnds or inferring them. Then, shapely's methods could be used to compute the intersection of each gridpolygon and the target polygon.

From some tests I made of both methods, the second can be quite fast and relatively easy to implement.

huard commented 3 years ago

https://github.com/pangeo-data/xESMF/pull/24 is now merged. With https://github.com/pangeo-data/xESMF/pull/49, everything should be in place to do this cleanly.

aulemahal commented 3 years ago

Was closed by #109.