Mercurial > repos > siwaa > redelac_stics_g
comparison redelacSticsInputGenerator.R @ 7:fb6f7d60508d draft
"planemo upload for repository https://forgemia.inra.fr/redelac commit d1c69d78e9ccfe06ceb7609dce59b438cd94d9d8"
author | siwaa |
---|---|
date | Thu, 20 Jul 2023 16:18:59 +0000 |
parents | bb1ac57f8545 |
children | 2a6d7d053ba7 |
comparison
equal
deleted
inserted
replaced
6:bb1ac57f8545 | 7:fb6f7d60508d |
---|---|
1 library(SticsRFiles) | 1 library(SticsRFiles) |
2 library(dplyr) | 2 library(dplyr) |
3 library(lubridate) | |
4 | |
5 | |
6 startTime <- Sys.time() | |
3 | 7 |
4 workspace <- paste0(getwd(), "/WS") | 8 workspace <- paste0(getwd(), "/WS") |
5 javastics_path <- getwd() | 9 javastics_path <- getwd() |
6 | 10 |
7 txt_path <- paste0(getwd(), "/WS/txt_files") | 11 txt_path <- paste0(getwd(), "/WS/txt_files") |
8 dir.create(txt_path,recursive = T) | 12 dir.create(txt_path, recursive = T) |
9 | 13 |
10 USMsFile <- "USMs.csv" | 14 USMsFile <- "USMs.csv" |
11 TecFile <- "Tec.csv" | 15 TecFile <- "Tec.csv" |
12 IniFile <- "Ini.csv" | 16 IniFile <- "Ini.csv" |
13 StationFile <- "Station.csv" | 17 StationFile <- "Station.csv" |
14 | 18 |
19 args = commandArgs(trailingOnly = TRUE) | |
20 | |
21 genUSMsXmlOneAfterOther <- (args[1] == "usmx_one_after_other") | |
22 | |
15 # USMs file loading | 23 # USMs file loading |
24 | |
16 usms_param <- read_params_table(file.path(workspace, USMsFile)) %>% | 25 usms_param <- read_params_table(file.path(workspace, USMsFile)) %>% |
17 select(usm_name,datedebut,datefin,finit,nomsol,fstation,fclim1,fclim2,culturean,nbplantes,codesimul,fplt_1,ftec_1,flai_1,fplt_2,ftec_2,flai_2) | 26 select( |
27 usm_name, | |
28 datedebut, | |
29 datefin, | |
30 finit, | |
31 nomsol, | |
32 fstation, | |
33 fclim1, | |
34 fclim2, | |
35 culturean, | |
36 nbplantes, | |
37 codesimul, | |
38 fplt_1, | |
39 ftec_1, | |
40 flai_1, | |
41 fplt_2, | |
42 ftec_2, | |
43 flai_2 | |
44 ) | |
18 | 45 |
19 # Tec files loading and generating xml | 46 # Tec files loading and generating xml |
47 | |
20 tec_param <- read_params_table(file.path(workspace, TecFile)) | 48 tec_param <- read_params_table(file.path(workspace, TecFile)) |
21 columnToRemove <- names(tec_param[grep("juleclair|nbinfloecl", names(tec_param))]) | 49 columnToRemove <- |
22 columnToKeep <- names(tec_param)[names(tec_param) %in% columnToRemove == FALSE] | 50 names(tec_param[grep("juleclair|nbinfloecl", names(tec_param))]) |
23 tec_param <- subset(tec_param, select=columnToKeep) | 51 columnToKeep <- |
52 names(tec_param)[names(tec_param) %in% columnToRemove == FALSE] | |
53 | |
54 tec_param <- subset(tec_param, select = columnToKeep) | |
55 | |
24 gen_tec_xml(param_df = tec_param, out_dir = workspace) | 56 gen_tec_xml(param_df = tec_param, out_dir = workspace) |
25 | 57 |
26 # Ini files loading and generating xml | 58 # Ini files loading and generating xml |
59 | |
27 ini_param <- read_params_table(file.path(workspace, IniFile)) | 60 ini_param <- read_params_table(file.path(workspace, IniFile)) |
61 | |
28 gen_ini_xml(param_df = ini_param, out_dir = workspace) | 62 gen_ini_xml(param_df = ini_param, out_dir = workspace) |
29 | 63 |
30 # Station files loading and generating xml | 64 # Station files loading and generating xml |
65 | |
31 sta_param <- read_params_table(file.path(workspace, StationFile)) | 66 sta_param <- read_params_table(file.path(workspace, StationFile)) |
67 | |
32 gen_sta_xml(param_df = sta_param, out_dir = workspace) | 68 gen_sta_xml(param_df = sta_param, out_dir = workspace) |
33 | 69 |
70 if (genUSMsXmlOneAfterOther) { | |
71 durGenX <- lubridate::as.duration(0) | |
72 durGenT <- lubridate::as.duration(0) | |
73 | |
74 # looping on USMs | |
75 for (i in 1:nrow(usms_param)) { | |
76 row <- usms_param[i, ] | |
77 | |
78 beforeGenXmlTimeI <- Sys.time() | |
79 | |
80 gen_usms_xml(file = file.path(workspace, "usms.xml"), | |
81 param_df = row) | |
82 | |
83 afterGenXmlTimeI <- Sys.time() | |
84 durGenXI <- | |
85 lubridate::as.duration(lubridate::interval(beforeGenXmlTimeI, | |
86 afterGenXmlTimeI)) | |
87 | |
88 # one after the other generating txt folder | |
89 | |
90 beforeGenTxtTimeI <- Sys.time() | |
91 | |
92 gen_usms_xml2txt( | |
93 javastics = javastics_path, | |
94 workspace = workspace, | |
95 out_dir = txt_path, | |
96 verbose = TRUE | |
97 ) | |
98 | |
99 afterGenTxtTimeI <- Sys.time() | |
100 durGenTI <- | |
101 lubridate::as.duration(lubridate::interval(beforeGenTxtTimeI, | |
102 afterGenTxtTimeI)) | |
103 | |
104 durGenX <- durGenX + durGenXI | |
105 durGenT <- durGenT + durGenTI | |
106 } | |
107 } else { | |
108 beforeGenXmlTime <- Sys.time() | |
109 | |
110 gen_usms_xml(file = file.path(workspace, "usms.xml"), | |
111 param_df = usms_param) | |
112 | |
113 afterGenXmlTime <- Sys.time() | |
114 durGenX <- | |
115 lubridate::as.duration(lubridate::interval(beforeGenXmlTime, | |
116 afterGenXmlTime)) | |
117 | |
118 beforeGenTxtTime <- Sys.time() | |
119 | |
120 gen_usms_xml2txt( | |
121 javastics = javastics_path, | |
122 workspace = workspace, | |
123 out_dir = txt_path, | |
124 verbose = TRUE | |
125 ) | |
126 | |
127 afterGenTxtTime <- Sys.time() | |
128 durGenT <- | |
129 lubridate::as.duration(lubridate::interval(beforeGenTxtTime, | |
130 afterGenTxtTime)) | |
131 | |
132 } | |
34 | 133 |
35 # looping on USMs | 134 endTime <- Sys.time() |
36 for(i in 1:nrow(usms_param)) { | 135 dur <- |
37 row <- usms_param[i,] | 136 lubridate::as.period(lubridate::as.duration(lubridate::interval(startTime, endTime))) |
137 durGenXP <- lubridate::as.period(durGenX) | |
138 durGenTP <- lubridate::as.period(durGenT) | |
38 | 139 |
39 # generating xml | 140 print("REDELAC Report") |
40 gen_usms_xml(file = file.path(workspace, "usms.xml"), param_df = row) | 141 print("==============") |
41 | 142 print(paste0("number of usms: ", nrow(usms_param))) |
42 # generating txt folder | 143 print(paste("usms.xml one after the other:", genUSMsXmlOneAfterOther)) |
43 gen_usms_xml2txt(javastics = javastics_path, | 144 sprintf( |
44 workspace = workspace, | 145 'overall duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', |
45 out_dir = txt_path, | 146 lubridate::day(dur), |
46 verbose = TRUE) | 147 lubridate::hour(dur), |
47 } | 148 lubridate::minute(dur), |
48 | 149 lubridate::second(dur) |
150 ) | |
151 sprintf( | |
152 'inside gen_usms_xml duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', | |
153 lubridate::day(durGenXP), | |
154 lubridate::hour(durGenXP), | |
155 lubridate::minute(durGenXP), | |
156 lubridate::second(durGenXP) | |
157 ) | |
158 sprintf( | |
159 'inside gen_usms_xml2txt duration: %g jour(s) %g heure(s) %g minute(s) %g seconde(s)', | |
160 lubridate::day(durGenTP), | |
161 lubridate::hour(durGenTP), | |
162 lubridate::minute(durGenTP), | |
163 lubridate::second(durGenTP) | |
164 ) |