diff --git a/processing/analyse.R b/processing/analyse.R index d5fcbe7feec437b3eeeb9bf5c832a1976726ac31..851f63e9ee2a90be636850a5dc2ea9814d262ad4 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 8d1f94ee3b110d281e17f1d97a87639e8ee89ae5..babdf908a572eb9f45e37e72305976738ea07c04 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 0000000000000000000000000000000000000000..57d6cc35ab22d1ead1f38d4e7b91e8421bbe47d5 --- /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 d61ddedd0a50048cdb1db855b93481d226b18b1a..0000000000000000000000000000000000000000 --- 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 8ea2ea69bea6dddfad8d5a0c091235bbaaa9ffbc..6c5468e58c2c346838f859c4c852a73512030f9d 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 c8cdf2addf85d4cd2473243ee6260b940fdf7488..dbd980c206766c55074d27713b605eca3a8fbdc0 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")