stilt.geometry.overlap_weights#
- stilt.geometry.overlap_weights(geometry, x_centers, y_centers, xres, yres, crs)[source]#
Return the fraction of each raster cell inside each geometry cell.
Polygon overlaps (a
Mesh, or aGridin another CRS) use exactextract when it is installed, which is about 100 times faster on large rasters, and shapely otherwise. Both give the same fractions. Results are cached, so repeated aggregations onto the same geometry are one matrix product each.- Parameters:
geometry (
Grid|Mesh|Zones) – Target geometry. It is reprojected tocrswhen needed.x_centers (
ndarray) – Cell-center coordinates of the raster, incrsunits.y_centers (
ndarray) – Cell-center coordinates of the raster, incrsunits.xres (
float) – Cell size of the raster, incrsunits.yres (
float) – Cell size of the raster, incrsunits.crs (
str) – CRS of the raster.
- Returns:
Shape
(n_cells, ny * nx), with rows ingeometry.indexorder and raster cells ordered withxvarying fastest (the order ofdata.transpose("time", y, x).reshape(nt, -1)).- Return type:
csr_matrix