isciences / exactextractr

R package for fast and accurate raster zonal statistics
https://isciences.gitlab.io/exactextractr/
272 stars 26 forks source link

weighted_mean on raster with NAs #78

Open danielreispereira opened 2 years ago

danielreispereira commented 2 years ago

Trying to exact_extract() on a netcdf using a tiff as weights returns NaN for the majority of regions except for really small ones, suggesting that the function is failing if there are NAs on the input netcdf/Raster. Simple mean/median working flawlessly.

Is this the expected behavior? Since there is no "na.rm=TRUE" or the likes when using weighted_mean, how can I proceed if either the data or weights raster contain missing pixels?

dbaston commented 2 years ago

NA values in the primary raster are always ignored. NA values in the weighting raster propagate to the result. To avoid this, you can set the default_weight argument.

danielreispereira commented 2 years ago

Thanks, DBaston. The default behavior and "deafult_weight" was not obvious to me from the docs. Understood it now.