This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Original arthur: vikrant @ R help mailing list | |
## return the maximum CCF value along with corresponding lag value | |
## http://r.789695.n4.nabble.com/ccf-function-td2288257.html | |
fun.ccfmax <- function(a,b) { | |
d <- ccf(a, b, plot = FALSE) | |
cor = d$acf[,,1] | |
lag = d$lag[,,1] | |
res = data.frame(cor,lag) | |
res_max = res[which.max(res$cor),] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Thanks RobertH for sharing this very useful function | |
## http://stackoverflow.com/a/9937083 | |
fun.quickstack <- function(f) { | |
r <- raster(f[1]) | |
ln <- extension(basename(f), '') | |
s <- stack(r) | |
s@layers <- sapply(1:length(f), function(x){ r@file@name = f[x]; | |
r@layernames=ln[x]; r@data@haveminmax=FALSE ; r }) | |
s@layernames <- ln |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## m is the nonlinear model, x is the variable | |
r2 <- 1 - (deviance(m) / sum((x - mean(x)) ^ 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## RMSE: Root Mean Squared Error | |
## obs: observations | |
## pred: predictions | |
fun.rmse <- function(obs, pred) { | |
sqrt(mean((obs-pred)^2)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Convert shapefile to raster | |
## Packages | |
require(sp) | |
require(raster) | |
## Import shapefile | |
shp.x = readOGR('shapefile.shp', layer = 'shapefile') | |
## Create an empty raster |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## invoke system command to convert shapefiles to raster | |
## Please install gdal before using this snippet | |
## http://www.gdal.org | |
## 12000: the width of the output raster | |
## 6400: the height of the output raster | |
## layer: the attribute field | |
system(command = 'gdal_rasterize -a input -ts 12000 6400 -l | |
layer /Users/me/Desktop/input.shp /Users/me/Desktop/output.tif') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This expression will list all files within the dir.hdf | |
## directory which contains ‘h29v11’ AND ended with the ‘.hdf’ extension. | |
files.hdf.h29v11 <- list.files(dir.hdf, pattern = '*.h29v11.*.hdf$', | |
recursive = TRUE, full.names = TRUE) |
NewerOlder