README.md

ghgvcr

R implementation of the Greenhouse Gas Value Calculator

Citation: Kristina J. Teixeira and Evan H. Delucia 2011. The greenhouse gas value of ecosystems. Global Change Biology. 17(1):425–438 doi: 10.1111/j.1365-2486.2010.02220.x

Inputs

Outputs

produced by example below:

Installing the ghgvcr package on the PEcAn 1.2.6 VM

The bash and R code snippets below install dependencies, and only need to be run once.

sudo apt-get install git
sudo apt-get install libcurl4-openssl-dev # dependency of Rcurl, 

git clone https://github.com/dlebauer/pecan.git pecan
git clone https://github.com/dlebauer/ghgvcR.git ghgvcR
R 
install.packages(c("devtools", "roxygen2"), repos = "http://cran.us.r-project.org")
library(devtools)
install(ghgvcr)
install(pecan/utils)

Example of how to run the calculator

## Error: there is no package called 'ghgvcr'

options(warn = FALSE)
# test('../ghgvcR') example(ghgvcr)


## the following is equivalent to
config.xml <- system.file("config.xml", package = "ghgvcr")
config.list <- xmlToList(xmlParse(config.xml))
Error: could not find function "xmlToList"
ecosystem_data <- config.list$ecosystem_data
Error: object 'config.list' not found

x <- ghgvcr::ghgvc(options = config.list$options, ecosystem_data = config.list$ecosystem_data)
Error: there is no package called 'ghgvcr'


writeLines(x, "inst/extdata/output.json")
Error: object 'x' not found
write.csv(as.data.frame(fromJSON(x)), "inst/extdata/output.csv")
Error: could not find function "fromJSON"
multisite_config.xml <- system.file("multisite_config.xml", package = "ghgvcr")
multipft_config.list <- xmlToList(xmlParse(multipft_config.xml))
Error: could not find function "xmlToList"

x2 <- ghgvcr::ghgvc2(multipft_config.list)
Error: there is no package called 'ghgvcr'

writeLines(x2, "inst/extdata/multipft_output.json")
Error: object 'x2' not found
write.csv(as.data.frame(fromJSON(x2)), "inst/extdata/multipft_output.csv")
Error: could not find function "fromJSON"

Plots:

library(ggplot2)
# number of ecosystems:
n.ecosystems <- length(names(ecosystem_data))
Error: object 'ecosystem_data' not found
for (i in 1:n.ecosystems) {
    result <- ecosystem_data[[i]]
    ecosystem.name <- result$name
    if (i == 1) {
        result.df <- as.data.frame(result)

    } else {
        result.df <- rbind(result.df, as.data.frame(result))
    }
    rownames(result.df)[i] <- gsub(" ", "", ecosystem.name)
}
Error: object 'n.ecosystems' not found

# identify cols with numbers
result.num <- suppressWarnings(as.numeric(result))
Error: object 'result' not found
num.logical <- !(is.na(result.num) | result.num == -9999)
Error: object 'result.num' not found
result.df <- result.df[, !(result.num == -9999 | is.na(result.num))]
Error: object 'result.df' not found

# transpose data.frame for plotting:
result.tdf <- cbind(variable = names(result.df), as.data.frame(t(result.df)))
Error: object 'result.df' not found

forcings.index <- grepl("F", names(result.df))
Error: object 'result.df' not found
forcings.names <- names(result.df)[forcings.index]
Error: object 'result.df' not found


forcings <- result.tdf[forcings.index, ]
Error: object 'result.tdf' not found
forcings.long <- melt(forcings, id.vars = "variable")
Error: could not find function "melt"
colnames(forcings.long) <- c("variable", "ecosystem", "value")
Error: object 'forcings.long' not found

ggplot(data = forcings.long, aes(x = variable, y = value, fill = ecosystem)) + 
    geom_bar(position = "dodge", stat = "identity") + ggtitle(label = "Example plot: values of F for two ecosystems") + 
    xlab("Variable") + ylab("Units of F") + coord_flip()
## Error: object 'forcings.long' not found


dlebauer/ghgvcR documentation built on May 15, 2019, 9:14 a.m.