Mercurial > repos > siwaa > carboseq_s
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 0:fb1b9308807f | 1:89c69fcbf561 |
|---|---|
| 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 srcDir <- NULL | |
| 10 part <- "modeltoolbox_sem_sep" | |
| 11 DS <- T | |
| 12 NBCores <- 1 | |
| 13 # Parse arguments | |
| 14 for (arg in args) { | |
| 15 if (grepl("^--url=", arg)) { | |
| 16 url <- sub("^--url=", "", arg) | |
| 17 } | |
| 18 | |
| 19 if (grepl("^--srcDir=", arg)) { | |
| 20 srcDir <- sub("^--srcDir=", "", arg) | |
| 21 } | |
| 22 | |
| 23 if (grepl("^--part=", arg)) { | |
| 24 part <- sub("^--part=", "", arg) | |
| 25 } | |
| 26 | |
| 27 if (grepl("^--DS=", arg)) { | |
| 28 DS <- ifelse(sub("^--DS=", "", arg) == "TRUE", TRUE, FALSE) | |
| 29 } | |
| 30 | |
| 31 if (grepl("^--NBCores=", arg)) { | |
| 32 NBCores <- as.numeric(sub("^--NBCores=", "", arg)) | |
| 33 } | |
| 34 | |
| 35 if (grepl("^--srcOut=", arg)) { | |
| 36 srcOut <- sub("^--srcOut=", "", arg) | |
| 37 } | |
| 38 | |
| 39 if (grepl("^--semPath=", arg)) { | |
| 40 semPath <- sub("^--semPath=", "", arg) | |
| 41 } | |
| 42 | |
| 43 } | |
| 44 | |
| 45 list(url = url, srcDir = srcDir, part = part, DS = DS, NBCores = NBCores, srcOut = srcOut, semPath = semPath) | |
| 46 } | |
| 47 | |
| 48 argus <- parse_args() | |
| 49 url <- argus[["url"]] | |
| 50 srcDir <- argus[["srcDir"]] | |
| 51 part <- argus[["part"]] | |
| 52 DS <- argus[["DS"]] | |
| 53 NBCores <- argus[["NBCores"]] | |
| 54 | |
| 55 srcOut <- argus[["srcOut"]] | |
| 56 semPath <- argus[["semPath"]] | |
| 57 | |
| 58 if (!endsWith(srcOut, "/")) { | |
| 59 srcOut <- paste0(srcOut, "/") | |
| 60 } | |
| 61 | |
| 62 # url="https://147.100.203.110/semantify " | |
| 63 # srcDir="~/tmp/testFiles/400Sites/" | |
| 64 # part="modeltoolbox" | |
| 65 # part="csoprapreprocessor" | |
| 66 # DS=TRUE | |
| 67 # NBCores=10 | |
| 68 | |
| 69 | |
| 70 # MTB{{{ | |
| 71 if (part == "modeltoolbox") { | |
| 72 f0 <- function(){ | |
| 73 modeltoolbox::loadCSVs(maxCores = NBCores, cinputCalculator = "cinest", | |
| 74 preprocessorInputs = ppi) | |
| 75 modeltoolbox::runSims(maxCores = NBCores) | |
| 76 res <- modeltoolbox::readSocForcingsResults() | |
| 77 fileName <- "resRun.RData" | |
| 78 filePath <- file.path(srcOut, fileName) | |
| 79 save(res, file = filePath) | |
| 80 } | |
| 81 } | |
| 82 #}}} | |
| 83 | |
| 84 if (part == "modeltoolbox_sem_sep") { | |
| 85 DS <- F | |
| 86 print("Setting DS to F. Will semantify outside of the csoprapreprocessor functions") | |
| 87 f0 <- function(){ | |
| 88 csopratools::semantify( | |
| 89 inputDir = srcDir, | |
| 90 outputDir = srcDir, | |
| 91 name = "carboseq", | |
| 92 # use = "service", | |
| 93 URL = url, | |
| 94 use = "java", | |
| 95 semantifierRootPath = semPath, | |
| 96 extFileNames = paste0(c("crop", "soil", "units"), ".csv") | |
| 97 ) | |
| 98 print("between semantify and load") | |
| 99 modeltoolbox::loadCSVs(maxCores = NBCores, cinputCalculator = "cinest", | |
| 100 preprocessorInputs = ppi) | |
| 101 print("between load an sim") | |
| 102 modeltoolbox::runSims(maxCores = NBCores) | |
| 103 res <- modeltoolbox::getYearlySOCResults() | |
| 104 fileName <- "resRun.RData" | |
| 105 filePath <- file.path(srcOut, fileName) | |
| 106 save(res, file = filePath) | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 ppi <- list( | |
| 111 weatherRetrievalMethod = "service", | |
| 112 srcDir = srcDir, | |
| 113 doSemantify = DS, | |
| 114 weatherRetrievalURL = "https://147.100.203.110/climate", | |
| 115 semantifierServiceURL = url | |
| 116 ) | |
| 117 | |
| 118 | |
| 119 print(url) | |
| 120 print(srcDir) | |
| 121 print(srcOut) | |
| 122 print(DS) | |
| 123 print(NBCores) | |
| 124 print(f0) | |
| 125 | |
| 126 f0() | |
| 127 | |
| 128 |
