scripts/10_predict_R0_from_fluctuating_T.R

# load results and save


devtools::load_all()


options(didehpc.cluster = "fi--didemrchnb")

CLUSTER <- TRUE

my_resources <- c(
  file.path("R", "temp_functions_all.R"),
  file.path("R", "R0_function.R"),
  file.path("R", "calculate_annual_traits_R0_FT.R"),
  file.path("R", "utilities.R"))

if (CLUSTER) {

  # running out of place

  workdir <- "Q:/DENVclimate"
  didehpc::didehpc_config_global(workdir = workdir)
  root <- file.path(workdir, "context")

} else {

  root <- "context"

}

context::context_log_start()
ctx <- context::context_save(path = root,
                             sources = my_resources)


# define parameters -----------------------------------------------------------


dir_save <- file.path("output", "trait_R0_relationships")

covariates <- c("DayTemp_const_term", "NightTemp_const_term")

var <- "pred_R0_1"


# define variables ------------------------------------------------------------


covar <- covariates[2]

out_file_name <- paste0(var, "_", covar, "_fluctuating_T")


# are you using the cluster? --------------------------------------------------


if (CLUSTER) {

  config <- didehpc::didehpc_config(template = "24Core")
  obj <- didehpc::queue_didehpc(ctx, config = config)

} else {

  context::context_load(ctx)
  context::parallel_cluster_start(8, ctx)

}


# get the results -------------------------------------------------------------


all_bundles <- obj$task_bundle_info()

id <- all_bundles[nrow(all_bundles), "name"]

task_obj <- obj$task_bundle_get(id)

all_results <- task_obj$results()

all_results_mat <- do.call("rbind", all_results)

R0.M <- rowMeans(all_results_mat)


# save ------------------------------------------------------------------------


write_out_rds(R0.M, dir_save, out_file_name)
lorecatta/DENVclimate documentation built on Dec. 11, 2019, 7:05 a.m.