Mercurial > repos > siwaa > redelac_stics_s
view redelacSticsSimulator.R @ 6:41f652e6616f draft
"planemo upload for repository https://forgemia.inra.fr/redelac/redelac-toolbox/-/tree/f8a7aebffe0c850bef03045efa3772aca6cd51c2/tools/REDELACSticsSimulator commit f8a7aebffe0c850bef03045efa3772aca6cd51c2-dirty"
author | siwaa |
---|---|
date | Tue, 26 Sep 2023 15:21:42 +0000 |
parents | 70ae7516e925 |
children | 2586f7dbcde1 |
line wrap: on
line source
library(SticsRFiles) library(SticsOnR) library(parallel) library(doParallel) library(readxl) sessionInfo() workspace <- paste0(getwd(), "/WS") javastics_path <- getwd() default_config_path <- paste0(javastics_path, "/config") txt_path <- paste0(getwd(), "/WS/txt_files") # List of successive USMs successive_usms_file <- ("successionPlan.csv") successive_usms_tab <- read.csv(file = file.path(workspace, successive_usms_file), sep =";") args = commandArgs(trailingOnly = TRUE) parallel <- (args[1] == "parallel") nbSlots <- as.integer(args[2]) if (parallel) { cl <- makeCluster(nbSlots) print(cl) registerDoParallel(cl) `%dordopar%` <- `%dopar%` } else { `%dordopar%` <- `%do%` } result <- foreach(i=1:nrow(successive_usms_tab), .packages = c("foreach", "SticsRFiles", "SticsOnR") ) %dordopar% { nusms <- as.numeric(successive_usms_tab[i,2]) vec <- as.character(successive_usms_tab[i,c(3:(2+nusms))]) list_successive_usms <- list(vec) sim_options <- stics_wrapper_options(javastics = javastics_path, stics_exe = paste0(javastics_path,"/bin/stics_modulo"), workspace = txt_path, verbose = TRUE, successive = list_successive_usms) list_usms <- vec return(stics_wrapper(model_options = sim_options, situation = list_usms)) } if (parallel) stopCluster(cl) for (i in 1:nrow(successive_usms_tab)) { #i=1 if (i == 1) { simPCP <- result[[i]] } else { simPCP$sim_list <- c(simPCP$sim_list, result[[i]]$sim_list) } } save(simPCP, file = "results.RData")