Hi Even,
Thanks. I can silence this with a custom error handler (I tested it, and
it works). But the part that is confusing to me, as a user of the Python
API, is that I did not ask the API to do anything with int32s. All I did
was open the dataset using the default parameters of gdal.Open(). I
would not expect a warning to be reported in that circumstance, unless
opening .img files that use nan as the NoData value was problematic for
GDAL in some way. That is why I was suggesting that the warning be removed.
Jason
On 5/8/25 17:51, Even Rouault wrote:
Jason,
It looks like something in the code asks a float64 field to be
returned as a int32, and thus NaN has to be turned into something
else. That's perhaps fine in the context where that happens with your
file and could potentially be silenced, but access to the file would
be needed to investigate
Even
Le 08/05/2025 à 23:01, Jason Roberts via gdal-dev a écrit :
Hi GDAL team,
I'm working with the GDAL Python API. I have some HFA (.img) files
that are float32 and that use nan as their NoData value. As far as I
can tell, using nan is allowed but I could be wrong. When I open
them, I get "Warning 1: NaN converted to INT_MAX." Everything seems
to work fine after that. Is this message something I need to worry
about? If not, may I suggest you remove it from the HFA driver if
possible?
Here's some code demonstrating the message. If need be, I can provide
an example file, or write some code to generate one.
>>> import numpy as np
>>> from osgeo import gdal
>>> gdal.__version__ # this version is packaged with ArcGIS Pro
3.4, but I don't think the version matters
'3.9.2e'
>>> ds =
gdal.Open(r'\\conch\denmod\Covariates\NARW25\CMEMS_GLORYS\SST\1999\SST_199901.img',
gdal.GA_ReadOnly)
Warning 1: NaN converted to INT_MAX.
>>> band = ds.GetRasterBand(1)
>>> gdal.GetDataTypeName(band.DataType)
'Float32'
>>> band.GetNoDataValue()
nan
>>> arr = band.ReadAsArray() # the data look ok:
>>> np.isnan(arr).sum()
86788
>>> (~np.isnan(arr)).sum()
142985
>>> np.max(arr)
nan
>>> np.nanmax(arr)
27.078554
As far as I can tell, the warning comes from this code in
gdal/frmts/hfa/hfafield.cpp:
else if (std::isnan(dfDoubleRet))
{
CPLError(CE_Warning, CPLE_AppDefined,
"NaN converted to INT_MAX.");
nIntRet = nMax;
}
But I don't know if there are any negative ramifications that will
result.
Thank you for your help. And, as always, thank you very much for
developing and maintaining GDAL.
Jason
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev
--
http://www.spatialys.com/
My software is free, but my time generally not.
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev