8
|
1 # help : Rscript % --url=https://coby.infosol.inrae.fr:7777/semantify --srcDir=~/CSCL/src/csoprapreprocessor/inst/extdata/carboseq/set001/
|
|
2
|
|
3 # Function to parse command-line arguments
|
|
4 parse_args <- function() {
|
|
5 args <- commandArgs(trailingOnly = TRUE)
|
|
6
|
|
7 # Default values for optional parameters
|
|
8 # url <- "https://coby.infosol.inrae.fr:8080/semantify/"
|
|
9 url <- "http://localhost:8282/semantify"
|
|
10 srcDir <- NULL
|
|
11 part <- "modeltoolbox_sem_sep"
|
|
12 DS <- T
|
|
13 NBCores <- 1
|
|
14 # Parse arguments
|
|
15 for (arg in args) {
|
|
16 if (grepl("^--url=", arg)) {
|
|
17 url <- sub("^--url=", "", arg)
|
|
18 }
|
|
19
|
|
20 if (grepl("^--srcDir=", arg)) {
|
|
21 srcDir <- sub("^--srcDir=", "", arg)
|
|
22 }
|
|
23
|
|
24 if (grepl("^--part=", arg)) {
|
|
25 part <- sub("^--part=", "", arg)
|
|
26 }
|
|
27
|
|
28 if (grepl("^--DS=", arg)) {
|
|
29 DS <- ifelse(sub("^--DS=", "", arg) == "TRUE", TRUE, FALSE)
|
|
30 }
|
|
31
|
|
32 if (grepl("^--NBCores=", arg)) {
|
|
33 NBCores <- as.numeric(sub("^--NBCores=", "", arg))
|
|
34 }
|
|
35
|
|
36 if (grepl("^--srcOut=", arg)) {
|
|
37 srcOut <- sub("^--srcOut=", "", arg)
|
|
38 }
|
|
39
|
|
40 }
|
|
41
|
|
42 list(url = url, srcDir = srcDir, part = part, DS = DS, NBCores = NBCores, srcOut = srcOut)
|
|
43 }
|
|
44
|
|
45 argus <- parse_args()
|
|
46 url <- argus[["url"]]
|
|
47 srcDir <- argus[["srcDir"]]
|
|
48 part <- argus[["part"]]
|
|
49 DS <- argus[["DS"]]
|
|
50 NBCores <- argus[["NBCores"]]
|
|
51
|
|
52 srcOut <- argus[["srcOut"]]
|
|
53
|
|
54 if (!endsWith(srcOut, "/")) {
|
|
55 srcOut <- paste0(srcOut, "/")
|
|
56 }
|
|
57
|
|
58 # url="https://147.100.203.110/semantify "
|
|
59 # srcDir="~/tmp/testFiles/400Sites/"
|
|
60 # part="modeltoolbox"
|
|
61 # part="csoprapreprocessor"
|
|
62 # DS=TRUE
|
|
63 # NBCores=10
|
|
64
|
|
65
|
|
66 # MTB{{{
|
|
67 if (part == "modeltoolbox") {
|
|
68 f0 <- function(){
|
|
69 modeltoolbox::loadCSVs(maxCores = NBCores, cinputCalculator = "cinest",
|
|
70 preprocessorInputs = ppi)
|
|
71 modeltoolbox::runSims(maxCores = NBCores)
|
|
72 res <- modeltoolbox::readSocForcingsResults()
|
|
73 fileName <- "resRun.RData"
|
|
74 filePath <- file.path(srcOut, fileName)
|
|
75 save(res, file = filePath)
|
|
76 }
|
|
77 }
|
|
78 #}}}
|
|
79
|
|
80 if (part == "modeltoolbox_sem_sep") {
|
|
81 DS <- F
|
|
82 print("Setting DS to F. Will semantify outside of the csoprapreprocessor functions")
|
|
83 f0 <- function(){
|
|
84 # path <- this.path::this.dir()
|
|
85 # print(path)
|
|
86 # setwd(path)
|
|
87 # setwd("../..")
|
|
88 print("before semantify")
|
|
89 # Sys.sleep(runif(n=1, min=30, max=60))
|
|
90 csopratools::semantify(
|
|
91 inputDir = srcDir,
|
|
92 outputDir = srcDir,
|
|
93 name = "carboseq",
|
|
94 use = "service",
|
|
95 URL = url,
|
|
96 # extFileNames = paste0(c("crop", "soil", "units"), ".csv")
|
|
97 extFileNames = list.files(srcDir)
|
|
98 )
|
|
99 print("between semantify and load")
|
|
100 modeltoolbox::loadCSVs(maxCores = NBCores, cinputCalculator = "cinest",
|
|
101 preprocessorInputs = ppi)
|
|
102 print("between load an sim")
|
|
103 modeltoolbox::runSims(maxCores = NBCores)
|
|
104 res <- modeltoolbox::getYearlySOCResults()
|
|
105 fileName <- "resRun.RData"
|
|
106 filePath <- file.path(srcOut, fileName)
|
|
107 save(res, file = filePath)
|
|
108 }
|
|
109 }
|
|
110
|
|
111 ppi <- list(
|
|
112 weatherRetrievalMethod = "service",
|
|
113 srcDir = srcDir,
|
|
114 doSemantify = DS,
|
|
115 weatherRetrievalURL = "https://147.100.203.110/climate",
|
|
116 semantifierServiceURL = url
|
|
117 )
|
|
118
|
|
119
|
|
120 print(url)
|
|
121 print(srcDir)
|
|
122 print(srcOut)
|
|
123 print(DS)
|
|
124 print(NBCores)
|
|
125 print(f0)
|
|
126
|
|
127 f0()
|
|
128
|
|
129
|