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 a Grid in 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 to crs when needed.

  • x_centers (ndarray) – Cell-center coordinates of the raster, in crs units.

  • y_centers (ndarray) – Cell-center coordinates of the raster, in crs units.

  • xres (float) – Cell size of the raster, in crs units.

  • yres (float) – Cell size of the raster, in crs units.

  • crs (str) – CRS of the raster.

Returns:

Shape (n_cells, ny * nx), with rows in geometry.index order and raster cells ordered with x varying fastest (the order of data.transpose("time", y, x).reshape(nt, -1)).

Return type:

csr_matrix