<div dir="ltr">Thanks Even,<div><br></div><div>If I look at the metadata of my netcdf, the values of "offset" and "scale factor" are in float64 instead of float32. So the correct values to read should be -0.08 as offset and 0.004 as scale factor. </div><div>If I open the netcdf in SNAP, for example, I am able to correctly see this information. So, I suppose that, by default, gdal reads metadata values  in float64 instead of 32bit, and I would like to know if there is a way to force gdal to read these values as float32.</div><div> <br>  NC_GLOBAL#title=10-daily Normalized Difference Vegetation Index 333M: GLOBE 2020-06-21T00:00:00Z<br>  NDVI#add_offset=-0.079999998<br>  NDVI#flag_meanings=Missing cloud snow sea background<br>  NDVI#flag_values={251,252,253,254,255}<br>  NDVI#grid_mapping=crs<br>  NDVI#missing_value=255<br>  NDVI#scale_factor=0.0040000002<br>  NDVI#valid_range={0,250}<br>  NDVI#_FillValue=255<br><br>Band 1 Block=3270x1272 Type=Byte, ColorInterp=Undefined<br>  NoData Value=255<br>  Offset: -0.0799999982118607,   Scale:0.00400000018998981<br>  Metadata:<br>    add_offset=-0.079999998<br>    flag_meanings=Missing cloud snow sea background<br>    flag_values={251,252,253,254,255}<br>    grid_mapping=crs<br>    long_name=Normalized Difference Vegetation Index 333M<br>    missing_value=255<br>    NETCDF_VARNAME=NDVI<br>    scale_factor=0.0040000002<br>    valid_range={0,250}<br>    _FillValue=255<br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno ven 31 lug 2020 alle ore 15:37 Even Rouault <<a href="mailto:even.rouault@spatialys.com">even.rouault@spatialys.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div style="font-family:monospace;font-size:9pt;font-weight:400;font-style:normal">
<p style="margin:0px;text-indent:0px">On vendredi 31 juillet 2020 15:04:45 CEST Federico Gianoli wrote:</p>
<p style="margin:0px;text-indent:0px">> Dear all,</p>
<p style="margin:0px;text-indent:0px">> I have an issue opening a netcdf with gdal. I should declare the data type</p>
<p style="margin:0px;text-indent:0px">> of my raster in gdal.Open().</p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> The Netcdf data type is declared in the metadata as "Float", but GDAL reads</p>
<p style="margin:0px;text-indent:0px">> this information as Float64 and not as Float32. This reading error</p>
<p style="margin:0px;text-indent:0px">> misinterprets my decimal values causing rounding errors.</p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> float 32 to float64 (wrong):</p>
<p style="margin:0px;text-indent:0px">> [0.9160000518, 0.920000052] > 0.92 --> [False, True] WRONG</p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> flaot32 to float32 (correct):</p>
<p style="margin:0px;text-indent:0px">> [0.916, 0.92] > 0.92 --> [False, False] CORRECT</p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> </p>
<p style="margin:0px;text-indent:0px">> Is there a way to specify the input data type?</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">No. What do you mean by "The Netcdf data type is declared in the metadata as "Float"" ? Is this some text attribute that would override the native data type, which would be Float64 ? the GDAL netCDF driver has proper support for both Float32 or Float64 based on the data types of variable.</p>
<p style="margin:0px;text-indent:0px">If you need to override it, your best option is to use the -ot Float32 switch of gdal_translate to down cast.</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">Even</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">-- </p>
<p style="margin:0px;text-indent:0px">Spatialys - Geospatial professional services</p>
<p style="margin:0px;text-indent:0px"><a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a></p></div></blockquote></div>