S2 Resampling / Netcdf-CF Export / Qgis import

Hi there,

I’m trying to build a compatible Netcdf/CF 1.6 file (from any kind of sentinel2) and at the same time readable from gdal (or software based on gdal api).

I did the following:

  1. Download S2 (.zip) and unzip to .SAFE
  2. Open in Snap (last version)
  3. Perform a Optical-Geometric-S2 Resampling Processor
    image
  4. Choose Netcdf/CF as result/export format
  5. Try to import as a layer in Qgis (3.4)

    Invalid layer…
  6. Try also a gdalinfo on the same

I’m missing something or I did something wrong?

Thanks, Mirko.

1 Like

gdalinfo needs a single grid data set. Your screen capture isn’t readable on this laptop screen, but I’m guessing you used the filename without specifying the subdataset. Here is an example from a NASA standard mapped image:

$ gdalinfo A2006167181000.smi_chlor_a_mn.nc
Driver: netCDF/Network Common Data Format
Files: A2006167181000.smi_chlor_a_mn.nc
Size is 512, 512
Coordinate System is `'
Metadata:
  NC_GLOBAL#cdm_data_type=grid
  NC_GLOBAL#Conventions=CF-1.6 ACDD-1.3
[...] 
Subdatasets:
  SUBDATASET_1_NAME=NETCDF:"A2006167181000.smi_chlor_a_mn.nc":chlor_a
  SUBDATASET_1_DESC=[768x768] mass_concentration_of_chlorophyll_in_sea_water (32-bit floating-point)
  SUBDATASET_2_NAME=NETCDF:"A2006167181000.smi_chlor_a_mn.nc":chlor_a_stdev
  SUBDATASET_2_DESC=[768x768] mass_concentration_of_chlorophyll_in_sea_water (32-bit floating-point)
  SUBDATASET_3_NAME=NETCDF:"A2006167181000.smi_chlor_a_mn.nc":palette
  SUBDATASET_3_DESC=[3x256] palette (8-bit unsigned integer)
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  512.0)
Upper Right (  512.0,    0.0)
Lower Right (  512.0,  512.0)
Center      (  256.0,  256.0)

Note the “subdataset” entries, for example:

$ gdalinfo NETCDF:"A2006167181000.smi_chlor_a_mn.nc":chlor_a
Driver: netCDF/Network Common Data Format
Files: A2006167181000.smi_chlor_a_mn.nc
Size is 768, 768
Coordinate System is `'
Origin = (-78.000002546447192,45.999998728019783)
Pixel Size = (0.020833339964706,-0.020833332504412)
Metadata:
  chlor_a#display_max=20
  chlor_a#display_min=0.0099999998
  chlor_a#display_scale=log
  chlor_a#long_name=Chlorophyll Concentration, OCI Algorithm
  chlor_a#reference=Hu, C., Lee Z., and Franz, B.A. (2012). Chlorophyll-a algorithms for oligotrophic oceans: A novel approach based on three-band reflectance difference, J. Geophys. Res., 117, C01011, doi:10.1029/2011JC007395.
  chlor_a#standard_name=mass_concentration_of_chlorophyll_in_sea_water
  chlor_a#units=mg m^-3
  chlor_a#valid_max=100
  chlor_a#valid_min=0.001
  chlor_a#_FillValue=-32767
  lat#long_name=Latitude
  lat#standard_name=latitude
  lat#units=degrees_north
  lat#valid_max=90
  lat#valid_min=-90
  lat#_FillValue=-999
  lon#long_name=Longitude
  lon#standard_name=longitude
  lon#units=degrees_east
  lon#valid_max=180
  lon#valid_min=-180
  lon#_FillValue=-999
  NC_GLOBAL#cdm_data_type=grid
  NC_GLOBAL#Conventions=CF-1.6 ACDD-1.3
  NC_GLOBAL#creator_email=data@oceancolor.gsfc.nasa.gov
  NC_GLOBAL#creator_name=NASA/GSFC/OBPG
  NC_GLOBAL#creator_url=https://oceandata.sci.gsfc.nasa.gov
  NC_GLOBAL#data_bins=153426
  NC_GLOBAL#data_maximum=97.059814
  NC_GLOBAL#data_minimum=0
  NC_GLOBAL#date_created=2019-11-06T12:35:18.000Z
  NC_GLOBAL#easternmost_longitude=-62
  NC_GLOBAL#end_orbit_number=21910
  NC_GLOBAL#geospatial_lat_max=46
  NC_GLOBAL#geospatial_lat_min=30
  NC_GLOBAL#geospatial_lat_resolution=0.020833334
  NC_GLOBAL#geospatial_lat_units=degrees_north
  NC_GLOBAL#geospatial_lon_max=-62
  NC_GLOBAL#geospatial_lon_min=-78
  NC_GLOBAL#geospatial_lon_resolution=0.020833334
  NC_GLOBAL#geospatial_lon_units=degrees_east
  NC_GLOBAL#history=l3mapgen ifile=A2006167181000.L3b_time.nc ofile=A2006167181000.smi_chlor_a_mn.nc product=chlor_a,chlor_a:stdev resolution=2km east=-62 west=-78 south=30 north=46 quiet
  NC_GLOBAL#id=L3/A2006167181000.L3b_time.nc
  NC_GLOBAL#institution=NASA Goddard Space Flight Center, Ocean Ecology Laboratory, Ocean Biology Processing Group
  NC_GLOBAL#instrument=MODIS
  NC_GLOBAL#l2_flag_names=ATMFAIL,LAND,HILT,HISATZEN,STRAYLIGHT,CLDICE,COCCOLITH,LOWLW,CHLWARN,CHLFAIL,NAVWARN,MAXAERITER,ATMWARN,HISOLZEN,NAVFAIL,FILTER,HIGLINT
  NC_GLOBAL#latitude_step=0.020833334
  NC_GLOBAL#latitude_units=degrees_north
  NC_GLOBAL#license=https://science.nasa.gov/earth-science/earth-science-data/data-information-policy/
  NC_GLOBAL#longitude_step=0.020833334
  NC_GLOBAL#longitude_units=degrees_east
  NC_GLOBAL#map_projection=Equidistant Cylindrical
  NC_GLOBAL#measure=Mean
  NC_GLOBAL#naming_authority=gov.nasa.gsfc.sci.oceandata
  NC_GLOBAL#northernmost_latitude=46
  NC_GLOBAL#number_of_columns=768
  NC_GLOBAL#number_of_lines=768
  NC_GLOBAL#platform=Aqua
  NC_GLOBAL#processing_level=L3 Mapped
  NC_GLOBAL#processing_version=Unspecified
  NC_GLOBAL#product_name=A2006167181000.smi_chlor_a_mn.nc
  NC_GLOBAL#project=Ocean Biology Processing Group (NASA/GSFC/OBPG)
  NC_GLOBAL#publisher_email=data@oceancolor.gsfc.nasa.gov
  NC_GLOBAL#publisher_name=NASA/GSFC/OBPG
  NC_GLOBAL#publisher_url=https://oceandata.sci.gsfc.nasa.gov
  NC_GLOBAL#southernmost_latitude=30
  NC_GLOBAL#spatialResolution=2.32 km
  NC_GLOBAL#standard_name_vocabulary=CF Standard Name Table v36
  NC_GLOBAL#start_orbit_number=21910
  NC_GLOBAL#suggested_image_scaling_applied=No
  NC_GLOBAL#suggested_image_scaling_maximum=20
  NC_GLOBAL#suggested_image_scaling_minimum=0.0099999998
  NC_GLOBAL#suggested_image_scaling_type=LOG
  NC_GLOBAL#sw_point_latitude=30.010416
  NC_GLOBAL#sw_point_longitude=-77.989586
  NC_GLOBAL#temporal_range=1-hour
  NC_GLOBAL#time_coverage_end=2006-06-16T18:14:58.000Z
  NC_GLOBAL#time_coverage_start=2006-06-16T18:10:01.000Z
  NC_GLOBAL#title=MODISA Level-3 Standard Mapped Image
  NC_GLOBAL#westernmost_longitude=-78
  NC_GLOBAL#_lastModified=2019-11-06T12:35:18.000Z
Corner Coordinates:
Upper Left  ( -78.0000025,  45.9999987)
Lower Left  ( -78.0000025,  29.9999994)
Upper Right ( -61.9999975,  45.9999987)
Lower Right ( -61.9999975,  29.9999994)
Center      ( -70.0000000,  37.9999990)
Band 1 Block=257x257 Type=Float32, ColorInterp=Undefined
  NoData Value=-32767
  Unit Type: mg m^-3
  Metadata:
    display_max=20
    display_min=0.0099999998
    display_scale=log
    long_name=Chlorophyll Concentration, OCI Algorithm
    NETCDF_VARNAME=chlor_a
    reference=Hu, C., Lee Z., and Franz, B.A. (2012). Chlorophyll-a algorithms for oligotrophic oceans: A novel approach based on three-band reflectance difference, J. Geophys. Res., 117, C01011, doi:10.1029/2011JC007395.
    standard_name=mass_concentration_of_chlorophyll_in_sea_water
    units=mg m^-3
    valid_max=100
    valid_min=0.001
    _FillValue=-32767

Qgis uses gdal under the hood, so should also use the subdataset names.

Thanks for the suggestion, but I did a (gdal) print for a specific dataset (the 4th)

You’re right, I think gdal works fine. The issue is that QGis 3.4 (that I hope uses the same version of gdal) doesn’t recognize the file at all (neither as georef-raster nor a raster).

