perrygeo / python-rasterstats

Summary statistics of geospatial raster datasets based on vector geometries.
BSD 3-Clause "New" or "Revised" License
525 stars 117 forks source link

Use numpy dtype arg selectively, instead of casting all integer data #279

Closed perrygeo closed 1 year ago

perrygeo commented 1 year ago

As noted in #267, the previous strategy of casting all integers to int64 can be undesirable.

This PR changes the strategy to use the dtype argument to any numpy methods that are susceptible to integer overflow (sum, mean). This allows the aggregate function to accumulate values in a "safe" integer type without casting all of the raster data.

Should be a small performance boost if you're using 16 or 32 bit integers.

Thanks @maxfenv and @groutr

Closes #267

maxfenv commented 1 year ago

@perrygeo 8 bit integers even! Many thanks for this