Skip to content

Instantly share code, notes, and snippets.

@adamhsparks
Last active August 29, 2015 14:03
Show Gist options
  • Save adamhsparks/4419aa1b711f72c7fa78 to your computer and use it in GitHub Desktop.
Save adamhsparks/4419aa1b711f72c7fa78 to your computer and use it in GitHub Desktop.
Compare output from EPIRICE when using 1º and 0.25º data
##############################################################################
# title : Compare_EPIRICE_Outputs.R;
# purpose : Compare output from EPIRICE when using 1º and 0.25º data;
# producer : prepared by A. Sparks;
# last update : in Los Baños, Laguna, Jun. 2014;
# inputs : EPIRICE output from 2001-2008;
# outputs : histograms and graphs of comparison for leaf blast at 1º and 0.25º;
# remarks 1 : ;
# Licence: : GPL2;
##############################################################################
#### Load libraries #####
library(raster)
#### End load libraries ####
#### Load data ####
quarterdeg <- stack(list.files(path = "/Volumes/Workspace/Kyle/Project_EPIRICE/PK1_audpc/PK1_blast_audpc/", pattern = "[[:graph:]]+.tif", full.names = TRUE)) # load all the files for leaf blast
onedeg <- stack(list.files(path = "~/Data/EPIRICE Output/1deg", pattern = "leafblast[[:digit:]]{4}.tif", full.names = TRUE)) # load all the files for leaf blast
onedeg <- crop(onedeg, quarterdeg) # crop the onedeg, whole world, by the extent of quarterdeg, Asia
#### End load data ####
#### Start data munging ####
onedeg <- dropLayer(onedeg, c(1, 2, 3, 4)) # drop layers for 1997 to 2000
quarterdeg <- dropLayer(quarterdeg, c(9, 10, 11, 12)) # drop layers for 2009 to 2011
names(onedeg) <- names(quarterdeg) <- c("2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008") # give layers uniform names now for ease of use
#### End data munging ####
#### Start data analysis ####
onedeg.sd <- calc(onedeg, fun = sd)
quarterdeg.sd <- calc(quarterdeg, fun = sd)
onedeg.avg <- calc(onedeg, fun = mean)
quarterdeg.avg <- calc(quarterdeg, fun = mean)
#### End data analysis ####
#### Start data visualisation ####
## Histograms
hist(onedeg.sd)
hist(quarterdeg.sd)
hist(onedeg.avg)
hist(quarterdeg.avg)
## Maps
plot(onedeg.avg)
plot(quaterdeg.avg)
plot(onedeg.sd)
plot(quarterdeg.sd)
#### End data visualisation ####
#eos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment