Commit 07b7318f authored by Heraut Louis's avatar Heraut Louis
Browse files

summary table txt

parent 0e823839
No related merge requests found
Showing with 167 additions and 133 deletions
+167 -133
...@@ -838,6 +838,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, ...@@ -838,6 +838,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period,
# significant figures # significant figures
trendValueC = signif(trendValue, 2) trendValueC = signif(trendValue, 2)
} }
trendValueC = as.character(trendValueC)
# If it is significative # If it is significative
if (Alpha_trend_per[i] == 'TRUE') { if (Alpha_trend_per[i] == 'TRUE') {
...@@ -860,7 +861,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, ...@@ -860,7 +861,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period,
mat = mat + mat = mat +
# Writes the mean trend # Writes the mean trend
annotate('text', x=X[i], y=Y[i], annotate('text', x=X[i], y=Y[i],
label=trendValueC, label=bquote(bold(.(trendValueC))),
hjust=0.5, vjust=0.5, hjust=0.5, vjust=0.5,
size=3, color=Tcolor) + size=3, color=Tcolor) +
# Writes the mean of the associated variable # Writes the mean of the associated variable
...@@ -1165,11 +1166,12 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, ...@@ -1165,11 +1166,12 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period,
# significant figures # significant figures
breakValueC = signif(breakValue, 2) breakValueC = signif(breakValue, 2)
} }
breakValueC = as.character(breakValueC)
# Writes breaking values # Writes breaking values
mat = mat + mat = mat +
annotate('text', x=Xr_mean[i], y=Y[i], annotate('text', x=Xr_mean[i], y=Y[i],
label=breakValueC, label=bquote(bold(.(breakValueC))),
hjust=0.5, vjust=0.5, hjust=0.5, vjust=0.5,
size=3, color='white') size=3, color='white')
} }
......
...@@ -97,7 +97,7 @@ get_intercept = function (df_Xtrend, df_Xlist, unit2day=365.25) { ...@@ -97,7 +97,7 @@ get_intercept = function (df_Xtrend, df_Xlist, unit2day=365.25) {
### 1.1. QA __________________________________________________________ ### 1.1. QA __________________________________________________________
# Realise the trend analysis of the average annual flow (QA) # Realise the trend analysis of the average annual flow (QA)
# hydrological variable # hydrological variable
get_QAtrend = function (df_data, df_meta, period, alpha, dayLac_lim, yearNA_lim, df_flag, df_mod=tibble()) { get_QAtrend = function (df_data, df_meta, period, per.start, alpha, dayLac_lim, yearNA_lim, df_flag, df_mod=tibble()) {
# Local corrections if needed # Local corrections if needed
res = flag_data(df_data, df_meta, res = flag_data(df_data, df_meta,
...@@ -132,8 +132,12 @@ get_QAtrend = function (df_data, df_meta, period, alpha, dayLac_lim, yearNA_lim, ...@@ -132,8 +132,12 @@ get_QAtrend = function (df_data, df_meta, period, alpha, dayLac_lim, yearNA_lim,
funct=mean, funct=mean,
timestep='year', timestep='year',
period=per, period=per,
per.start=per.start,
pos.datetime=1, pos.datetime=1,
na.rm=TRUE) na.rm=TRUE)
# df_QAEx = date_correction(df_QAEx, per)
# Compute the trend analysis # Compute the trend analysis
df_QAtrend = Estimate.stats(data.extract=df_QAEx, df_QAtrend = Estimate.stats(data.extract=df_QAEx,
level=alpha, level=alpha,
......
...@@ -136,7 +136,7 @@ iRegHydro = c('D'='Affluents du Rhin', ...@@ -136,7 +136,7 @@ iRegHydro = c('D'='Affluents du Rhin',
## 2. SELECTION ______________________________________________________ ## 2. SELECTION ______________________________________________________
### 2.1. Creation of selection _______________________________________ ### 2.1. Creation of a selection _____________________________________
# Create a txt file that resume all the station data files present # Create a txt file that resume all the station data files present
# in a filedir # in a filedir
create_selection = function (computer_data_path, filedir, outname, optname='_HYDRO_QJM') { create_selection = function (computer_data_path, filedir, outname, optname='_HYDRO_QJM') {
...@@ -178,11 +178,11 @@ create_selection = function (computer_data_path, filedir, outname, optname='_HYD ...@@ -178,11 +178,11 @@ create_selection = function (computer_data_path, filedir, outname, optname='_HYD
# create_selection( # create_selection(
# "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data", # "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data",
# "France207", # "France207",
# "INRAE_selection.txt") # "selection.txt")
### 2.2. Agence de l'eau Adour-Garonne selection _____________________ ### 2.2. Agence de l'eau Adour-Garonne selection _____________________
# Gets the selection of station from the 'Liste-station_RRSE.docx' file # Gets the selection of station from the 'Liste-station_RRSE.docx' file
get_selection_AEAG = function (computer_data_path, listdir, listname, get_selection_DOCX = function (computer_data_path, listdir, listname,
cnames=c('code','station', 'BV_km2', cnames=c('code','station', 'BV_km2',
'axe_principal_concerne', 'axe_principal_concerne',
'longueur_serie', 'commentaires', 'longueur_serie', 'commentaires',
...@@ -227,7 +227,7 @@ get_selection_AEAG = function (computer_data_path, listdir, listname, ...@@ -227,7 +227,7 @@ get_selection_AEAG = function (computer_data_path, listdir, listname,
return (df_selec) return (df_selec)
} }
# Example # Example
# df_selec_AEAG = get_selection_AEAG( # df_selec_DOCX = get_selection_DOCX(
# "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data", # "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data",
# "", # "",
# "Liste-station_RRSE.docx", # "Liste-station_RRSE.docx",
...@@ -240,10 +240,10 @@ get_selection_AEAG = function (computer_data_path, listdir, listname, ...@@ -240,10 +240,10 @@ get_selection_AEAG = function (computer_data_path, listdir, listname,
# c_num=c('BV_km2', # c_num=c('BV_km2',
# 'longueur_serie')) # 'longueur_serie'))
### 2.3. INRAE selection _____________________________________________ ### 2.3. TXT selection _____________________________________________
# Gets the selection of station from the selection txt file generated # Gets the selection of station from the selection txt file generated
# by the 'create_selection' function # by the 'create_selection' function
get_selection_INRAE = function (computer_data_path, listdir, listname) { get_selection_TXT = function (computer_data_path, listdir, listname) {
# Gets the file path to the data # Gets the file path to the data
list_path = file.path(computer_data_path, listdir, listname) list_path = file.path(computer_data_path, listdir, listname)
...@@ -259,10 +259,10 @@ get_selection_INRAE = function (computer_data_path, listdir, listname) { ...@@ -259,10 +259,10 @@ get_selection_INRAE = function (computer_data_path, listdir, listname) {
return (df_selec) return (df_selec)
} }
# Example # Example
# df_selec_INRAE = get_selection_INRAE( # df_selec_TXT = get_selection_TXT(
# "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data", # "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data",
# "", # "",
# "INRAE_selection.txt") # "selection.txt")
## 3. EXTRACTION _____________________________________________________ ## 3. EXTRACTION _____________________________________________________
......
...@@ -306,6 +306,38 @@ sampling_data = function (df_data, df_meta, sampleSpan=c('05-01', '11-30'), Code ...@@ -306,6 +306,38 @@ sampling_data = function (df_data, df_meta, sampleSpan=c('05-01', '11-30'), Code
## 2. DURING TREND ANALYSE ___________________________________________ ## 2. DURING TREND ANALYSE ___________________________________________
date_correction = function (df_XEx, per) {
# Takes the first date as example
exDate = df_XEx$datetime[1]
# Finds the number of dash in the date
nbt = lengths(regmatches(exDate, gregexpr('-', exDate)))
# If there is only one dash
if (nbt == 1) {
# Converts it to date from a year and a month
Date = paste(df_XEx$datetime, '01', sep='-')
# If there is no dash
} else if (nbt == 0) {
# Converts it to date from only a year
Date = paste(df_XEx$datetime, '01', '01', sep='-')
# If there is more than 2 dashes
} else if (nbt != 2) {
# This is not a classical date
stop('erreur of date format')
}
Start = per[1]
End = per[2]
df_XEx = df_XEx[Date >= Start & Date <= End,]
return (df_XEx)
}
### 2.1. Preparation _________________________________________________ ### 2.1. Preparation _________________________________________________
# Prepares the data in order to have a list of a data tibble with # Prepares the data in order to have a list of a data tibble with
# date, group and flow column and a info tibble with the station code # date, group and flow column and a info tibble with the station code
...@@ -452,7 +484,7 @@ prepare_date = function(df_XEx, df_Xlist, per.start="01-01") { ...@@ -452,7 +484,7 @@ prepare_date = function(df_XEx, df_Xlist, per.start="01-01") {
### 3.1. Period of trend _____________________________________________ ### 3.1. Period of trend _____________________________________________
# Compute the start and the end of the period for a trend analysis # Compute the start and the end of the period for a trend analysis
# according to the accessible data # according to the accessible data
get_period = function (per, df_Xtrend, df_XEx, df_Xlist) { get_period = function (per, df_Xtrend, df_XEx, df_Xlist, per.start='01-01') {
# Converts results of trend to tibble # Converts results of trend to tibble
df_Xtrend = tibble(df_Xtrend) df_Xtrend = tibble(df_Xtrend)
...@@ -461,38 +493,30 @@ get_period = function (per, df_Xtrend, df_XEx, df_Xlist) { ...@@ -461,38 +493,30 @@ get_period = function (per, df_Xtrend, df_XEx, df_Xlist) {
df_Xtrend$period_start = as.Date("1970-01-01") df_Xtrend$period_start = as.Date("1970-01-01")
df_Xtrend$period_end = as.Date("1970-01-01") df_Xtrend$period_end = as.Date("1970-01-01")
# Changes the format of the date variable to date # print(df_XEx)
df_Xlisttmp = reprepare(df_XEx, df_Xlist, colnamegroup=c('code')) # print(head(df_XEx))
df_XExtmp = df_Xlisttmp$data # print(tail(df_XEx))
# print('')
df_data = df_Xlist$data
df_info = df_Xlist$info
# For all the different group # For all the different group
for (g in df_Xlisttmp$info$group) { for (g in df_info$group) {
# Gets the analyse data associated to the group # Gets the analyse data associated to the group
df_XExtmp_code = df_XExtmp[df_XExtmp$group == g,] df_data_code = df_data[df_data$group == g,]
# Gets the id in the trend result associated to the group # Gets the id in the trend result associated to the group
id = which(df_Xtrend$group1 == g) id = which(df_Xtrend$group1 == g)
# Computes index of the nearest accessible start and end date
OkStart = df_XExtmp_code$Date >= as.Date(per[1])
OkEnd = df_XExtmp_code$Date <= as.Date(per[2])
# DateStart = df_XExtmp_code$Date[OkStart]
# DateEnd = df_XExtmp_code$Date[OkEnd]
DateStart = df_XExtmp_code$Date
DateEnd = df_XExtmp_code$Date
iStart = which.min(abs(DateStart - as.Date(per[1]))) Date = df_data_code$Date
iEnd = which.min(abs(DateEnd - as.Date(per[2]))) Date = df_data_code$Date
# print(nrow(df_XEx)) iStart = which.min(abs(Date - as.Date(per[1])))
# print(as.Date(DateStart[iStart])) iEnd = which.min(abs(Date - as.Date(per[2])))
# print(head(df_XEx))
# print(tail(df_XEx))
# print(as.Date(DateEnd[iEnd]))
# Stores the start and end of the trend analysis # Stores the start and end of the trend analysis
df_Xtrend$period_start[id] = as.Date(DateStart[iStart]) df_Xtrend$period_start[id] = as.Date(Date[iStart])
df_Xtrend$period_end[id] = as.Date(DateEnd[iEnd]) df_Xtrend$period_end[id] = as.Date(Date[iEnd])
} }
return (df_Xtrend) return (df_Xtrend)
} }
......
...@@ -66,8 +66,10 @@ filename = ...@@ -66,8 +66,10 @@ filename =
# "Q6332510_HYDRO_QJM.txt", # "Q6332510_HYDRO_QJM.txt",
# "Q7002910_HYDRO_QJM.txt", # "Q7002910_HYDRO_QJM.txt",
# "Q0214010_HYDRO_QJM.txt", # "Q0214010_HYDRO_QJM.txt",
# "O3035210_HYDRO_QJM.txt",
# "O0554010_HYDRO_QJM.txt", # "O0362510_HYDRO_QJM.txt",
# "O0554010_HYDRO_QJM.txt"
# "Q6332510_HYDRO_QJM.txt" # "Q6332510_HYDRO_QJM.txt"
# "O0362510_HYDRO_QJM.txt" # "O0362510_HYDRO_QJM.txt"
# ) # )
...@@ -76,24 +78,25 @@ filename = ...@@ -76,24 +78,25 @@ filename =
## AGENCE EAU ADOUR GARONNE SELECTION ## AGENCE EAU ADOUR GARONNE SELECTION
# Path to the 'docx' list file of station from the Agence de l'eau # Path to the 'docx' list file of station from the Agence de l'eau
# Adour-Garonne that will be analysed # Adour-Garonne that will be analysed
AEAGlistdir = DOCXlistdir =
"" ""
AEAGlistname = DOCXlistname =
# "" # ""
"Liste-station_RRSE.docx" "Liste-station_RRSE.docx"
## NIVALE SELECTION ## MANUAL SELECTION
# Path to the 'txt' list file of station from INRAE that will be analysed # Path to the 'txt' list file of station from manualy created that
# will be analysed
# Generated with : # Generated with :
# create_selection(computer_data_path, 'dirname', 'example.txt') # create_selection(computer_data_path, 'dirname', 'example.txt')
INRAElistdir = TXTlistdir =
"" ""
INRAElistname = TXTlistname =
"" ""
# "INRAE_selection.txt" # "selection.txt"
which_layout = which_layout =
...@@ -151,10 +154,10 @@ df_flag = data.frame( ...@@ -151,10 +154,10 @@ df_flag = data.frame(
# Sampling span of the data # Sampling span of the data
sampleSpan = c('05-01', '11-30') sampleSpan = c('05-01', '11-30')
# Is the hydrological network needs to be plot # If the hydrological network needs to be plot
show_river = FALSE show_river = FALSE
# If results and data used in the analysis needs to be written # If results and dresata used in the analysis needs to be written
saving = FALSE saving = FALSE
############### END OF REGION TO MODIFY (without risk) ############### ############### END OF REGION TO MODIFY (without risk) ###############
...@@ -217,18 +220,18 @@ rv_shpname = 'CoursEau_FXX.shp' ...@@ -217,18 +220,18 @@ rv_shpname = 'CoursEau_FXX.shp'
## 2. SELECTION OF STATION ___________________________________________ ## 2. SELECTION OF STATION ___________________________________________
# Initialization of null data frame if there is no data selected # Initialization of null data frame if there is no data selected
df_data_AEAG = NULL df_data_DOCX = NULL
df_data_INRAE = NULL df_data_TXT = NULL
df_meta_AEAG = NULL df_meta_DOCX = NULL
df_meta_INRAE = NULL df_meta_TXT = NULL
### 2.1. Selection of the Agence de l'eau Adour-Garonne ______________ ### 2.1. Selection of the Agence de l'eau Adour-Garonne ______________
if (AEAGlistname != "") { if (DOCXlistname != "") {
# Get only the selected station from a list station file # Get only the selected station from a list station file
df_selec_AEAG = get_selection_AEAG(computer_data_path, df_selec_DOCX = get_selection_DOCX(computer_data_path,
AEAGlistdir, DOCXlistdir,
AEAGlistname, DOCXlistname,
cnames=c('code', cnames=c('code',
'station', 'station',
'BV_km2', 'BV_km2',
...@@ -240,40 +243,40 @@ if (AEAGlistname != "") { ...@@ -240,40 +243,40 @@ if (AEAGlistname != "") {
'longueur_serie')) 'longueur_serie'))
# Get filenames of the selection # Get filenames of the selection
filename = df_selec_AEAG[df_selec_AEAG$ok,]$filename filename = df_selec_DOCX[df_selec_DOCX$ok,]$filename
# Extract metadata about selected stations # Extract metadata about selected stations
df_meta_AEAG = extract_meta(computer_data_path, filedir, filename) df_meta_DOCX = extract_meta(computer_data_path, filedir, filename)
# Extract data about selected stations # Extract data about selected stations
df_data_AEAG = extract_data(computer_data_path, filedir, filename) df_data_DOCX = extract_data(computer_data_path, filedir, filename)
} }
### 2.2. INRAE selection _____________________________________________ ### 2.2. TXT selection _____________________________________________
if (INRAElistname != ""){ if (TXTlistname != ""){
# Get only the selected station from a list station file # Get only the selected station from a list station file
df_selec_INRAE = get_selection_INRAE(computer_data_path, df_selec_TXT = get_selection_TXT(computer_data_path,
INRAElistdir, TXTlistdir,
INRAElistname) TXTlistname)
# Get filenames of the selection # Get filenames of the selection
filename = df_selec_INRAE[df_selec_INRAE$ok,]$filename filename = df_selec_TXT[df_selec_TXT$ok,]$filename
# Extract metadata about selected stations # Extract metadata about selected stations
df_meta_INRAE = extract_meta(computer_data_path, filedir, filename) df_meta_TXT = extract_meta(computer_data_path, filedir, filename)
# Extract data about selected stations # Extract data about selected stations
df_data_INRAE = extract_data(computer_data_path, filedir, filename) df_data_TXT = extract_data(computer_data_path, filedir, filename)
} }
### 2.3. Manual selection ____________________________________________ ### 2.3. Manual selection ____________________________________________
if (AEAGlistname == "" & INRAElistname == "") { if (DOCXlistname == "" & TXTlistname == "") {
# Extract metadata about selected stations # Extract metadata about selected stations
df_meta_AEAG = extract_meta(computer_data_path, filedir, filename) df_meta_DOCX = extract_meta(computer_data_path, filedir, filename)
# Extract data about selected stations # Extract data about selected stations
df_data_AEAG = extract_data(computer_data_path, filedir, filename) df_data_DOCX = extract_data(computer_data_path, filedir, filename)
} }
### 2.4. Data join ___________________________________________________ ### 2.4. Data join ___________________________________________________
df_join = join_selection(df_data_AEAG, df_data_INRAE, df_join = join_selection(df_data_DOCX, df_data_TXT,
df_meta_AEAG, df_meta_INRAE) df_meta_DOCX, df_meta_TXT)
df_data = df_join$data df_data = df_join$data
df_meta = df_join$meta df_meta = df_join$meta
...@@ -310,68 +313,69 @@ df_meta = get_hydrograph(df_data, df_meta, period=mean_period[[1]])$meta ...@@ -310,68 +313,69 @@ df_meta = get_hydrograph(df_data, df_meta, period=mean_period[[1]])$meta
df_sqrt = compute_sqrt(df_data) df_sqrt = compute_sqrt(df_data)
### 3.2. Trend analysis ______________________________________________ ### 3.2. Trend analysis ______________________________________________
# if ('analyse' %in% which_layout) { if ('analyse' %in% which_layout) {
# # QA trend # QA trend
# res = get_QAtrend(df_data, df_meta, res = get_QAtrend(df_data, df_meta,
# period=trend_period, period=trend_period,
# alpha=alpha, per.start='09-01',
# dayLac_lim=dayLac_lim, alpha=alpha,
# yearNA_lim=yearNA_lim, dayLac_lim=dayLac_lim,
# df_flag=df_flag) yearNA_lim=yearNA_lim,
# df_QAdata = res$data df_flag=df_flag)
# df_QAmod = res$mod df_QAdata = res$data
# res_QAtrend = res$analyse df_QAmod = res$mod
res_QAtrend = res$analyse
# # QMNA tend
# res = get_QMNAtrend(df_data, df_meta, # QMNA tend
# period=trend_period, res = get_QMNAtrend(df_data, df_meta,
# alpha=alpha, period=trend_period,
# sampleSpan=sampleSpan, alpha=alpha,
# dayLac_lim=dayLac_lim, sampleSpan=sampleSpan,
# yearNA_lim=yearNA_lim, dayLac_lim=dayLac_lim,
# df_flag=df_flag) yearNA_lim=yearNA_lim,
# df_QMNAdata = res$data df_flag=df_flag)
# df_QMNAmod = res$mod df_QMNAdata = res$data
# res_QMNAtrend = res$analyse df_QMNAmod = res$mod
res_QMNAtrend = res$analyse
# # VCN10 trend
# res = get_VCN10trend(df_data, df_meta, # VCN10 trend
# period=trend_period, res = get_VCN10trend(df_data, df_meta,
# alpha=alpha, period=trend_period,
# sampleSpan=sampleSpan, alpha=alpha,
# dayLac_lim=dayLac_lim, sampleSpan=sampleSpan,
# yearNA_lim=yearNA_lim, dayLac_lim=dayLac_lim,
# df_flag=df_flag) yearNA_lim=yearNA_lim,
# df_VCN10data = res$data df_flag=df_flag)
# df_VCN10mod = res$mod df_VCN10data = res$data
# res_VCN10trend = res$analyse df_VCN10mod = res$mod
res_VCN10trend = res$analyse
# # Start date for low water trend
# res = get_tDEBtrend(df_data, df_meta, # Start date for low water trend
# period=trend_period, res = get_tDEBtrend(df_data, df_meta,
# alpha=alpha, period=trend_period,
# sampleSpan=sampleSpan, alpha=alpha,
# thresold_type='VCN10', sampleSpan=sampleSpan,
# select_longest=TRUE, thresold_type='VCN10',
# dayLac_lim=dayLac_lim, select_longest=TRUE,
# yearNA_lim=yearNA_lim, dayLac_lim=dayLac_lim,
# df_flag=df_flag) yearNA_lim=yearNA_lim,
# df_tDEBdata = res$data df_flag=df_flag)
# df_tDEBmod = res$mod df_tDEBdata = res$data
# res_tDEBtrend = res$analyse df_tDEBmod = res$mod
res_tDEBtrend = res$analyse
# # Center date for low water trend
# res = get_tCENtrend(df_data, df_meta, # Center date for low water trend
# period=trend_period, res = get_tCENtrend(df_data, df_meta,
# alpha=alpha, period=trend_period,
# sampleSpan=sampleSpan, alpha=alpha,
# dayLac_lim=dayLac_lim, sampleSpan=sampleSpan,
# yearNA_lim=yearNA_lim, dayLac_lim=dayLac_lim,
# df_flag=df_flag) yearNA_lim=yearNA_lim,
# df_tCENdata = res$data df_flag=df_flag)
# df_tCENmod = res$mod df_tCENdata = res$data
# res_tCENtrend = res$analyse df_tCENmod = res$mod
# } res_tCENtrend = res$analyse
}
### 3.3. Break analysis ______________________________________________ ### 3.3. Break analysis ______________________________________________
# df_break = get_break(res_QAtrend$data, df_meta) # df_break = get_break(res_QAtrend$data, df_meta)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment