Ticket #1894 (new defect)

Opened 4 years ago

Last modified 2 months ago

netcdf driver does not support irregular grids (was: NetCDF file lacks georeferencing)

Reported by: warmerdam Owned by: warmerdam
Priority: high Milestone:
Component: GDAL_Raster Version: svn-trunk
Severity: normal Keywords: netcdf
Cc: malaret@…, dnadeau, PCJ, kyle

Description (last modified by kyle) (diff)

The attached netcdf file does not have any georeferencing reported, though it does have lat, and lon arrays. It seems like the lat and lon values are irregular, so it likely couldn't be represented using a geotransform, but perhaps it should be represented as having geolocation arrays (see RFC 4)?

dimensions:
        xdim = 300 ;
        ydim = 200 ;
variables:
        float lon(xdim) ;
                lon:long_name = "longitude" ;
                lon:units = "degrees" ;
                lon:scale_factor = 1.f ;
        float lat(ydim) ;
                lat:long_name = "latitude" ;
                lat:units = "degrees" ;
                lat:scale_factor = 1.f ;
        float ssha(ydim, xdim) ;
                ssha:long_name = "Gridded SSH anomaly in GoM" ;
                ssha:units = "centimeters" ;
                ssha:scale_factor = 0.1f ;

I wonder if the proposed netcdf improvements in #1808 would help?

Filed on behalf of ACT (a project sponsor).

Attachments

c001.dt_ssha.nc Download (236.9 KB) - added by warmerdam 4 years ago.
Problem NetCDF file

Change History

Changed 4 years ago by warmerdam

Problem NetCDF file

Changed 2 years ago by kyle

  • cc malaret@…, dnadeau, PCJ, kyle added; malaret@… removed

Changed 15 months ago by kyle

  • description modified (diff)

Changed 15 months ago by kyle

When gdalinfo is run on this file, it reports only 1 band. the lat/lon bands are not read in as bands. I am familiarizing myself with the driver more and more, but it appears that I would have to populate two bands for lat/lon in order to use the geolocation array metadata. If that is the case, should the lat/lon bands always be imported as bands? I am a little confused.

Changed 2 months ago by etourigny

  • summary changed from NetCDF file lacks georeferencing to netcdf driver does not support irregular grids (was: NetCDF file lacks georeferencing)

The file has the following structure which is not standard

$ ncdump -h c001.dt_ssha.nc  
netcdf c001.dt_ssha {
dimensions:
	xdim = 300 ;
	ydim = 200 ;
variables:
	float lon(xdim) ;
		lon:long_name = "longitude" ;
		lon:units = "degrees" ;
		lon:scale_factor = 1.f ;
	float lat(ydim) ;
		lat:long_name = "latitude" ;
		lat:units = "degrees" ;
		lat:scale_factor = 1.f ;
	float ssha(ydim, xdim) ;
		ssha:long_name = "Gridded SSH anomaly in GoM" ;
		ssha:units = "centimeters" ;
		ssha:scale_factor = 0.1f ;

// global attributes:
		:creation_date = "Thu Mar 29 12:48:26 2007" ;
		:title = "Map of NRT-SSHA in GoM from Jason-1" ;
}

$ cdo sinfo c001.dt_ssha.nc 
   File format: netCDF
    -1 : Institut Source   Param       Time Typ  Grid Size Num  Levels Num
     1 : unknown  unknown  -1          con  F32       300   1       1   1
     2 : unknown  unknown  -2          con  F32       200   2       1   1
     3 : unknown  unknown  -3          con  F32     60000   3       1   1
   Horizontal grids :
     1 : generic      > size      : dim = 300
     2 : generic      > size      : dim = 200
     3 : generic      > size      : dim = 60000  nx = 300  ny = 200
   Vertical grids :
     1 : surface                  : 0 
cdo sinfo: Processed 3 variables. ( 0.00s )

Other software such as cdo and ncview are also unable to correctly identify this data, therefore we cannot support this particular format.

The file can be fixed with the "ncrename" utility from "NCO" like:

ncrename -d xdim,lon tmp1.nc
ncrename -d ydim,lat tmp1.nc

The resulting is standard and is supported by ncview and cdo:

$ ncdump -h tmp1.nc
netcdf tmp1 {
dimensions:
	lon = 300 ;
	lat = 200 ;
variables:
	float lon(lon) ;
		lon:long_name = "longitude" ;
		lon:units = "degrees" ;
		lon:scale_factor = 1.f ;
	float lat(lat) ;
		lat:long_name = "latitude" ;
		lat:units = "degrees" ;
		lat:scale_factor = 1.f ;
	float ssha(lat, lon) ;
		ssha:long_name = "Gridded SSH anomaly in GoM" ;
		ssha:units = "centimeters" ;
		ssha:scale_factor = 0.1f ;

// global attributes:
		:creation_date = "Thu Mar 29 12:48:26 2007" ;
		:title = "Map of NRT-SSHA in GoM from Jason-1" ;
		:history = "Sun Dec  4 03:58:32 2011: ncrename -d ydim,lat tmp1.nc\n",
			"Sun Dec  4 03:58:28 2011: ncrename -d xdim,lon tmp1.nc" ;
}
$ cdo sinfo tmp1.nc
   File format: netCDF
    -1 : Institut Source   Param       Time Typ  Grid Size Num  Levels Num
     1 : unknown  unknown  -1          con  F32     60000   1       1   1
   Horizontal grids :
     1 : lonlat       > size      : dim = 60000  nlon = 300  nlat = 200
                        lon       : first = 262.5  last = 278.5  degrees
                        lat       : first = 18.5  last = 30.5  degrees
   Vertical grids :
     1 : surface                  : 0 
cdo sinfo: Processed 1 variable. ( 0.00s )

However, the grid structure is unevenly-spaced, which is not supported by the driver:

$ gdalinfo --debug on tmp1.nc
GDAL_netCDF: 
=====
calling nc_open( tmp1.nc )

GDAL_netCDF: driver detected file type=1, libnetcdf detected type=1
GDAL_netCDF: dim_count = 2
Warning 1: No UNIDATA NC_GLOBAL:Conventions attribute
GDAL_netCDF: var_count = 3
GDAL_netCDF: 
=====
SetProjectionFromVar( 2 )

GDAL_netCDF: bIsGdalFile=0 bIsGdalCfFile=0 bBottomUp=1
GDAL_netCDF: set bBottomUp = 1 from Y axis
GDAL_netCDF: Longitude is not equally spaced.
GDAL_netCDF: bGotGeogCS=0 bGotCfSRS=0 bGotGeoTransform=1
GDAL_netCDF: SetGeoTransform(0.000000,1.000000,0.000000,0.000000,0.000000,1.000000)
...

This issue has been added to netcdf improvements page (section Dimension/grid issue).

Note: See TracTickets for help on using tickets.