<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>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.<br>
</p>
<div class="moz-cite-prefix">Le 09/05/2025 à 00:35, Jason Roberts a
écrit :<br>
</div>
<blockquote type="cite"
cite="mid:8d468679-aad9-4d65-8f9f-62551b414e2e@duke.edu">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<font face="Verdana">Hi Even,<br>
<br>
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.<br>
<br>
Jason<br>
</font><br>
<div class="moz-cite-prefix">On 5/8/25 17:51, Even Rouault wrote:<br>
</div>
<blockquote type="cite"
cite="mid:7f77f6f0-caea-4e70-9ed2-c3c8848bb00f@spatialys.com">
<p>Jason,</p>
<p>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</p>
<p>Even<br>
</p>
<div class="moz-cite-prefix">Le 08/05/2025 à 23:01, Jason
Roberts via gdal-dev a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:2d66b13b-34e6-460d-a687-90e0a4196eda@duke.edu"> <font
face="Verdana">Hi GDAL team,<br>
<br>
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?<br>
<br>
Here's some code demonstrating the message. If need be, I
can provide an example file, or write some code to generate
one.<br>
<br>
>>> import numpy as np<br>
>>> from osgeo import gdal<br>
>>> gdal.__version__ # this version is
packaged with ArcGIS Pro 3.4, but I don't think the version
matters<br>
'3.9.2e'<br>
>>> ds =
gdal.Open(r'\\conch\denmod\Covariates\NARW25\CMEMS_GLORYS\SST\1999\SST_199901.img',
gdal.GA_ReadOnly)<br>
Warning 1: NaN converted to INT_MAX.<br>
>>> band = ds.GetRasterBand(1)<br>
</font><font face="Verdana">>>>
gdal.GetDataTypeName(band.DataType)<br>
'Float32'<br>
</font><font face="Verdana">>>> band.GetNoDataValue()<br>
nan<br>
>>> arr = band.ReadAsArray() # the data look ok:<br>
>>> np.isnan(arr).sum()<br>
86788<br>
>>> (~np.isnan(arr)).sum()<br>
142985<br>
</font><font face="Verdana">>>> np.max(arr)<br>
nan<br>
</font><font face="Verdana">>>> np.nanmax(arr)<br>
27.078554<br>
<br>
As far as I can tell, the warning comes from this code in
gdal/frmts/hfa/hfafield.cpp:<br>
<br>
else if (std::isnan(dfDoubleRet))<br>
{<br>
CPLError(CE_Warning, CPLE_AppDefined,<br>
"NaN converted to INT_MAX.");<br>
nIntRet = nMax;<br>
}<br>
<br>
But I don't know if there are any negative ramifications
that will result.<br>
<br>
Thank you for your help. And, as always, thank you very much
for developing and maintaining GDAL.<br>
<br>
Jason<br>
<br>
</font> <br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated moz-txt-link-freetext"
href="mailto:gdal-dev@lists.osgeo.org" moz-do-not-send="true">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext"
href="https://lists.osgeo.org/mailman/listinfo/gdal-dev"
originalsrc="https://lists.osgeo.org/mailman/listinfo/gdal-dev"
moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com/"
originalsrc="http://www.spatialys.com/" moz-do-not-send="true">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</blockquote>
<br>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</body>
</html>