[gdal-dev] Specify data type on opening a netcdf
Andrew C Aitchison
andrew at aitchison.me.uk
Fri Jul 31 09:21:45 PDT 2020
On Fri, 31 Jul 2020, Federico Gianoli wrote:
> Thanks Even,
>
> 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.
> 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.
>
> NC_GLOBAL#title=10-daily Normalized Difference Vegetation Index 333M:
> GLOBE 2020-06-21T00:00:00Z
> NDVI#add_offset=-0.079999998
> NDVI#flag_meanings=Missing cloud snow sea background
> NDVI#flag_values={251,252,253,254,255}
> NDVI#grid_mapping=crs
> NDVI#missing_value=255
> NDVI#scale_factor=0.0040000002
> NDVI#valid_range={0,250}
> NDVI#_FillValue=255
Does SNAP allow you to display the values with more precision ?
If they were exactly -0.08 and 0.004 before conversion to Float64
the values actually stored will be more like -0.08000000000000000167
and 0.00400000000000000008 (printed in C with "%.20lf")
Could the initial data have been Float32, converted to Float64
to be stored in the netcdf ?
I guess what you really want is for gdal to read in Float64 data and
convert it to Float32 for processing/outout ?
Evan's suggestion of "-ot Flat32" will give you 32bit output.
>> 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.
>>
>> If you need to override it, your best option is to use the -ot Float32
>> switch of gdal_translate to down cast.
--
Andrew C. Aitchison Kendal, UK
andrew at aitchison.me.uk
More information about the gdal-dev
mailing list