From c90cff654a4631c9151e1d52725cb0e8a109567e Mon Sep 17 00:00:00 2001 From: "louis.heraut" <louis.heraut@inrae.fr> Date: Tue, 16 Nov 2021 17:07:20 +0100 Subject: [PATCH] Trend analyse mean --- processing/analyse.R | 8 -------- processing/extractNV.R | 12 +++++++----- processing/format.R | 23 +++++++++++++++++++++++ processing/prepare.R | 13 ------------- script.R | 42 +++++++++++++++++++++++++++++------------- script_install.R | 3 ++- 6 files changed, 61 insertions(+), 40 deletions(-) create mode 100644 processing/format.R delete mode 100644 processing/prepare.R diff --git a/processing/analyse.R b/processing/analyse.R index d5fcbe7..851f63e 100644 --- a/processing/analyse.R +++ b/processing/analyse.R @@ -1,5 +1,4 @@ # Usefull library -library(StatsAnalysisTrend) library(dplyr) @@ -58,10 +57,3 @@ get_lacune = function (df_data, df_info) { return (df_lac) } - - - - - - - diff --git a/processing/extractNV.R b/processing/extractNV.R index 8d1f94e..babdf90 100644 --- a/processing/extractNV.R +++ b/processing/extractNV.R @@ -62,6 +62,8 @@ extractNVlist_info = function (computer_data_path, filedir, listdir, listname, v paste(missing, '.txt', sep='')))) + + df_info = df_info[order(df_info$code),] } else { print(paste('filename', list_path, 'do not exist')) @@ -72,11 +74,11 @@ extractNVlist_info = function (computer_data_path, filedir, listdir, listname, v } # Example -df_info = extractNVlist_info( - "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data", - 'France207', - '', - 'liste_bv_principaux_global.txt') +# df_info = extractNVlist_info( +# "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data", +# 'France207', +# '', +# 'liste_bv_principaux_global.txt') # Extraction of data diff --git a/processing/format.R b/processing/format.R new file mode 100644 index 0000000..57d6cc3 --- /dev/null +++ b/processing/format.R @@ -0,0 +1,23 @@ +library(dplyr) + +prepare = function(df_data, df_info) { + + df_data$Gcode = as.integer(factor(df_data$code)) + df_data = tibble(Date=df_data$Date, + Gcode=df_data$Gcode, + Qm3s=df_data$Qm3s + ) + + df_info$Gcode = as.integer(factor(df_info$code)) + + return (list(data=df_data, info=df_info)) +} + + +clean = function (df_xTrend, df_info) { + + print(df_info$Gcode == df_xTrend$group1) + df_xTrend$code = df_info$code[df_info$Gcode == df_xTrend$group1] + + return (df_xTrend) +} diff --git a/processing/prepare.R b/processing/prepare.R deleted file mode 100644 index d61dded..0000000 --- a/processing/prepare.R +++ /dev/null @@ -1,13 +0,0 @@ - - -prepare = function(df_data, df_info) { - - df_data$Gcode = as.integer(factor(df_data$code)) - df_data = tibble(Date=df_data$Date, - Qm3s=df_data$Qm3s, - Gcode=df_data$code) - - df_info$Gcode = as.integer(factor(df_info$code)) - - return (list(data=df_data, info=df_info)) -} diff --git a/script.R b/script.R index 8ea2ea6..6c5468e 100644 --- a/script.R +++ b/script.R @@ -17,8 +17,8 @@ computer_work_path = # Path to the directory where BH data is stored BHfiledir = # "test" - # "" - "BanqueHydro_Export2021" + "" + # "BanqueHydro_Export2021" ## Manual selection ## # Name of the file that will be analysed from the BH directory @@ -33,20 +33,20 @@ BHlistdir = "" BHlistname = - # "" - "Liste-station_RRSE.docx" + "" + # "Liste-station_RRSE.docx" ### NIVALE ### # Path to the directory where NV data is stored NVfiledir = - "" - # "France207" + # "" + "France207" # Name of the file that will be analysed from the NV directory NVfilename = - "" - # "all" + # "" + "all" # Path to the list file of information about station that will be analysed @@ -54,25 +54,34 @@ NVlistdir = "" NVlistname = - "" - # "liste_bv_principaux_global.txt" + # "" + "liste_bv_principaux_global.txt" + + +### TREND ANALYSIS ### +# Time period to analyse +period = c("1960-01-01","2020-01-01") + + ######################## +# FILE STRUCTURE # # Set working directory setwd(computer_work_path) # Sourcing R file source('processing/extractBH.R') source('processing/extractNV.R') -source('processing/prepare.R') +source('processing/format.R') source('processing/analyse.R') source('plotting/panel.R') # Usefull library - +library(StatsAnalysisTrend) +library(dplyr) # Result directory resdir = file.path(computer_work_path, 'results') @@ -164,6 +173,13 @@ if (!is.null(df_data_NV) & !is.null(df_data_BH)) { df_list = prepare(df_data, df_info) +df_meanEx = extract.Var(data.station=df_list, + funct=mean, + period=period, + pos.datetime=1, + na.rm=TRUE) - +df_meanTrend = Estimate.stats(data.extract=df_meanEx) +### /!\ verify order conservation ### +df_meanTrend = clean(df_meanTrend, df_info) diff --git a/script_install.R b/script_install.R index c8cdf2a..dbd980c 100644 --- a/script_install.R +++ b/script_install.R @@ -5,9 +5,10 @@ install.packages("devtools") install.packages("dplyr") install.packages("ggplot2") install.packages("officer") +install.packages("lubridate") library(devtools) -install_github("https://github.com/benRenard/BFunk") +install_github("https://github.com/benRenard/BFunk") #type '1' # install_git("git@gitlab-ssh.irstea.fr:valentin.mansanarez/statistical-analysis-of-trends.git") # SSH install_git("https://gitlab.irstea.fr/valentin.mansanarez/statistical-analysis-of-trends.git") -- GitLab