Mercurial > repos > siwaa > redelac_stics_g
comparison redelacSticsInputGenerator.R @ 9:2a6d7d053ba7 draft
"planemo upload for repository https://forgemia.inra.fr/redelac commit adcac73e150f1f821b4b7f7673a490dc0fadc936"
author | siwaa |
---|---|
date | Mon, 25 Sep 2023 16:25:51 +0000 |
parents | fb6f7d60508d |
children | f707c2fb725b |
comparison
equal
deleted
inserted
replaced
8:0625e6a639ea | 9:2a6d7d053ba7 |
---|---|
1 library(SticsRFiles) | 1 library(SticsRFiles) |
2 library(dplyr) | 2 library(dplyr) |
3 library(lubridate) | 3 library(lubridate) |
4 library(parallel) | |
5 library(doParallel) | |
4 | 6 |
7 sessionInfo() | |
5 | 8 |
6 startTime <- Sys.time() | 9 startTime <- Sys.time() |
7 | 10 |
8 workspace <- paste0(getwd(), "/WS") | 11 workspace <- paste0(getwd(), "/WS") |
9 javastics_path <- getwd() | 12 javastics_path <- getwd() |
17 StationFile <- "Station.csv" | 20 StationFile <- "Station.csv" |
18 | 21 |
19 args = commandArgs(trailingOnly = TRUE) | 22 args = commandArgs(trailingOnly = TRUE) |
20 | 23 |
21 genUSMsXmlOneAfterOther <- (args[1] == "usmx_one_after_other") | 24 genUSMsXmlOneAfterOther <- (args[1] == "usmx_one_after_other") |
25 parallel <- (args[2] == "parallel") | |
26 nbSlots <- as.integer(args[3]) | |
22 | 27 |
23 # USMs file loading | 28 # USMs file loading |
24 | 29 |
25 usms_param <- read_params_table(file.path(workspace, USMsFile)) %>% | 30 usms_param <- read_params_table(file.path(workspace, USMsFile)) %>% |
26 select( | 31 select( |
66 sta_param <- read_params_table(file.path(workspace, StationFile)) | 71 sta_param <- read_params_table(file.path(workspace, StationFile)) |
67 | 72 |
68 gen_sta_xml(param_df = sta_param, out_dir = workspace) | 73 gen_sta_xml(param_df = sta_param, out_dir = workspace) |
69 | 74 |
70 if (genUSMsXmlOneAfterOther) { | 75 if (genUSMsXmlOneAfterOther) { |
76 | |
71 durGenX <- lubridate::as.duration(0) | 77 durGenX <- lubridate::as.duration(0) |
72 durGenT <- lubridate::as.duration(0) | 78 durGenT <- lubridate::as.duration(0) |
73 | 79 |
80 if (parallel) { | |
81 cl <- makeCluster(nbSlots) | |
82 print(cl) | |
83 registerDoParallel(cl) | |
84 `%dordopar%` <- `%dopar%` | |
85 } else { | |
86 `%dordopar%` <- `%do%` | |
87 } | |
88 | |
74 # looping on USMs | 89 # looping on USMs |
75 for (i in 1:nrow(usms_param)) { | 90 loopRes <- foreach::foreach(i = 1:nrow(usms_param), |
76 row <- usms_param[i, ] | 91 .packages = c("SticsRFiles", "lubridate")) %dordopar% { |
77 | 92 |
78 beforeGenXmlTimeI <- Sys.time() | 93 beforeGenXmlTimeI <- Sys.time() |
79 | 94 |
80 gen_usms_xml(file = file.path(workspace, "usms.xml"), | 95 usmxFileName = paste0("usms", as.character(i) , ".xml") |
81 param_df = row) | 96 |
82 | 97 usmxFilePath = file.path(workspace, usmxFileName) |
98 | |
99 gen_usms_xml(file = usmxFilePath, | |
100 param_df = usms_param[i, ]) | |
101 | |
83 afterGenXmlTimeI <- Sys.time() | 102 afterGenXmlTimeI <- Sys.time() |
84 durGenXI <- | 103 durGenXI <- |
85 lubridate::as.duration(lubridate::interval(beforeGenXmlTimeI, | 104 lubridate::as.duration(lubridate::interval(beforeGenXmlTimeI, |
86 afterGenXmlTimeI)) | 105 afterGenXmlTimeI)) |
87 | 106 |
88 # one after the other generating txt folder | 107 # one after the other generating txt folder |
89 | 108 |
90 beforeGenTxtTimeI <- Sys.time() | 109 beforeGenTxtTimeI <- Sys.time() |
91 | 110 |
92 gen_usms_xml2txt( | 111 gen_usms_xml2txt( |
112 usms_file = usmxFileName, | |
93 javastics = javastics_path, | 113 javastics = javastics_path, |
94 workspace = workspace, | 114 workspace = workspace, |
95 out_dir = txt_path, | 115 out_dir = txt_path, |
96 verbose = TRUE | 116 verbose = TRUE |
97 ) | 117 ) |
98 | 118 |
99 afterGenTxtTimeI <- Sys.time() | 119 afterGenTxtTimeI <- Sys.time() |
100 durGenTI <- | 120 durGenTI <- |
101 lubridate::as.duration(lubridate::interval(beforeGenTxtTimeI, | 121 lubridate::as.duration(lubridate::interval(beforeGenTxtTimeI, |
102 afterGenTxtTimeI)) | 122 afterGenTxtTimeI)) |
103 | 123 |
104 durGenX <- durGenX + durGenXI | 124 return(c(durGenXI, durGenTI)) |
105 durGenT <- durGenT + durGenTI | |
106 } | 125 } |
126 | |
127 if (parallel) stopCluster(cl) | |
128 | |
129 durDS <- as.data.frame(do.call(rbind, loopRes)) | |
130 durGenX <- sum(durDS[1]) | |
131 durGenT <- sum(durDS[2]) | |
132 | |
107 } else { | 133 } else { |
134 | |
108 beforeGenXmlTime <- Sys.time() | 135 beforeGenXmlTime <- Sys.time() |
109 | 136 |
110 gen_usms_xml(file = file.path(workspace, "usms.xml"), | 137 gen_usms_xml(file = file.path(workspace, "usms.xml"), |
111 param_df = usms_param) | 138 param_df = usms_param) |
112 | 139 |
113 afterGenXmlTime <- Sys.time() | 140 afterGenXmlTime <- Sys.time() |
114 durGenX <- | 141 durGenX <- |
115 lubridate::as.duration(lubridate::interval(beforeGenXmlTime, | 142 lubridate::as.duration(lubridate::interval(beforeGenXmlTime, |
116 afterGenXmlTime)) | 143 afterGenXmlTime)) |
117 | 144 |
118 beforeGenTxtTime <- Sys.time() | 145 beforeGenTxtTime <- Sys.time() |
119 | 146 |
120 gen_usms_xml2txt( | 147 gen_usms_xml2txt( |
121 javastics = javastics_path, | 148 javastics = javastics_path, |
122 workspace = workspace, | 149 workspace = workspace, |
123 out_dir = txt_path, | 150 out_dir = txt_path, |
124 verbose = TRUE | 151 verbose = TRUE |
125 ) | 152 ) |
126 | 153 |
127 afterGenTxtTime <- Sys.time() | 154 afterGenTxtTime <- Sys.time() |
128 durGenT <- | 155 durGenT <- |
129 lubridate::as.duration(lubridate::interval(beforeGenTxtTime, | 156 lubridate::as.duration(lubridate::interval(beforeGenTxtTime, |
130 afterGenTxtTime)) | 157 afterGenTxtTime)) |
131 | 158 |
132 } | 159 } |
133 | 160 |
134 endTime <- Sys.time() | 161 endTime <- Sys.time() |
162 | |
135 dur <- | 163 dur <- |
136 lubridate::as.period(lubridate::as.duration(lubridate::interval(startTime, endTime))) | 164 lubridate::as.period(lubridate::as.duration(lubridate::interval(startTime, endTime))) |
137 durGenXP <- lubridate::as.period(durGenX) | 165 durGenXP <- lubridate::as.period(durGenX) |
138 durGenTP <- lubridate::as.period(durGenT) | 166 durGenTP <- lubridate::as.period(durGenT) |
139 | 167 |
140 print("REDELAC Report") | 168 print("REDELACSticsInputGenerator Report") |
141 print("==============") | 169 print("=================================") |
142 print(paste0("number of usms: ", nrow(usms_param))) | 170 print(paste0("number of usms: ", nrow(usms_param))) |
143 print(paste("usms.xml one after the other:", genUSMsXmlOneAfterOther)) | 171 print(paste("usms.xml one after the other:", genUSMsXmlOneAfterOther)) |
172 | |
144 sprintf( | 173 sprintf( |
145 'overall duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', | 174 'overall duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', |
146 lubridate::day(dur), | 175 lubridate::day(dur), |
147 lubridate::hour(dur), | 176 lubridate::hour(dur), |
148 lubridate::minute(dur), | 177 lubridate::minute(dur), |
149 lubridate::second(dur) | 178 lubridate::second(dur)) |
150 ) | 179 |
151 sprintf( | 180 sprintf( |
152 'inside gen_usms_xml duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', | 181 'inside gen_usms_xml duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', |
153 lubridate::day(durGenXP), | 182 lubridate::day(durGenXP), |
154 lubridate::hour(durGenXP), | 183 lubridate::hour(durGenXP), |
155 lubridate::minute(durGenXP), | 184 lubridate::minute(durGenXP), |
156 lubridate::second(durGenXP) | 185 lubridate::second(durGenXP)) |
157 ) | 186 |
158 sprintf( | 187 sprintf( |
159 'inside gen_usms_xml2txt duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', | 188 'inside gen_usms_xml2txt duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', |
160 lubridate::day(durGenTP), | 189 lubridate::day(durGenTP), |
161 lubridate::hour(durGenTP), | 190 lubridate::hour(durGenTP), |
162 lubridate::minute(durGenTP), | 191 lubridate::minute(durGenTP), |
163 lubridate::second(durGenTP) | 192 lubridate::second(durGenTP)) |
164 ) |