[R-sig-Geo] raster package. raster() function scales data when reading from HDF

Dutrieux, Loic loic.dutrieux at wur.nl
Fri May 3 10:54:14 CEST 2013


Dear all,

I've noticed some unexpected behavior while loading HDF4 data with the raster() function. See the example below.

# In the terminal
mkdir ~/MODIS_test
cd ~/MODIS_test/
wget ftp://e4ftl01.cr.usgs.gov/MOLT/MOD13A2.005/2003.03.06/MOD13A2.A2003065.h10v10.005.2008301134056.hdf # 7MB

# R
library(raster)
library(MODIS)
sds = getSds('~/MODIS_test/MOD13A2.A2003065.h10v10.005.2008301134056.hdf')
a = raster(sds$SDS4gdal[1])
summary(a)

Returns the following results:
MOD13A2.A2003065.h10v10.005.2008301134056.hdf..MODIS_Grid_16DAY_1km_VI.1_km_16_days_NDVI
Min.                                                                                   -19580000
1st Qu.                                                                                 20930000
Median                                                                                  43820000
3rd Qu.                                                                                 63740000
Max.                                                                                    99650000
NA's                                                                                           0

Which is outside of the valid range by a factor of 10000.

My first guess is that it has to do with the version of GDAL intalled; this started after upgrading from gdal1.7.3. to gdal1.9.2.

Any idea?

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] MODIS_0.6-4   bitops_1.0-5  rgdal_0.8-6   raster_2.1-25 sp_1.0-8     

loaded via a namespace (and not attached):
[1] grid_2.15.2     lattice_0.20-15 tools_2.15.2   


Thanks in advance
Best regards,

--
Loïc Dutrieux
Laboratory of Geo-Information Science and Remote Sensing
Wageningen University
The Netherlands



More information about the R-sig-Geo mailing list