Mercurial > repos > siwaa > redelac_stics_a
changeset 0:80842c5ecb58 draft default tip
"planemo upload for repository https://forgemia.inra.fr/redelac/redelac-toolbox/-/tree/68f4e9db390070700af804f77468145abfc26bc0/tools/REDELACcomputeAclim commit 68f4e9db390070700af804f77468145abfc26bc0-dirty"
| author | siwaa |
|---|---|
| date | Tue, 24 Feb 2026 08:53:06 +0000 |
| parents | |
| children | |
| files | redelacComputeAclim.R redelacComputeAclim.xml |
| diffstat | 2 files changed, 179 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/redelacComputeAclim.R Tue Feb 24 08:53:06 2026 +0000 @@ -0,0 +1,116 @@ +library(data.table) #version 1.14.2 +library(dplyr) #version 1.0.10 +library(ggplot2) +library(rlang) +library(stringr) +sessionInfo() + +args = commandArgs(trailingOnly = TRUE) + +climatPath = args[1] +horizons = args[2] +rdsOut = args[3] +csvOut = args[4] +png1Out = args[5] +png2Out = args[6] + +liste_mailles_SAFRAN <- list.dirs(climatPath,full.names = F,recursive = F) + +#agregation des fichiers climatiques dans un unique fichier +fichier_climat_tot<- NULL + + +for(maille_DRIAS in liste_mailles_SAFRAN){ + + setwd(paste0(climatPath,"/",maille_DRIAS)) + + filenames <- list.files() + + + fichier_climat_maille_tot <- NULL + f=1 + for (filename in filenames) + { + file <- as.data.frame(fread(filename,sep="\t", dec=".", header=FALSE)) + if (f==1) {fichier_climat_maille_tot <-file} else {fichier_climat_maille_tot <- bind_rows(fichier_climat_maille_tot,file)} + f=f+1 + } + fichier_climat_tot<- bind_rows(fichier_climat_tot,fichier_climat_maille_tot) + setwd("../..") +} + +#rm(file,fichier_climat_maille_tot) + +#entete des colonnes +# column 1: name of weather file +# column 2: year +# column 3: month +# column 4: day in month +# column 5: Julian day +# column 6: minimum temperature (degrees C) +# column 7: maximum temperature (degrees C) +# column 8: global radiation (MJ m-2 j-1) +# column 9: Penman PET (mm j-1) +# column 10: rainfall (mm j-1) +# column 11: wind (m s-1) +# column 12: vapour pressure (mbars) +# column 13: CO2 content(ppm) + +names(fichier_climat_tot) + +names(fichier_climat_tot)<- c("maille_DRIAS","annee","mois","jcal","jjulien","TN","TX","RG","ETP","P","V","PV","CO2") + + +# sanityzing + +trimedHorizon <-str_trim(horizons) +purgedHorizon <-str_sub(trimedHorizon, 1, nchar(trimedHorizon)-1) + +listHory <- lapply(unlist(strsplit(purgedHorizon, ",")), function(x) {tmpdata <- str_split(str_trim(x), " ")[[1]]; paste0("(annee<", tmpdata[3], ")&(annee>",tmpdata[2], ")~\"", tmpdata[1], "\"" )}) + +listHory + +paste(listHory, collapse = ",", sep = "") + +horizonsFilter <- parse_expr(paste(listHory, collapse = ",", sep = "")) + +listHory + +fichier_climat_tot <- fichier_climat_tot %>% + mutate(horizon=case_when(!!horizonsFilter)) + +#fichier_climat_tot <- fichier_climat_tot %>% +# mutate(horizon=case_when((annee>1990)&(annee<2025)~"ref")) + +#ecriture du fichier +saveRDS(fichier_climat_tot, rdsOut) + +fichier_aclim_an <- fichier_climat_tot %>% + select(maille_DRIAS,horizon,annee,V)%>% + group_by(maille_DRIAS,horizon,annee)%>% + summarise(Vmed = median(V,na.rm=T))%>% + mutate(aclim=-6.2*log(Vmed)+17.5) + +fichier_aclim_hor <- fichier_aclim_an %>% + select(maille_DRIAS,horizon,annee,aclim)%>% + group_by(maille_DRIAS,horizon)%>% + summarise(aclim = median(aclim,na.rm=T))%>% + filter(is.na(horizon)==F) + + +#ecriture des valeurs de aclim par maille SAFRAN et horizon +write.table(fichier_aclim_hor,csvOut,sep=";",dec=",",row.names = F) + + +#tracage des valeurs calculees de aclim +# ggplot()+geom_boxplot(data=fichier_aclim_an,aes(y=aclim)) +# ggplot()+geom_boxplot(data=fichier_aclim_an,aes(y=aclim,x=horizon)) +# ggplot()+geom_boxplot(data=fichier_aclim_an,aes(y=aclim,x=as.factor(maille_DRIAS))) + +ggplot()+geom_line(data=fichier_aclim_an ,aes(x=annee,y=aclim,group=maille_DRIAS,color=as.factor(maille_DRIAS))) +ggsave(png1Out) +ggplot()+ + geom_boxplot(data=fichier_aclim_an %>% filter(is.na(horizon)==F),aes(x=as.factor(maille_DRIAS),y=aclim,fill=horizon))+ + xlab("Maille DRIAS")+ +theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +ggsave(png2Out)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/redelacComputeAclim.xml Tue Feb 24 08:53:06 2026 +0000 @@ -0,0 +1,63 @@ +<tool id="redelacSticsComputeAclim" name="redelacSticsComputeAclim" version="1.0.1"> + <description>to compute aclim on Stics climate</description> + <requirements> + <container type="singularity">docker://registry.forge.inrae.fr/redelac/redelac-toolbox/sticsrpacks:5337507635242b3ad0f3559a1a6b666512ecf002 + </container> + </requirements> + <command detect_errors="aggressive"> + <![CDATA[ + mkdir Climat && + unzip -d ./Climat ${Climat} && + Rscript --verbose $__tool_directory__/redelacComputeAclim.R ./Climat " + #for $i, $h in enumerate($horizons) + ${h.name} ${h.min} ${h.max}, + #end for + " ./output.rds ./output.csv ./output1.png ./output2.png && + cp ./output.csv ${aclim} && + cp ./output.rds ${output} && + cp ./output1.png ${output1} && + cp ./output2.png ${output1} + ]]> + </command> + <inputs> + <repeat name ="horizons" min="1" title="Specify a horizon"> + <param name="name" type="text" value="ref" label="The horizon name"/> + <param name="min" type="integer" value="1990" label="The horizon lower range year"/> + <param name="max" type="integer" value="2025" label="The horizon upper range year"/> + </repeat> + + <param name="Climat" type="data" format="zip" label="Select a climat scenario (zip file)"/> + </inputs> + <outputs> + <data format="csv" name="aclim" + label="aclimValuesPerHorizon"> + </data> + <data format="rds" name="output" + label="output"> + </data> + <data format="png" name="output1" + label="output1"> + </data> + <data format="png" name="output2" + label="output2"> + </data> + </outputs> + <tests> + </tests> + <help> +*The usage of this tool is restricted to the user of the redelac_authorized group.* + +*To be granted, apply to the REDELAC Project Team and then request to SIWAA* + +Documentation +------------- +A tool to compute AClim for REDELAC + +Credits +------- +- Wrapped Tool Author: https://www6.paca.inrae.fr/stics_eng/About-us/Project-Stics-Team +- Stics Site: https://www6.paca.inra.fr/stics_eng +- Galaxy Tool Maintainer: Patrick Chabrier patrick.chabrier@inrae.fr +- Copyright: INRAE + </help> +</tool>
