exactextract icon indicating copy to clipboard operation
exactextract copied to clipboard

Add functionality to convert nodata to a fixed value

Open dbaston opened this issue 11 months ago • 0 comments

Many population datasets use NODATA pixels for areas outside the modeled domain, e.g. ocean pixels. For the purpose of exactextract these should be considered equivalent to zero.

The following workaround is available in Python using GDAL:

from osgeo import gdal
gdal.BuildVRT('/vsimem/vrt1.vrt', "my_pop_data.tif", VRTNodata = 0)
pop_src = gdal.BuildVRT('', '/vsimem/vrt1.vrt', srcNodata = "none")

This is not clear in its intent and easy to get wrong. As an alternative, the exactextractr package uses default_weight and default_value arguments to convert NODATA into a constant value.

Similar functionality could be added to exactextract, either by:

  1. modifying Raster to have a default_value argument. This would require that all RasterSource implementations in turn accept such a value, and pass it along when constructing Raster objects.
  2. modifying RasterStats to take appropriate arguments, so you could call e.g.weighted_mean(default_weight=0). This would be automatically exposed in both the Python bindings and the CLI and would avoid the need to modify RasterSource implementations.

dbaston avatar Mar 18 '24 15:03 dbaston