comparison REDELACparallelSticsRsequence.R @ 0:21e91d3b7068 draft

"planemo upload for repository https://forgemia.inra.fr/redelac"
author siwaa
date Thu, 01 Jun 2023 09:13:11 +0000
parents
children 50dd120308af
comparison
equal deleted inserted replaced
-1:000000000000 0:21e91d3b7068
1 library(SticsRFiles)
2 library(SticsOnR)
3 library(parallel)
4 library(doParallel)
5 library(readxl)
6
7 workspace <- paste0(getwd(), "/WS")
8 javastics_path <- getwd()
9 default_config_path <- paste0(javastics_path, "/config")
10
11 # copy of the var.mod and rap.mod into the config folder
12 # generalizing maybe should be inside a config folder
13
14 #file.copy(from = file.path(workspace, "var.mod"),
15 # to = file.path(default_config_path, "var.mod"),
16 # overwrite = TRUE)
17 #file.copy(from = file.path(workspace, "rap.mod"),
18 # to = file.path(default_config_path, "rap.mod"),
19 # overwrite = TRUE)
20
21 txt_path <- paste0(getwd(), "/WS/txt_files")
22 #dir.create(txt_path,recursive = T)
23
24 #gen_usms_xml2txt(javastics = javastics_path,
25 # workspace = workspace,
26 # out_dir = txt_path,
27 # check = FALSE)
28
29 print("==================================")
30
31 print(paste0("Cores=", detectCores()))
32 print(paste0("javastics=", javastics_path))
33 print(paste0("ws=", workspace))
34 print(paste0("out_dir=", txt_path))
35
36 print("==================================")
37
38
39 # List of successive USMs
40 successive_usms_file <- ("successionPlan.csv")
41 successive_usms_tab <- read.csv(file = file.path(workspace, successive_usms_file))
42
43 no_cores <- detectCores() - 1
44 cl <- makeCluster(no_cores)
45 registerDoParallel(cl)
46
47 result <- foreach(i=1:nrow(successive_usms_tab),
48 .packages = c("SticsRFiles", "SticsOnR") ) %dopar% {
49
50 nusms <- as.numeric(successive_usms_tab[i,2])
51
52 vec <- as.character(successive_usms_tab[i,c(3:(2+nusms))])
53
54 list_successive_usms <- list(vec)
55
56 sim_options <- stics_wrapper_options(javastics = javastics_path,
57 stics_exe = paste0(javastics_path,"/bin/stics_modulo"),
58 workspace = txt_path,
59 verbose = TRUE,
60 successive = list_successive_usms)
61 list_usms <- vec
62
63 stics_wrapper(model_options = sim_options, situation = list_usms)
64 }
65
66 stopCluster(cl)
67
68 for (i in 1:nrow(successive_usms_tab)) { #i=1
69 if (i == 1) {
70 simPCP <- result[[i]]
71 } else {
72 simPCP$sim_list <- c(simPCP$sim_list, result[[i]]$sim_list)
73 }
74
75 }
76
77 save(simPCP, file = "results.RData")