Mercurial > repos > siwaa > carboseq_s
diff run.r @ 1:89c69fcbf561 draft
"planemo upload for repository https://forgemia.inra.fr/carboseq/record-projet-carboseq/-/tree/ae4b6513d1114f2bf0f476b9398c6d8d39e08a0c/toos/CarboSeqSimulator commit ae4b6513d1114f2bf0f476b9398c6d8d39e08a0c-dirty"
author | siwaa |
---|---|
date | Fri, 09 Aug 2024 15:09:48 +0000 |
parents | |
children | a069fc43b0b1 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run.r Fri Aug 09 15:09:48 2024 +0000 @@ -0,0 +1,128 @@ +# help : Rscript % --url=https://coby.infosol.inrae.fr:7777/semantify --srcDir=~/CSCL/src/csoprapreprocessor/inst/extdata/carboseq/set001/ + +# Function to parse command-line arguments +parse_args <- function() { + args <- commandArgs(trailingOnly = TRUE) + + # Default values for optional parameters + url <- "https://coby.infosol.inrae.fr:8080/semantify/" + srcDir <- NULL + part <- "modeltoolbox_sem_sep" + DS <- T + NBCores <- 1 + # Parse arguments + for (arg in args) { + if (grepl("^--url=", arg)) { + url <- sub("^--url=", "", arg) + } + + if (grepl("^--srcDir=", arg)) { + srcDir <- sub("^--srcDir=", "", arg) + } + + if (grepl("^--part=", arg)) { + part <- sub("^--part=", "", arg) + } + + if (grepl("^--DS=", arg)) { + DS <- ifelse(sub("^--DS=", "", arg) == "TRUE", TRUE, FALSE) + } + + if (grepl("^--NBCores=", arg)) { + NBCores <- as.numeric(sub("^--NBCores=", "", arg)) + } + + if (grepl("^--srcOut=", arg)) { + srcOut <- sub("^--srcOut=", "", arg) + } + + if (grepl("^--semPath=", arg)) { + semPath <- sub("^--semPath=", "", arg) + } + + } + + list(url = url, srcDir = srcDir, part = part, DS = DS, NBCores = NBCores, srcOut = srcOut, semPath = semPath) +} + +argus <- parse_args() +url <- argus[["url"]] +srcDir <- argus[["srcDir"]] +part <- argus[["part"]] +DS <- argus[["DS"]] +NBCores <- argus[["NBCores"]] + +srcOut <- argus[["srcOut"]] +semPath <- argus[["semPath"]] + +if (!endsWith(srcOut, "/")) { + srcOut <- paste0(srcOut, "/") +} + +# url="https://147.100.203.110/semantify " +# srcDir="~/tmp/testFiles/400Sites/" +# part="modeltoolbox" +# part="csoprapreprocessor" +# DS=TRUE +# NBCores=10 + + +# MTB{{{ +if (part == "modeltoolbox") { +f0 <- function(){ + modeltoolbox::loadCSVs(maxCores = NBCores, cinputCalculator = "cinest", + preprocessorInputs = ppi) + modeltoolbox::runSims(maxCores = NBCores) + res <- modeltoolbox::readSocForcingsResults() + fileName <- "resRun.RData" + filePath <- file.path(srcOut, fileName) + save(res, file = filePath) +} +} +#}}} + +if (part == "modeltoolbox_sem_sep") { + DS <- F + print("Setting DS to F. Will semantify outside of the csoprapreprocessor functions") + f0 <- function(){ + csopratools::semantify( + inputDir = srcDir, + outputDir = srcDir, + name = "carboseq", + # use = "service", + URL = url, + use = "java", + semantifierRootPath = semPath, + extFileNames = paste0(c("crop", "soil", "units"), ".csv") + ) + print("between semantify and load") + modeltoolbox::loadCSVs(maxCores = NBCores, cinputCalculator = "cinest", + preprocessorInputs = ppi) + print("between load an sim") + modeltoolbox::runSims(maxCores = NBCores) + res <- modeltoolbox::getYearlySOCResults() + fileName <- "resRun.RData" + filePath <- file.path(srcOut, fileName) + save(res, file = filePath) + } +} + +ppi <- list( + weatherRetrievalMethod = "service", + srcDir = srcDir, + doSemantify = DS, + weatherRetrievalURL = "https://147.100.203.110/climate", + semantifierServiceURL = url + ) + + +print(url) +print(srcDir) +print(srcOut) +print(DS) +print(NBCores) +print(f0) + +f0() + +