<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<font face="Verdana">Thank you!<br>
<br>
Jason<br>
</font><br>
<div class="moz-cite-prefix">On 5/9/25 06:04, Even Rouault wrote:<br>
</div>
<blockquote type="cite" cite="mid:878ac53d-666d-4f04-9128-3a8c595110c5@spatialys.com">Will
be fixed per
<a class="moz-txt-link-freetext" href="https://github.com/OSGeo/gdal/pull/12323">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FOSGeo%2Fgdal%2Fpull%2F12323&data=05%7C02%7Cjason.roberts%40duke.edu%7C7800a2bcc6734e514f2508dd8ee0f36a%7Ccb72c54e4a314d9eb14a1ea36dfac94c%7C0%7C0%7C638823818986051056%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=hGWcGXob7vp%2FGd%2B1fR1IXYcDZmWcAl4oJTGE%2BpzJFs8%3D&reserved=0</a><br>
<br>
Le 09/05/2025 à 07:56, Rahkonen Jukka a écrit :
<br>
<blockquote type="cite">Hi,
<br>
<br>
Another method to reproduce without Python by using gdal_create:
<br>
<br>
gdal_create -outsize 100 100 -ot float32 -a_nodata nan -of hfa
nan.img
<br>
<br>
C:\data\000\gdaltest>gdalinfo nan.img
<br>
Warning 1: NaN converted to INT_MAX.
<br>
Driver: HFA/Erdas Imagine Images (.img)
<br>
Files: nan.img
<br>
Size is 100, 100
<br>
...
<br>
Band 1 Block=64x64 Type=Float32, ColorInterp=Undefined
<br>
Description = Layer_1
<br>
NoData Value=nan
<br>
Metadata:
<br>
LAYER_TYPE=athematic
<br>
<br>
If I convert nan.img into GeoTIFF with "gdal_translate nan.img
nan.tif", I do see the warning, but the new GeoTIFF still has
NoData Value=nsn. I wonder what is the real meaning of the
warning.
<br>
<br>
-Jukka Rahkonen-
<br>
<br>
________________________________________
<br>
Lähettäjä: gdal-dev käyttäjän Jason Roberts via gdal-dev
puolesta
<br>
Lähetetty: Perjantai 9. toukokuuta 2025 2.04
<br>
Vastaanottaja: Even Rouault; gdal dev
<br>
Aihe: Re: [gdal-dev] HFA (.img) driver prints Warning 1: NaN
converted to INT_MAX when float raster has nan as the NoData
value
<br>
<br>
Thank you. I can help you repro it if you want to take a
look.I'm having trouble attaching a .img file to email. My email
system doesn't want to allow it, even if I put it in a zip. But
here is a simple way to repro it by creating the file with GDAL
itself. (In this example, I used float64 and the same warning
occurs.) You could use this to produce a test file. If you'd
prefer I send a file I can post it to a file exchange
service.>>> import numpy as np>>>>>>
from osgeo import gdal>>>
print(gdal.__version__)3.9.2e>>>
gdal.UseExceptions()>>>>>> # Create the
dataset as float64 with 1 band>>> f =
'has_nans.img'>>> drv =
gdal.GetDriverByName('HFA')>>> ds = drv.Create(f, 100,
100, 1, gdal.GDT_Float64)>>>>>> # Make some
fake data; set some cells to nan, although this is not necessary
to repro the warning>>> data = np.arange(100*100,
dtype=float).reshape(100,100)>>> data[0:20,0:30] =
float('nan')>>>>>> # Write the data to the
band>>> band = ds.GetRasterBand(1)>>>
band.SetNoDataValue(float('nan'))0>>>
band.WriteArray(data, 0, 0)0>>>>>> # Close the
dataset>>> del band, ds>>>>>> # Open
it again - warning happens here>>> ds = gdal.Open(f,
gdal.GA_ReadOnly)Warning 1: NaN converted to INT_MAX.JasonOn
5/8/25 18:39, Even Rouault wrote:There are metadata fields that
the HFA driver opens. That must come from that. Always shutting
down the warning could be inappropriate, but perhaps in the
context where the warning is emitted the driver could avoid
emitting it. But we need to have access to the file to better
understand the call path.Le 09/05/2025 à 00:35, Jason Roberts a
écrit :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.JasonOn 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 investigateEvenLe
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.078554As 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
_______________________________________________
<br>
gdal-dev mailing list
<br>
<a class="moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>
<br>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fgdal-dev&data=05%7C02%7Cjason.roberts%40duke.edu%7C7800a2bcc6734e514f2508dd8ee0f36a%7Ccb72c54e4a314d9eb14a1ea36dfac94c%7C0%7C0%7C638823818986070091%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=YAdFj2bnDMKNhN4CC3zePuwsowSnLHKE0y6cGtRcvzw%3D&reserved=0</a>
<br>
</blockquote>
<br>
</blockquote>
<br>
</body>
</html>