comparison redelacSticsSimulator.R @ 2:ea8e91473dc8 draft

"planemo upload for repository https://forgemia.inra.fr/redelac/redelac-toolbox/-/tree/4c3e6dc71284e3eecf1cfa8402aaf12dc49c1ee4/tools/REDELACSticsSimulator commit 4c3e6dc71284e3eecf1cfa8402aaf12dc49c1ee4-dirty"
author siwaa
date Fri, 23 Jun 2023 10:17:27 +0000
parents
children f262814e48a3
comparison
equal deleted inserted replaced
1:be10e3fb6e64 2:ea8e91473dc8
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), sep =";")
42
43 no_cores <- detectCores() - 1
44 #no_cores <- 10
45 cl <- makeCluster(no_cores)
46 registerDoParallel(cl)
47
48 result <- foreach(i=1:nrow(successive_usms_tab),
49 .packages = c("SticsRFiles", "SticsOnR") ) %dopar% {
50
51
52 print(paste("coucou ", i))
53 nusms <- as.numeric(successive_usms_tab[i,2])
54 print(paste0("coco ", nusms))
55
56 vec <- as.character(successive_usms_tab[i,c(3:(2+nusms))])
57
58 list_successive_usms <- list(vec)
59
60 sim_options <- stics_wrapper_options(javastics = javastics_path,
61 stics_exe = paste0(javastics_path,"/bin/stics_modulo"),
62 workspace = txt_path,
63 verbose = TRUE,
64 successive = list_successive_usms)
65 list_usms <- vec
66
67 stics_wrapper(model_options = sim_options, situation = list_usms)
68 }
69
70 stopCluster(cl)
71
72 for (i in 1:nrow(successive_usms_tab)) { #i=1
73 if (i == 1) {
74 simPCP <- result[[i]]
75 } else {
76 simPCP$sim_list <- c(simPCP$sim_list, result[[i]]$sim_list)
77 }
78
79 }
80
81 save(simPCP, file = "results.RData")