comparison redelacComputeAclim.R @ 1:8ce4e694e8f6 draft default tip

"planemo upload for repository https://forgemia.inra.fr/redelac/redelac-toolbox/-/tree/da77b35ba19889b7800e44db967c33ca6e55c39a/tools/REDELACcomputeAclim commit da77b35ba19889b7800e44db967c33ca6e55c39a-dirty"
author siwaa
date Thu, 02 Jul 2026 07:35:08 +0000
parents 80842c5ecb58
children
comparison
equal deleted inserted replaced
0:80842c5ecb58 1:8ce4e694e8f6
1
1 library(data.table) #version 1.14.2 2 library(data.table) #version 1.14.2
2 library(dplyr) #version 1.0.10 3 library(dplyr) #version 1.0.10
3 library(ggplot2) 4 library(ggplot2)
4 library(rlang) 5 library(rlang)
5 library(stringr) 6 library(stringr)
12 rdsOut = args[3] 13 rdsOut = args[3]
13 csvOut = args[4] 14 csvOut = args[4]
14 png1Out = args[5] 15 png1Out = args[5]
15 png2Out = args[6] 16 png2Out = args[6]
16 17
18 # sanityzing
19
20 trimedHorizon <-str_trim(horizons)
21 purgedHorizon <-str_sub(trimedHorizon, 1, nchar(trimedHorizon)-1)
22
23 listHory <- lapply(unlist(strsplit(purgedHorizon, ",")), function(x) {tmpdata <- str_split(str_trim(x), " ")[[1]]; paste0("(annee<", tmpdata[3], ")&(annee>",tmpdata[2], ")~\"", tmpdata[1], "\"" )})
24
25 rules <- lapply(unlist(strsplit(purgedHorizon, ",")), function(x) {tmpdata <- str_split(str_trim(x), " ")[[1]]; list (condition = paste0("(annee<", tmpdata[3], ")&(annee>",tmpdata[2], ")"), label = tmpdata[1])})
26
27 rules
28
29 cases <- lapply(rules, \(r) {
30 expr(!!parse_expr(r$condition) ~ !!r$label)
31 })
32
33 str(cases)
34
35 cases
36
17 liste_mailles_SAFRAN <- list.dirs(climatPath,full.names = F,recursive = F) 37 liste_mailles_SAFRAN <- list.dirs(climatPath,full.names = F,recursive = F)
38
39 print(liste_mailles_SAFRAN)
18 40
19 #agregation des fichiers climatiques dans un unique fichier 41 #agregation des fichiers climatiques dans un unique fichier
20 fichier_climat_tot<- NULL 42 fichier_climat_tot<- NULL
21 43
22 44
66 trimedHorizon <-str_trim(horizons) 88 trimedHorizon <-str_trim(horizons)
67 purgedHorizon <-str_sub(trimedHorizon, 1, nchar(trimedHorizon)-1) 89 purgedHorizon <-str_sub(trimedHorizon, 1, nchar(trimedHorizon)-1)
68 90
69 listHory <- lapply(unlist(strsplit(purgedHorizon, ",")), function(x) {tmpdata <- str_split(str_trim(x), " ")[[1]]; paste0("(annee<", tmpdata[3], ")&(annee>",tmpdata[2], ")~\"", tmpdata[1], "\"" )}) 91 listHory <- lapply(unlist(strsplit(purgedHorizon, ",")), function(x) {tmpdata <- str_split(str_trim(x), " ")[[1]]; paste0("(annee<", tmpdata[3], ")&(annee>",tmpdata[2], ")~\"", tmpdata[1], "\"" )})
70 92
93
94
95
96
71 listHory 97 listHory
72 98
73 paste(listHory, collapse = ",", sep = "") 99 paste(listHory, collapse = ",", sep = "")
74 100
75 horizonsFilter <- parse_expr(paste(listHory, collapse = ",", sep = "")) 101 #horizonsFilter <- parse_expr(paste(listHory, collapse = ",", sep = ""))
76 102
77 listHory 103 listHory
78 104
105 #fichier_climat_tot <- fichier_climat_tot %>%
106 # mutate(horizon=case_when(!!horizonsFilter))
107
79 fichier_climat_tot <- fichier_climat_tot %>% 108 fichier_climat_tot <- fichier_climat_tot %>%
80 mutate(horizon=case_when(!!horizonsFilter)) 109 mutate(horizon=case_when(!!!cases))
81 110
82 #fichier_climat_tot <- fichier_climat_tot %>% 111 #fichier_climat_tot <- fichier_climat_tot %>%
83 # mutate(horizon=case_when((annee>1990)&(annee<2025)~"ref")) 112 # mutate(horizon=case_when((annee>1990)&(annee<2025)~"ref"))
84 113
85 #ecriture du fichier 114 #ecriture du fichier