roocs / clisops

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

Add a 'intersects' option to subset bbox and shape #253

Open RondeauG opened 2 years ago

RondeauG commented 2 years ago

Description

Currently, clisops will subset a dataset based on the lat/lon coordinate of the grid pixels, meaning that the center of the pixel needs to be inside the region to be kept. An option to instead keep all the pixels that touch the region would be very useful.

I realise that the buffer argument of subset_shape already serves that purpose, but it can be difficult to use effectively since the optimal value depends on model resolution. At minimum, however, a similar option should be included for subset_bbox too.

aulemahal commented 2 years ago

That would necessitate the cell boundaries I believe. Similarly with xESMF, this is trivial to obtain for rectilinear grids, but not for curvilinear (rotated pole) ones. Would you be ok if this had the same conditions as in xESMF? i.e. : When touching = True, if lat and lon are 2D arrays and ds.cf.get_bounds fails, then the function fails.

RondeauG commented 2 years ago

I think so, but in that case we'd definitely need both buffer and touching for subset_shape and subset_bbox. This way, buffer could still be used for curvilinear grids.

Also, reading a little more on which features shapely has, I think that intersects or overlaps would be better terms than touches/touching.

From https://shapely.readthedocs.io/en/stable/manual.html#object.intersects: