Skip to content
Prev 4881 / 29559 Next

readGDAL() and HDF5 files

On Sat, 24 Jan 2009 12:56:13 +0100 (CET),
Roger Bivand <Roger.Bivand at nhh.no> wrote:

            
I did provide most of this information in my first post, although I
forgot to include info on non-R software, so here it is again:

R> sessionInfo()
R version 2.8.1 (2008-12-22) 
x86_64-pc-linux-gnu 

locale:
LC_CTYPE=en_CA.UTF-8;LC_NUMERIC=C;LC_TIME=en_CA.UTF-8;LC_COLLATE=en_CA.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_CA.UTF-8;LC_PAPER=en_CA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_CA.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgdal_0.6-5     sp_0.9-29       slmisc_0.7.0    lattice_0.17-20

loaded via a namespace (and not attached):
[1] grid_2.8.1


and Debian sid libgdal1-1.5.2-3, which lags behind slightly the upstream
version.  I'm also using Debian sid's libhdf5-serial-1.6.6-0 for the
HDF5 libraries.  OSGeo4W is only for MS Windows IIUC.  So we may not be
able to properly compare our results.

For what it's worth, this is what I tried with one of the NetCDF files
(using Debian sid's libnetcdf4 1:3.6.2-3.1, where ncdump-hdf is
equivalent to the upstream ncdump facility):

---<--------------------cut here---------------start------------------->---
$ ncdump-hdf -h ice_conc_nh_200901151200.nc 
netcdf ice_conc_nh_200901151200 {
dimensions:
	time = 1 ;
	ni = 760 ;
	nj = 1120 ;

variables:
	long time(time) ;
		time:long_name = "reference time of sea ice file" ;
		time:units = "seconds since 1981-01-01 00:00:00" ;
	float lat(nj, ni) ;
		lat:long_name = "latitude" ;
		lat:units = "degrees_north" ;
	float lon(nj, ni) ;
		lon:long_name = "longitude" ;
		lon:units = "degrees_east" ;
	char polar_stereographic ;
		polar_stereographic:grid_mapping_name = "polar_stereographic" ;
		polar_stereographic:straight_vertical_longitude_from_pole = -45.f ;
		polar_stereographic:latitude_of_projection_origin = 90.f ;
		polar_stereographic:standard_parallel = 70.f ;
		polar_stereographic:false_easting = -3850.f ;
		polar_stereographic:false_northing = 5850.f ;
		polar_stereographic:proj4_string = "+proj=stere +a=6378273 +b=6356889.44891 +lat_0=90 +lat_ts=70 +lon_0=-45" ;
	short ice_concentration(time, nj, ni) ;
		ice_concentration:long_name = "sea ice concentration" ;
		ice_concentration:standard_name = "ice_concentration" ;
		ice_concentration:units = "%" ;
		ice_concentration:coordinates = "lon lat" ;
		ice_concentration:grid_mapping = "polar_stereographic" ;
		ice_concentration:source = "EUMETSAT OSI SAF" ;
		ice_concentration:missing_value = -32767s ;
		ice_concentration:_FillValue = -32767s ;
		ice_concentration:valid_min = 0.f ;
		ice_concentration:valid_max = 100.f ;
		ice_concentration:scale_factor = 0.0099999998f ;
		ice_concentration:add_offset = 0.f ;
	byte confidence_level(time, nj, ni) ;
		confidence_level:long_name = "confidence level" ;
		confidence_level:units = "1" ;
		confidence_level:coordinates = "lon lat" ;
		confidence_level:grid_mapping = "polar_stereographic" ;
		confidence_level:missing_value = '\0' ;
		confidence_level:_FillValue = '\0' ;
		confidence_level:valid_min = '\1' ;
		confidence_level:valid_max = '\5' ;
		confidence_level:comment = "0 Unprocessed; 1 Erroneous; 2 Unreliable; 3 Acceptable; 4 Good; 5 Excellent" ;
	short quality_index(time, nj, ni) ;
		quality_index:long_name = "quality index" ;
		quality_index:units = "1" ;
		quality_index:coordinates = "lon lat" ;
		quality_index:grid_mapping = "polar_stereographic" ;
		quality_index:missing_value = 0s ;
		quality_index:_FillValue = 0s ;
		quality_index:comment = "Contains bitmap with quality flags, see Users Manual for details" ;

// global attributes:
		:title = "Total Sea Ice Concentration from EUMETSAT OSI SAF" ;
		:conventions = "CF-1.0" ;
		:netcdf_version_id = "3.5.1 of Feb  7 2008 11:53:33 $" ;
		:creation_date = "2009-01-16" ;
		:product_version = "2.1" ;
		:software_version = "3.2" ;
		:reference = "OSI SAF Sea Ice Product Manual, Andersen S., Breivik L.A., Eastwood S., God?y ?., Lind M., Porcires M., Schyberg H., v3.5, January 2007" ;
		:comment = "For more information about the OSI SAF Sea Ice products, see http://saf.met.no" ;
		:sensor = "Multi sensor" ;
		:spatial_resolution = "10.0km" ;
		:area = "Northern Hemipshere" ;
		:southernmost_latitude = 31.08831f ;
		:northernmost_latitude = 89.934723f ;
		:westernmost_longitude = -180.f ;
		:easternmost_longitude = 179.92558f ;
		:start_date = "2009-01-15 UTC" ;
		:start_time = "00:00:00 UTC" ;
		:stop_date = "2009-01-15 UTC" ;
		:stop_time = "23:59:59 UTC" ;
		:field_type = "daily" ;
		:institution = "EUMETSAT OSI SAF" ;
		:institution_references = "http://www.osi-saf.org" ;
		:contact = "osisaf-manager at met.no" ;
		:operational_status = "operational" ;
}
$ gdalinfo ice_conc_nh_200901151200.nc 
Segmentation fault
---<--------------------cut here---------------end--------------------->---

As can be seen, these files have more datasets.  Presumably the segfault
I'm getting in R stems from the same problem with gdal above:

---<--------------------cut here---------------start------------------->---
R> ncdata <- "ice_conc_nh_200901151200.nc"
R> p4s <- NA
R> ice <- readGDAL(ncdata, p4s=p4s)

 *** caught segfault ***
address 0x1050, cause 'memory not mapped'

Traceback:
 1: .Call("RGDAL_OpenDataset", as.character(filename), TRUE, PACKAGE = "rgdal")
 2: .local(.Object, ...)
 3: initialize(value, ...)
 4: initialize(value, ...)
 5: new("GDALReadOnlyDataset", filename)
 6: GDAL.open(fname)
 7: readGDAL(ncdata, p4s = p4s)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
---<--------------------cut here---------------end--------------------->---

although note that I don't know how to tell readGDAL to access the
dataset that contains the actual grid I want (ice_concentration) for
this file format.

Anyway, based on your analysis below, it does seem as if the file header
is not providing metadata that GDAL can actually understand.  Otherwise
gdalinfo should not segfault like that.  I also get the same messed up
image I get in R if I use gdaltranslate to see a TIFF image of the file.

Thanks for looking into this.  I can live using your data "molesting"
approach for now! :-)


Cheers,
Seb
R> summary(ice)
Cheers,