Mercurial > repos > siwaa > redelac_stics_s
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 5:fa8e742b197b | 6:41f652e6616f |
|---|---|
| 1 library(SticsRFiles) | 1 library(SticsRFiles) |
| 2 library(SticsOnR) | 2 library(SticsOnR) |
| 3 library(parallel) | 3 library(parallel) |
| 4 library(doParallel) | 4 library(doParallel) |
| 5 library(readxl) | 5 library(readxl) |
| 6 | |
| 7 sessionInfo() | |
| 6 | 8 |
| 7 workspace <- paste0(getwd(), "/WS") | 9 workspace <- paste0(getwd(), "/WS") |
| 8 javastics_path <- getwd() | 10 javastics_path <- getwd() |
| 9 default_config_path <- paste0(javastics_path, "/config") | 11 default_config_path <- paste0(javastics_path, "/config") |
| 10 | 12 |
| 11 txt_path <- paste0(getwd(), "/WS/txt_files") | 13 txt_path <- paste0(getwd(), "/WS/txt_files") |
| 12 | 14 |
| 13 print("==================================") | |
| 14 | |
| 15 print(paste0("Cores=", detectCores())) | |
| 16 print(paste0("javastics=", javastics_path)) | |
| 17 print(paste0("ws=", workspace)) | |
| 18 print(paste0("out_dir=", txt_path)) | |
| 19 | |
| 20 print("==================================") | |
| 21 | |
| 22 # List of successive USMs | 15 # List of successive USMs |
| 23 successive_usms_file <- ("successionPlan.csv") | 16 successive_usms_file <- ("successionPlan.csv") |
| 24 successive_usms_tab <- read.csv(file = file.path(workspace, successive_usms_file), sep =";") | 17 successive_usms_tab <- read.csv(file = file.path(workspace, successive_usms_file), sep =";") |
| 25 | 18 |
| 26 #no_cores <- detectCores() - 1 | 19 args = commandArgs(trailingOnly = TRUE) |
| 27 #no_cores <- 10 | |
| 28 #cl <- makeCluster(no_cores) | |
| 29 #registerDoParallel(cl) | |
| 30 | 20 |
| 31 result <- list() | 21 parallel <- (args[1] == "parallel") |
| 22 nbSlots <- as.integer(args[2]) | |
| 32 | 23 |
| 33 #result <- foreach(i=1:nrow(successive_usms_tab), | 24 if (parallel) { |
| 34 # .packages = c("SticsRFiles", "SticsOnR") ) %dopar% { | 25 cl <- makeCluster(nbSlots) |
| 35 for(i in 1:nrow(successive_usms_tab)) { | 26 print(cl) |
| 27 registerDoParallel(cl) | |
| 28 `%dordopar%` <- `%dopar%` | |
| 29 } else { | |
| 30 `%dordopar%` <- `%do%` | |
| 31 } | |
| 32 | |
| 33 result <- foreach(i=1:nrow(successive_usms_tab), | |
| 34 .packages = c("foreach", "SticsRFiles", "SticsOnR") ) %dordopar% { | |
| 36 | 35 |
| 37 nusms <- as.numeric(successive_usms_tab[i,2]) | 36 nusms <- as.numeric(successive_usms_tab[i,2]) |
| 38 | 37 |
| 39 vec <- as.character(successive_usms_tab[i,c(3:(2+nusms))]) | 38 vec <- as.character(successive_usms_tab[i,c(3:(2+nusms))]) |
| 40 | 39 |
| 45 workspace = txt_path, | 44 workspace = txt_path, |
| 46 verbose = TRUE, | 45 verbose = TRUE, |
| 47 successive = list_successive_usms) | 46 successive = list_successive_usms) |
| 48 list_usms <- vec | 47 list_usms <- vec |
| 49 | 48 |
| 50 singleResult = stics_wrapper(model_options = sim_options, situation = list_usms) | 49 return(stics_wrapper(model_options = sim_options, situation = list_usms)) |
| 51 | 50 |
| 52 result = append(result, list(singleResult)) | 51 } |
| 53 } | |
| 54 | 52 |
| 55 #stopCluster(cl) | 53 if (parallel) stopCluster(cl) |
| 56 | 54 |
| 57 for (i in 1:nrow(successive_usms_tab)) { #i=1 | 55 for (i in 1:nrow(successive_usms_tab)) { #i=1 |
| 58 if (i == 1) { | 56 if (i == 1) { |
| 59 simPCP <- result[[i]] | 57 simPCP <- result[[i]] |
| 60 } else { | 58 } else { |
