Skip to content

Commit

Permalink
Merge pull request #2857 from moki1202/patch-2
Browse files Browse the repository at this point in the history
Last few tweaks to PEcAn.utils
  • Loading branch information
mdietze committed Sep 24, 2021
2 parents a843c49 + c892cd7 commit b8eba46
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 20 deletions.
2 changes: 0 additions & 2 deletions base/utils/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export(n_leap_day)
export(paste.stats)
export(r2bugs.distributions)
export(read.output)
export(read.sa.output)
export(read_web_config)
export(retry.func)
export(rsync)
Expand All @@ -57,7 +56,6 @@ export(transformstats)
export(tryl)
export(units_are_equivalent)
export(vecpaste)
export(write.sa.configs)
export(zero.truncate)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
2 changes: 1 addition & 1 deletion base/workflow/R/run.write.configs.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ run.write.configs <- function(settings, write = TRUE, ens.sample.method = "unifo

### Write out SA config files
PEcAn.logger::logger.info("\n ----- Writing model run config files ----")
sa.runs <- PEcAn.utils::write.sa.configs(defaults = settings$pfts,
sa.runs <- PEcAn.uncertainty::write.sa.configs(defaults = settings$pfts,
quantile.samples = sa.samples,
settings = settings,
model = model,
Expand Down
2 changes: 2 additions & 0 deletions modules/uncertainty/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export(prep.data.assim)
export(read.ameriflux.L2)
export(read.ensemble.output)
export(read.ensemble.ts)
export(read.sa.output)
export(run.ensemble.analysis)
export(run.sensitivity.analysis)
export(runModule.get.results)
Expand All @@ -30,4 +31,5 @@ export(sensitivity.analysis)
export(sensitivity.filename)
export(spline.truncate)
export(write.ensemble.configs)
export(write.sa.configs)
importFrom(dplyr,"%>%")
2 changes: 1 addition & 1 deletion modules/uncertainty/R/get.results.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ get.results <- function(settings, sa.ensemble.id = NULL, ens.ensemble.id = NULL,
# when there is variable-per pft in the outputs, check for the tag for deciding SA per pft
per.pft <- ifelse(!is.null(settings$sensitivity.analysis$perpft),
as.logical(settings$sensitivity.analysis$perpft), FALSE)
sensitivity.output[[pft.name]] <- PEcAn.utils::read.sa.output(
sensitivity.output[[pft.name]] <- read.sa.output(
traits = traits,
quantiles = quantiles,
pecandir = outdir,
Expand Down
31 changes: 17 additions & 14 deletions base/utils/R/sensitivity.R → modules/uncertainty/R/sensitivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
##' If NULL, will look in `pecandir` for a file named `samples.Rdata`
##' and read from that
##' @export
##' @importFrom magrittr %>%
##' @author Ryan Kelly, David LeBauer, Rob Kooper, Mike Dietze, Istem Fer
#--------------------------------------------------------------------------------------------------#
##' @author Ryan Kelly, David LeBauer, Rob Kooper, Mike Dietze
Expand All @@ -37,8 +36,9 @@ read.sa.output <- function(traits, quantiles, pecandir, outdir, pft.name = "",
if (is.null(sa.run.ids)) {
samples.file <- file.path(pecandir, "samples.Rdata")
if (file.exists(samples.file)) {
load(samples.file)
sa.run.ids <- runs.samples$sa
samples <- new.env()
load(samples.file, envir = samples)
sa.run.ids <- samples$runs.samples$sa
} else {
PEcAn.logger::logger.error(samples.file, "not found, this file is required by the read.sa.output function")
}
Expand All @@ -59,10 +59,12 @@ read.sa.output <- function(traits, quantiles, pecandir, outdir, pft.name = "",
# if SA is requested on a variable available per pft, pass pft.name to read.output
# so that it only returns values for that pft
pass_pft <- switch(per.pft + 1, NULL, pft.name)
out.tmp <- read.output(runid = run.id, outdir = file.path(outdir, run.id),
start.year = start.year, end.year = end.year,
variables = variables[var],
pft.name = pass_pft)
out.tmp <- PEcAn.utils::read.output(
runid = run.id,
outdir = file.path(outdir, run.id),
start.year = start.year, end.year = end.year,
variables = variables[var],
pft.name = pass_pft)
assign(variables[var], out.tmp[[variables[var]]])
}

Expand Down Expand Up @@ -124,11 +126,11 @@ write.sa.configs <- function(defaults, quantile.samples, settings, model,
runs <- data.frame()

# Reading the site.pft specific tags from xml
site.pfts.vec <- settings$run$site$site.pft %>% unlist %>% as.character
site.pfts.vec <- as.character(unlist(settings$run$site$site.pft))

if(!is.null(site.pfts.vec)){
# find the name of pfts defined in the body of pecan.xml
defined.pfts <- settings$pfts %>% purrr::map('name') %>% unlist %>% as.character
defined.pfts <- as.character(unlist(purrr::map(settings$pfts, 'name')))
# subset ensemble samples based on the pfts that are specified in the site and they are also sampled from.
if (length(which(site.pfts.vec %in% defined.pfts)) > 0 )
quantile.samples <- quantile.samples [site.pfts.vec[ which(site.pfts.vec %in% defined.pfts) ]]
Expand Down Expand Up @@ -183,7 +185,7 @@ write.sa.configs <- function(defaults, quantile.samples, settings, model,
}
}
} else {
run.id <- get.run.id("SA", "median")
run.id <- PEcAn.utils::get.run.id("SA", "median")
ensemble.id <- NA
}
medianrun <- run.id
Expand Down Expand Up @@ -285,10 +287,11 @@ write.sa.configs <- function(defaults, quantile.samples, settings, model,
}
}
} else {
run.id <- get.run.id("SA",
round(quantile, 3),
trait = trait,
pft.name = names(trait.samples)[i])
run.id <- PEcAn.utils::get.run.id(
run.type = "SA",
index = round(quantile, 3),
trait = trait,
pft.name = names(trait.samples)[i])
}
runs[[pftname]][quantile.str, trait] <- run.id

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.

0 comments on commit b8eba46

Please sign in to comment.