2

I need to create a function to interpolate noise values on a landsat image time series by the mean on a time span of 2 (xt+1 and xt-1).

I´m using the fmask product to detect cloud and shadow, then interpolation is applied.

For one time series:

Since c2 is the vector of fmask time series (2 for cloud and 4 for shadow), and t2 the vector of evi time series:

for (i in 2:(length(t2)-1)){ if (c2[i]==2 | c2[i]==4) t2[i]<-mean(c(t2[i-1], t2[i+1]))}

But it is not possible to do this using the calc function of raster package, because it does not works with functions with 2 parameters.

Any suggestion about how deal with this and apply this interpolation for all the pixels of the raster time series?

  • I guess this was supposed to work, but it still not :( ` for (i in 2:(length(stacklist)-1)){ re<-raster(stacklist[i]) re1<-raster(stacklist[i+1]) re0<-raster(stacklist[i-1]) rc<-raster(stacklist2[i]) if (rc[i]==2 | rc[i]==4) re[i]<-mean(c(re0[i],re1[i])) writeRaster(re,filename =paste0(substr(stacklist[i], 48, 59), "_filtered.tif")) } ` – Bindini Aug 7 '16 at 17:24
0

I am only answering in case someone are interested in: I could solve with this code:

for (i in 2:(length(stacklist)-1)){
 re<-raster(stacklist[i]) 
 re1<-raster(stacklist[i+1]) 
 re0<-raster(stacklist[i-1]) 
 rc<-raster(stacklist2[i]) 
 rm<-mean(re0,re1)
 re[which(rc[]==2 | rc[]==4)]<-rm[which(rc[]==2 | rc[]==4)]
 writeRaster(re,filename =paste0(substr(stacklist[i], 80, 86),"_filtered.tif"), overwrite=TRUE)}  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.