gdalinfo /storage/mariomi/sample/S2A_MSIL1C_20170517T102031_N0205_R065_T32TMR_20170517T102352_s2resampled.nc -sd 4

`Driver: netCDF/Network Common Data Format
Files: /storage/mariomi/sample/S2A_MSIL1C_20170517T102031_N0205_R065_T32TMR_20170517T102352_s2resampled.nc
Size is 1830, 1830
Coordinate System is
Metadata:
B4#coordinates=lat lon
B4#long_name=Reflectance in band B4
B4#scale_factor=0.0001
B4#units=dl
B4#_Unsigned=true
NC_GLOBAL#Conventions=CF-1.4
NC_GLOBAL#start_date=17-MAY-2017 10:20:31.026000
NC_GLOBAL#stop_date=17-MAY-2017 10:20:31.026000
NC_GLOBAL#TileSize=512:512
Geolocation:
LINE_OFFSET=0
LINE_STEP=1
PIXEL_OFFSET=0
PIXEL_STEP=1
SRS=GEOGCS[“WGS 84”,DATUM[“WGS_1984”,SPHEROID[“WGS 84”,6378137,298.257223563,AUTHORITY[“EPSG”,“7030”]],AUTHORITY[“EPSG”,“6326”]],PRIMEM[“Greenwich”,0,AUTHORITY[“EPSG”,“8901”]],UNIT[“degree”,0.0174532925199433,AUTHORITY[“EPSG”,“9122”]],AUTHORITY[“EPSG”,“4326”]]
X_BAND=1
X_DATASET=NETCDF:"/storage/mariomi/sample/S2A_MSIL1C_20170517T102031_N0205_R065_T32TMR_20170517T102352_s2resampled.nc":lon
Y_BAND=1
Y_DATASET=NETCDF:"/storage/mariomi/sample/S2A_MSIL1C_20170517T102031_N0205_R065_T32TMR_20170517T102352_s2resampled.nc":lat
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 1830.0)
Upper Right ( 1830.0, 0.0)
Lower Right ( 1830.0, 1830.0)
Center ( 915.0, 915.0)
Band 1 Block=1830x1 Type=Int16, ColorInterp=Undefined
NoData Value=-32767
Unit Type: dl
Offset: 0, Scale:0.0001
Metadata:
coordinates=lat lon
long_name=Reflectance in band B4
NETCDF_VARNAME=B4
scale_factor=0.0001
units=dl
_Unsigned=true

Your example used galdinfo’s -sd option to select the subdataset. The example for MODIS Aqua used the GDAL ":filename: notation to specify a subdataset (also used for the lat and lon bands in your GDAL output). I’m not aware of a QGIS option corresponding to -sd – I always use the “format:filename:band” notation. If you tried that notation and it fails, you can try using a GDL Virtual Raster Table (.vrt), which QGIS also supports via GDAL. None of this is new, so either method should work for all recent versions of QGIS/GDAL. It is possible that QGIS is confused by something in the file metadata. You can try converting the band to a geoTIFF using GDAL to see if that is accepted by QGIS.

1 Like