Hi all,

I am trying to write an efficient script to calibrate hundreds of Landsat 8 
images. At a certain point of the calibration steps, I need to apply some 
coefficients in each layer of a raster stack.


This is one sample stack:fn <- system.file("external/test.grd", 
package="raster")

s  <- stack(fn, fn)

And these are sample coefficients:
mult <- c(0.0003342, 0.0005534) 
add  <- c(0.1, 0.2) 


What I need to is to apply each index of the coefficients to the correspondent 
index of the stack layer, like in this example:

s[[1]] <- (s[[1]] * mult[1]) + add[1]
s[[2]] <- (s[[2]] * mult[2]) + add[2]

This is my poor attempt, which obviously does not work:

cal.fun <- function(x) { 
x <- (x * mult) + add 
}

s.cal <- calc(s, cal.fun, progress='text')


Any ideas on how to do that?
 
Many thanks,
--
Thiago V. dos Santos
PhD student
Land and Atmospheric Science
University of Minnesota
http://www.laas.umn.edu/CurrentStudents/MeettheStudents/ThiagodosSantos/index.htm
Phone: (612) 323 9898

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to