[GIS] Converting Sentinel-3 data (netcdf) to GeoTIFF

gdalnetcdfsentinel-snap

I'm trying to convert Sentinel-3 data to GeoTiff file. The Sentinel-3 data comes as separate nc files (netcdf): a file for each spectral band and a nc file for qualityFlags, geo_coordinates etc' and an xml file. The official why to read Sentinel-3 data is to use the SNAP software and loading to SNAP the xml file that directs SNAP to the different files. I would like to do it using a python script, but I can't figure how. I tried GDAL translate but it does not make the connection between the spectral band file and the coordinate file. I am able to read each nc file separately and to read the coordinates nc file as text/array.

How can I combine the spectral band data with the coordinate data to create a Geotiff?

My guess is that it is possible doing that by using GDAL but I can't find the way. Is anyone familiar with Sentinel-3 data?
I'm using python 2.7 on win10, I have GDAL 2.1

Best Answer

it's a bit old but here I am. Unfortunately GDAL does not fully support the NetCDF standard and Sentinel 3 netcdf are one of those unfortunate case.

The following is a simple script written in kotlin unsing the java bindings:

    println(" * Converting $prodName...")
    val wgs84 = SpatialReference()
    wgs84.ImportFromEPSG(4326)

    val lst = gdal.Open("NETCDF:$prodName/LST_in.nc:LST")
    val map = mapOf(
            "LINE_OFFSET" to "1", "LINE_STEP" to "1",
            "PIXEL_OFFSET" to "1", "PIXEL_STEP" to "1",
            "X_BAND" to "1", "X_DATASET" to "NETCDF:$prodName/geodetic_in.nc:longitude_in",
            "Y_BAND" to "1", "Y_DATASET" to "NETCDF:$prodName/geodetic_in.nc:latitude_in"
    )

    lst.SetMetadata(Hashtable(map), "GEOLOCATION")

    val warp = gdal.AutoCreateWarpedVRT(lst, wgs84.ExportToWkt())

    gdal.Translate("$prodName/lst.tif", warp, TranslateOptions( gdal.ParseCommandLine("-of gtiff -oo COMPRESS=LZW ") ) )

    println(" * Complete")

this perfectly works with Sentinel 1 OCN products, but with Sentinel 3 GDAL gives some strange errors while parsing the file:

Warning 1: NetCDF driver detected file type=5, but libnetcdf detected type=3
Warning 1: No UNIDATA NC_GLOBAL:Conventions attribute
Warning 1: NetCDF driver detected file type=5, but libnetcdf detected type=3
Warning 1: No UNIDATA NC_GLOBAL:Conventions attribute
Warning 1: NetCDF driver detected file type=5, but libnetcdf detected type=3
Warning 1: No UNIDATA NC_GLOBAL:Conventions attribute
ERROR 1: Too many points (441 out of 441) failed to transform, unable to compute output bounds.
ERROR 1: IReadBlock failed at X offset 2, Y offset 0
ERROR 1: GetBlockRef failed at X block offset 2, Y block offset 0

After some throubleshooting it seems that it does not automatically apply the scale factor and offset of each variable, and so he have to deal with raw lat-lon coordinates and he does not know what to do with it.

I hope this will get fixed soon