0

I want to convert all subdatasets from an .nc4 file (Example file) to GeoTIFF files to work with in R (for visualisation). I try to do this with the following zsh script:

gdal_translate -unscale -sds -a_nodata -9999 -ot Float32 -of GTiff input.nc4 output.tif

The output, however, contains here and there negative values in the raster data (take subdataset 18 as an example), while there were no negative values in the input raster subdataset (check with gdalinfo).

I used cdo mergetime and cdo timmean for preprocessing, but I expect that this did not result in the errors.

What is the source of this 'error', and how can I solve this?

1 Answer 1

0

I don't think it's an error, the negative values are already present in the original file. See for example:

from osgeo import gdal

fn = 'NETCDF:"GLDAS_CLSM025_DA1_D.A20150108.022.nc4":ECanop_tavg'

info = gdal.Info(fn, format="json", computeMinMax=True, stats=True)

{k:v for k,v in info["bands"][0]["metadata"][''].items() if k.startswith("STATISTICS")}
{'STATISTICS_MAXIMUM': '4.2967963963747e-05',
 'STATISTICS_MEAN': '5.1214917809763e-07',
 'STATISTICS_MINIMUM': '-0.00042517101974227',
 'STATISTICS_STDDEV': '6.5606014858318e-06'}

For very large rasters, gdal might take a subset of the data to calculate the statistics, unless forced not to. This didn't happen for me in this case, but perhaps it's machine-specs specific. Something like that could potentially miss some of the extreme values in the file. See:
https://gdal.org/programs/gdalinfo.html#cmdoption-gdalinfo-mm

The values reported by gdal also match the ones already added in the metadata of the original netcdf:

{k:v for k,v in info["bands"][0]["metadata"][''].items() if k.startswith("v")}
{'vmax': '4.2967964e-05', 'vmin': '-0.00042517102'}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.