Skip to content
Prev 18177 / 29559 Next

raster package. raster() function scales data when reading from HDF

Thanks Matteo,

I dug the problem a bit, and found out where it may come from. There is a as.is argument in the getRasterData function (rgdal) that if set to FALSE applies a scaling factor fetched from the metadata to the data. The argument default to FALSE. When set to TRUE, no scaling is applied.

# Get sds from data previously downloaded
sds = getSds('~/MODIS_test/MOD13A2.A2003065.h10v10.005.2008301134056.hdf')

# Read the data first using defaults
a = readGDAL(sds$SDS4gdal[1])
summary(a)

Data attributes:
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max.      NA's 
-19790000  20790000  43840000  43680000  63740000  99860000   1043545 

# With as.is=TRUE
a = readGDAL(sds$SDS4gdal[1], as.is=TRUE)
summary(a)

Data attributes:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
  -1979    2079    4384    4368    6374    9986 1043545 

I'm not convinced that automatically scaling data is such a good default setting. 
Unfortunately the raster() function does not seem to take the as.is argument and therefore uses the default settings of getRasterData(). Any way we could get more control of that?

Cheers,
Lo?c