handle numpy
dtypes for scalar values such as in SetNoDataValue()
#330
Labels
enhancement
New feature or request
Milestone
As noted in natcap/invest#992, GDAL does not consider numpy Float32/Float64 objects as valid
double
s. And that can lead to exceptions like this:I think it would be nice for
pygeoprocessing
to handle this instead of forcing the user to remember the details of GDAL and its C implementation.pygeoprocessing
encourages users to pair it withnumpy
in all sorts of ways, so I think we can do a bit better here.There are a few places where we already handle this in
pygeoprocessing
. There are 5 instances of callingSetNoDataValue
and a few different ways of handling things.raster_calculator
:value is passed as-is from a function argument
new_raster_from_base
: (I propose adopting this solution for all the rest)uses
item()
to return a Python scalar representation https://numpy.org/doc/stable/reference/generated/numpy.ndarray.item.htmlcreate_raster_from_bounding_box
:always does
band.SetNoDataValue(float(target_nodata))
regardless of the target datatype for the rasterconvolve_2d
:value is passed as-is from a function argument unless it is
None
, then casts to Pythonfloat
, regardless of target datatype.numpy_array_to_raster
:value is passed as-is from a function argument
Are there any other cases of
numpy
Float types being rejected by GDAL, besidesSetNoDataValue()
that we should consider?The text was updated successfully, but these errors were encountered: