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,
# significant figures
trendValueC = signif(trendValue, 2)
}
trendValueC = as.character(trendValueC)
# If it is significative
if (Alpha_trend_per[i] == 'TRUE') {
......@@ -860,7 +861,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period,
mat = mat +
# Writes the mean trend
annotate('text', x=X[i], y=Y[i],
label=trendValueC,
label=bquote(bold(.(trendValueC))),
hjust=0.5, vjust=0.5,
size=3, color=Tcolor) +
# Writes the mean of the associated variable
......@@ -1165,11 +1166,12 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period,
# significant figures
breakValueC = signif(breakValue, 2)
}
breakValueC = as.character(breakValueC)
# Writes breaking values
mat = mat +
annotate('text', x=Xr_mean[i], y=Y[i],
label=breakValueC,
label=bquote(bold(.(breakValueC))),
hjust=0.5, vjust=0.5,
size=3, color='white')
}
......
......@@ -97,7 +97,7 @@ get_intercept = function (df_Xtrend, df_Xlist, unit2day=365.25) {
### 1.1. QA __________________________________________________________
# Realise the trend analysis of the average annual flow (QA)
# 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
res = flag_data(df_data, df_meta,
......@@ -132,8 +132,12 @@ get_QAtrend = function (df_data, df_meta, period, alpha, dayLac_lim, yearNA_lim,
funct=mean,
timestep='year',
period=per,
per.start=per.start,
pos.datetime=1,
na.rm=TRUE)
# df_QAEx = date_correction(df_QAEx, per)
# Compute the trend analysis
df_QAtrend = Estimate.stats(data.extract=df_QAEx,
level=alpha,
......
......@@ -136,7 +136,7 @@ iRegHydro = c('D'='Affluents du Rhin',
## 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
# in a filedir
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
# create_selection(
# "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data",
# "France207",
# "INRAE_selection.txt")
# "selection.txt")
### 2.2. Agence de l'eau Adour-Garonne selection _____________________
# 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',
'axe_principal_concerne',
'longueur_serie', 'commentaires',
......@@ -227,7 +227,7 @@ get_selection_AEAG = function (computer_data_path, listdir, listname,
return (df_selec)
}
# Example
# df_selec_AEAG = get_selection_AEAG(
# df_selec_DOCX = get_selection_DOCX(
# "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data",
# "",
# "Liste-station_RRSE.docx",
......@@ -240,10 +240,10 @@ get_selection_AEAG = function (computer_data_path, listdir, listname,
# c_num=c('BV_km2',
# 'longueur_serie'))
### 2.3. INRAE selection _____________________________________________
### 2.3. TXT selection _____________________________________________
# Gets the selection of station from the selection txt file generated
# 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
list_path = file.path(computer_data_path, listdir, listname)
......@@ -259,10 +259,10 @@ get_selection_INRAE = function (computer_data_path, listdir, listname) {
return (df_selec)
}
# Example
# df_selec_INRAE = get_selection_INRAE(
# df_selec_TXT = get_selection_TXT(
# "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data",
# "",
# "INRAE_selection.txt")
# "selection.txt")
## 3. EXTRACTION _____________________________________________________
......
......@@ -306,6 +306,38 @@ sampling_data = function (df_data, df_meta, sampleSpan=c('05-01', '11-30'), Code
## 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 _________________________________________________
# 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
......@@ -452,7 +484,7 @@ prepare_date = function(df_XEx, df_Xlist, per.start="01-01") {
### 3.1. Period of trend _____________________________________________
# Compute the start and the end of the period for a trend analysis
# 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
df_Xtrend = tibble(df_Xtrend)
......@@ -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_end = as.Date("1970-01-01")
# Changes the format of the date variable to date
df_Xlisttmp = reprepare(df_XEx, df_Xlist, colnamegroup=c('code'))
df_XExtmp = df_Xlisttmp$data
# print(df_XEx)
# print(head(df_XEx))
# print(tail(df_XEx))
# print('')
df_data = df_Xlist$data
df_info = df_Xlist$info
# 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
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
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])))
iEnd = which.min(abs(DateEnd - as.Date(per[2])))
# print(nrow(df_XEx))
# print(as.Date(DateStart[iStart]))
# print(head(df_XEx))
# print(tail(df_XEx))
# print(as.Date(DateEnd[iEnd]))
Date = df_data_code$Date
Date = df_data_code$Date
iStart = which.min(abs(Date - as.Date(per[1])))
iEnd = which.min(abs(Date - as.Date(per[2])))
# Stores the start and end of the trend analysis
df_Xtrend$period_start[id] = as.Date(DateStart[iStart])
df_Xtrend$period_end[id] = as.Date(DateEnd[iEnd])
df_Xtrend$period_start[id] = as.Date(Date[iStart])
df_Xtrend$period_end[id] = as.Date(Date[iEnd])
}
return (df_Xtrend)
}
......
......@@ -66,8 +66,10 @@ filename =
# "Q6332510_HYDRO_QJM.txt",
# "Q7002910_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"
# "O0362510_HYDRO_QJM.txt"
# )
......@@ -76,24 +78,25 @@ filename =
## AGENCE EAU ADOUR GARONNE SELECTION
# Path to the 'docx' list file of station from the Agence de l'eau
# Adour-Garonne that will be analysed
AEAGlistdir =
DOCXlistdir =
""
AEAGlistname =
DOCXlistname =
# ""
"Liste-station_RRSE.docx"
## NIVALE SELECTION
# Path to the 'txt' list file of station from INRAE that will be analysed
## MANUAL SELECTION
# Path to the 'txt' list file of station from manualy created that
# will be analysed
# Generated with :
# create_selection(computer_data_path, 'dirname', 'example.txt')
INRAElistdir =
TXTlistdir =
""
INRAElistname =
TXTlistname =
""
# "INRAE_selection.txt"
# "selection.txt"
which_layout =
......@@ -151,10 +154,10 @@ df_flag = data.frame(
# Sampling span of the data
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
# 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
############### END OF REGION TO MODIFY (without risk) ###############
......@@ -217,18 +220,18 @@ rv_shpname = 'CoursEau_FXX.shp'
## 2. SELECTION OF STATION ___________________________________________
# Initialization of null data frame if there is no data selected
df_data_AEAG = NULL
df_data_INRAE = NULL
df_meta_AEAG = NULL
df_meta_INRAE = NULL
df_data_DOCX = NULL
df_data_TXT = NULL
df_meta_DOCX = NULL
df_meta_TXT = NULL
### 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
df_selec_AEAG = get_selection_AEAG(computer_data_path,
AEAGlistdir,
AEAGlistname,
df_selec_DOCX = get_selection_DOCX(computer_data_path,
DOCXlistdir,
DOCXlistname,
cnames=c('code',
'station',
'BV_km2',
......@@ -240,40 +243,40 @@ if (AEAGlistname != "") {
'longueur_serie'))
# 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
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
df_data_AEAG = extract_data(computer_data_path, filedir, filename)
df_data_DOCX = extract_data(computer_data_path, filedir, filename)
}
### 2.2. INRAE selection _____________________________________________
if (INRAElistname != ""){
### 2.2. TXT selection _____________________________________________
if (TXTlistname != ""){
# Get only the selected station from a list station file
df_selec_INRAE = get_selection_INRAE(computer_data_path,
INRAElistdir,
INRAElistname)
df_selec_TXT = get_selection_TXT(computer_data_path,
TXTlistdir,
TXTlistname)
# 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
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
df_data_INRAE = extract_data(computer_data_path, filedir, filename)
df_data_TXT = extract_data(computer_data_path, filedir, filename)
}
### 2.3. Manual selection ____________________________________________
if (AEAGlistname == "" & INRAElistname == "") {
if (DOCXlistname == "" & TXTlistname == "") {
# 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
df_data_AEAG = extract_data(computer_data_path, filedir, filename)
df_data_DOCX = extract_data(computer_data_path, filedir, filename)
}
### 2.4. Data join ___________________________________________________
df_join = join_selection(df_data_AEAG, df_data_INRAE,
df_meta_AEAG, df_meta_INRAE)
df_join = join_selection(df_data_DOCX, df_data_TXT,
df_meta_DOCX, df_meta_TXT)
df_data = df_join$data
df_meta = df_join$meta
......@@ -310,68 +313,69 @@ df_meta = get_hydrograph(df_data, df_meta, period=mean_period[[1]])$meta
df_sqrt = compute_sqrt(df_data)
### 3.2. Trend analysis ______________________________________________
# if ('analyse' %in% which_layout) {
# # QA trend
# res = get_QAtrend(df_data, df_meta,
# period=trend_period,
# alpha=alpha,
# dayLac_lim=dayLac_lim,
# yearNA_lim=yearNA_lim,
# df_flag=df_flag)
# df_QAdata = res$data
# df_QAmod = res$mod
# res_QAtrend = res$analyse
# # QMNA tend
# res = get_QMNAtrend(df_data, df_meta,
# period=trend_period,
# alpha=alpha,
# sampleSpan=sampleSpan,
# dayLac_lim=dayLac_lim,
# yearNA_lim=yearNA_lim,
# df_flag=df_flag)
# df_QMNAdata = res$data
# df_QMNAmod = res$mod
# res_QMNAtrend = res$analyse
# # VCN10 trend
# res = get_VCN10trend(df_data, df_meta,
# period=trend_period,
# alpha=alpha,
# sampleSpan=sampleSpan,
# dayLac_lim=dayLac_lim,
# yearNA_lim=yearNA_lim,
# df_flag=df_flag)
# df_VCN10data = res$data
# df_VCN10mod = res$mod
# res_VCN10trend = res$analyse
# # Start date for low water trend
# res = get_tDEBtrend(df_data, df_meta,
# period=trend_period,
# alpha=alpha,
# sampleSpan=sampleSpan,
# thresold_type='VCN10',
# select_longest=TRUE,
# dayLac_lim=dayLac_lim,
# yearNA_lim=yearNA_lim,
# df_flag=df_flag)
# df_tDEBdata = res$data
# df_tDEBmod = res$mod
# res_tDEBtrend = res$analyse
# # Center date for low water trend
# res = get_tCENtrend(df_data, df_meta,
# period=trend_period,
# alpha=alpha,
# sampleSpan=sampleSpan,
# dayLac_lim=dayLac_lim,
# yearNA_lim=yearNA_lim,
# df_flag=df_flag)
# df_tCENdata = res$data
# df_tCENmod = res$mod
# res_tCENtrend = res$analyse
# }
if ('analyse' %in% which_layout) {
# QA trend
res = get_QAtrend(df_data, df_meta,
period=trend_period,
per.start='09-01',
alpha=alpha,
dayLac_lim=dayLac_lim,
yearNA_lim=yearNA_lim,
df_flag=df_flag)
df_QAdata = res$data
df_QAmod = res$mod
res_QAtrend = res$analyse
# QMNA tend
res = get_QMNAtrend(df_data, df_meta,
period=trend_period,
alpha=alpha,
sampleSpan=sampleSpan,
dayLac_lim=dayLac_lim,
yearNA_lim=yearNA_lim,
df_flag=df_flag)
df_QMNAdata = res$data
df_QMNAmod = res$mod
res_QMNAtrend = res$analyse
# VCN10 trend
res = get_VCN10trend(df_data, df_meta,
period=trend_period,
alpha=alpha,
sampleSpan=sampleSpan,
dayLac_lim=dayLac_lim,
yearNA_lim=yearNA_lim,
df_flag=df_flag)
df_VCN10data = res$data
df_VCN10mod = res$mod
res_VCN10trend = res$analyse
# Start date for low water trend
res = get_tDEBtrend(df_data, df_meta,
period=trend_period,
alpha=alpha,
sampleSpan=sampleSpan,
thresold_type='VCN10',
select_longest=TRUE,
dayLac_lim=dayLac_lim,
yearNA_lim=yearNA_lim,
df_flag=df_flag)
df_tDEBdata = res$data
df_tDEBmod = res$mod
res_tDEBtrend = res$analyse
# Center date for low water trend
res = get_tCENtrend(df_data, df_meta,
period=trend_period,
alpha=alpha,
sampleSpan=sampleSpan,
dayLac_lim=dayLac_lim,
yearNA_lim=yearNA_lim,
df_flag=df_flag)
df_tCENdata = res$data
df_tCENmod = res$mod
res_tCENtrend = res$analyse
}
### 3.3. Break analysis ______________________________________________
# 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