Skip to content

Instantly share code, notes, and snippets.

View azvoleff's full-sized avatar

Alex Zvoleff azvoleff

View GitHub Profile
# Script to test basic handling of raster images with distributedR. Loads
# imagery from a Vertica database.
#
# Alex Zvoleff, azvoleff@conservation.org, July 2014
library(distributedR)
library(vRODBC)
Sys.setenv(VERTICAINI="/home/alexz/vertica.ini")
Sys.setenv(ODBCINI="/home/alexz/odbc.ini")
#distributedR_start()
library(raster)
library(stringr)
img_file <- 'PSH_mosaic_2010_predictors.tif'
img <- stack(img_file)
img <- setMinMax(img)
# Setup a list with metadata on the image.
img_meta <- list(site=str_extract(img_file, '^[a-zA-Z]*'),
@azvoleff
azvoleff / parallel_example.R
Last active August 29, 2015 14:00
Parallel processing example
library(foreach)
library(doParallel)
# In the call below, 2 is the number of cores to use - set this to be less than
# the total number of cores you have.
cl <- makeCluster(2)
results <- foreach(i=1:5, .packages=c('pkg1', 'pkg2')) %dopar% {
# Do some stuff in here, and save the results in "results"