I am trying to raster::mosaic
bunch of .tif
files extracted from hdf4
MODIS files. My script is working fine but I am puzzled by the range of raster values (min, max)
before and after data processing. The original hdf4
rasters are 8 bits integer raster ranged between 0-255 for every individual raster files before mosaicing. However, when I do a raster mosaic then the resulting raster is ranged between 0-25. My question is why?
I tried to reproduce this through a reproducible example but the problem doesn't apply to any example data such as below:
#------------------------
rx1 <- raster(nrows=2400, ncols=2400, vals = floor(runif(5760000, min=0, max=256)) )
extent(rx1) <- c(11119505, 12231456, -4447802, -3335852)
rx2 <- raster(nrows=2400, ncols=2400, vals = floor(runif(5760000, min=0, max=256)) )
extent(rx2) <- c(12231456, 13343406, -4447802, -3335852)
lr.1 <- list()
lr.1[[1]] <- rx1
lr.1[[2]] <- rx2
lr.1$fun <- mean
rast.mosaic1 <- do.call(mosaic,lr.1)
rast.mosaic1
#class : RasterLayer
#dimensions : 2400, 4800, 11520000 (nrow, ncol, ncell)
#resolution : 463.3129, 463.3125 (x, y)
#extent : 11119505, 13343407, -4447802, -3335852 (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
#data source : in memory
#names : layer
#values : 0, 255 (min, max)
If the same line of codes is applied to this data, then the result is:
lr.2 <- list()
lr.2[[1]] <- r[[1]]
lr.2[[2]] <- r[[3]]
lr.2$fun <- mean
rast.mosaic2 <- do.call(mosaic,lr.2)
rast.mosaic2
#class : RasterLayer
#dimensions : 2400, 4800, 11520000 (nrow, ncol, ncell)
#resolution : 463.3127, 463.3127 (x, y)
#extent : 11119505, 13343406, -4447802, -3335852 (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs
#data source : in memory
#names : layer
#values : 0, 25.4 (min, max)