Mercurial > repos > siwaa > redelac_stics_s
view redelacSticsSimulator.R @ 3:f262814e48a3 draft
"planemo upload for repository https://forgemia.inra.fr/redelac/redelac-toolbox/-/tree/acafb1f877e923efa13655229681753dfa1928c0/tools/REDELACSticsSimulator commit acafb1f877e923efa13655229681753dfa1928c0-dirty"
author | siwaa |
---|---|
date | Mon, 26 Jun 2023 17:25:19 +0000 |
parents | ea8e91473dc8 |
children | 70ae7516e925 |
line wrap: on
line source
library(SticsRFiles) library(SticsOnR) library(parallel) library(doParallel) library(readxl) workspace <- paste0(getwd(), "/WS") javastics_path <- getwd() default_config_path <- paste0(javastics_path, "/config") # copy of the var.mod and rap.mod into the config folder # generalizing maybe should be inside a config folder #file.copy(from = file.path(workspace, "var.mod"), # to = file.path(default_config_path, "var.mod"), # overwrite = TRUE) #file.copy(from = file.path(workspace, "rap.mod"), # to = file.path(default_config_path, "rap.mod"), # overwrite = TRUE) txt_path <- paste0(getwd(), "/WS/txt_files") #dir.create(txt_path,recursive = T) #gen_usms_xml2txt(javastics = javastics_path, # workspace = workspace, # out_dir = txt_path, # check = FALSE) print("==================================") print(paste0("Cores=", detectCores())) print(paste0("javastics=", javastics_path)) print(paste0("ws=", workspace)) print(paste0("out_dir=", txt_path)) print("==================================") # List of successive USMs successive_usms_file <- ("successionPlan.csv") successive_usms_tab <- read.csv(file = file.path(workspace, successive_usms_file), sep =";") #no_cores <- detectCores() - 1 #no_cores <- 10 #cl <- makeCluster(no_cores) #registerDoParallel(cl) result <- list() #result <- foreach(i=1:nrow(successive_usms_tab), # .packages = c("SticsRFiles", "SticsOnR") ) %dopar% { for(i in 1:nrow(successive_usms_tab)) { print(paste("coucou ", i)) nusms <- as.numeric(successive_usms_tab[i,2]) print(paste0("coco ", nusms)) 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 result = append(result, stics_wrapper(model_options = sim_options, situation = list_usms)) } #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")