Commit 69ee04e6 authored by Heraut Louis's avatar Heraut Louis
Browse files

New map of delta

parent 7729e1d6
No related merge requests found
Showing with 854 additions and 614 deletions
+854 -614
......@@ -147,7 +147,7 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, info_header, ti
df_trend = list_df2plot[[i]]$trend
# Extracts the type of the variable
type = list_df2plot[[i]]$type
p_threshold = list_df2plot[[i]]$p_threshold
alpha = list_df2plot[[i]]$alpha
# Extracts the data corresponding to the code
df_data_code = df_data[df_data$code == code,]
df_trend_code = df_trend[df_trend$code == code,]
......@@ -187,7 +187,7 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, info_header, ti
}
# If the p value is under the threshold
if (df_trend_code_per$p <= p_threshold) {
if (df_trend_code_per$p <= alpha) {
# Stores the mean trend
TrendValue_code[j, i, k] = trendValue
# Otherwise
......@@ -338,7 +338,7 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, info_header, ti
# Extracts the trend corresponding to the
# current variable
df_trend = list_df2plot[[i]]$trend
p_threshold = list_df2plot[[i]]$p_threshold
alpha = list_df2plot[[i]]$alpha
unit2day = list_df2plot[[i]]$unit2day
missRect = list_df2plot[[i]]$missRect
# Extract the variable of the plot
......@@ -359,7 +359,7 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, info_header, ti
for (j in 1:nPeriod_max) {
# If the trend is significant
if (df_trend_code$p[j] <= p_threshold){
if (df_trend_code$p[j] <= alpha){
# Gets the associated time info
Start = tab_Start[k, i, j]
End = tab_End[k, i, j]
......@@ -421,7 +421,7 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, info_header, ti
# Computes the time panel associated to the current variable
p = time_panel(df_data_code, df_trend_code, var=var,
type=type, p_threshold=p_threshold,
type=type, alpha=alpha,
missRect=missRect, trend_period=trend_period,
mean_period=mean_period, axis_xlim=axis_xlim,
unit2day=unit2day, grid=FALSE, color=color,
......@@ -522,7 +522,7 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, info_header, ti
## 2. OTHER PANEL FOR THE DATASHEET
### 2.1. Time panel
time_panel = function (df_data_code, df_trend_code, var, type, p_threshold=0.1, missRect=FALSE, unit2day=365.25, trend_period=NULL, mean_period=NULL, axis_xlim=NULL, grid=TRUE, ymin_lim=NULL, color=NULL, NspaceMax=NULL, first=FALSE, last=FALSE, lim_pct=10) {
time_panel = function (df_data_code, df_trend_code, var, type, alpha=0.1, missRect=FALSE, unit2day=365.25, trend_period=NULL, mean_period=NULL, axis_xlim=NULL, grid=TRUE, ymin_lim=NULL, color=NULL, NspaceMax=NULL, first=FALSE, last=FALSE, lim_pct=10) {
# If 'type' is square root apply it to data
if (var == 'sqrt(Q)') {
......
......@@ -137,7 +137,7 @@ datasheet_layout = function (df_data, df_meta, layout_matrix,
toplot=c('datasheet', 'matrix', 'map'),
figdir='', filedir_opt='', filename_opt='',
variable='', df_trend=NULL,
p_threshold=0.1, unit2day=365.25, var='',
alpha=0.1, unit2day=365.25, var='',
type='', trend_period=NULL,
mean_period=NULL, axis_xlim=NULL,
missRect=FALSE, time_header=NULL,
......@@ -192,13 +192,13 @@ datasheet_layout = function (df_data, df_meta, layout_matrix,
df_trend = replicate(nbp, df_trend)
}}
if (all(class(p_threshold) != 'list')) {
p_threshold = list(p_threshold)
if (all(class(alpha) != 'list')) {
alpha = list(alpha)
# If there is only one value
if (length(p_threshold) == 1) {
if (length(alpha) == 1) {
# Replicates the value the number of times that there
# is of studied variables
p_threshold = replicate(nbp, p_threshold)
alpha = replicate(nbp, alpha)
}}
# Same
......@@ -234,7 +234,7 @@ datasheet_layout = function (df_data, df_meta, layout_matrix,
# Creates a list that gather all the info for one type of graph
df2plot = list(data=df_data[[i]],
trend=df_trend[[i]],
p_threshold=p_threshold[[i]],
alpha=alpha[[i]],
unit2day=unit2day[[i]],
var=var[[i]], type=type[[i]],
missRect=missRect[[i]])
......@@ -252,14 +252,16 @@ datasheet_layout = function (df_data, df_meta, layout_matrix,
# If summarize matrix needs to be plot
if ('matrix' %in% toplot) {
matrix_panel(list_df2plot, df_meta, trend_period, mean_period,
slice=12, outdirTmp=outdirTmp, A3=TRUE)
slice=19, outdirTmp=outdirTmp, A3=TRUE,
foot_note=foot_note, foot_height=foot_height, resources_path=resources_path, AEAGlogo_file=AEAGlogo_file, INRAElogo_file=INRAElogo_file, FRlogo_file=FRlogo_file,)
}
# If map needs to be plot
if ('map' %in% toplot) {
map_panel(list_df2plot,
df_meta,
idPer=length(trend_period),
idPer_trend=length(trend_period),
mean_period=mean_period,
df_shapefile=df_shapefile,
foot_note=foot_note,
foot_height=foot_height,
......
This diff is collapsed.
......@@ -28,7 +28,11 @@
## 1. MATRIX PANEL
# Generates a summarizing matrix of the trend analyses of all station for different hydrological variables and periods. Also shows difference of means between specific periods.
matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice=NULL, outdirTmp='', outnameTmp='matrix', title=NULL, A3=FALSE) {
matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice=NULL, outdirTmp='', outnameTmp='matrix', title=NULL, A3=FALSE,
foot_note=FALSE,
foot_height=0, resources_path=NULL,
AEAGlogo_file=NULL, INRAElogo_file=NULL,
FRlogo_file=NULL) {
# Number of variable/plot
nbp = length(list_df2plot)
......@@ -140,7 +144,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
df_trend = list_df2plot[[i]]$trend
# Extracts the type of the variable
type = list_df2plot[[i]]$type
p_threshold = list_df2plot[[i]]$p_threshold
alpha = list_df2plot[[i]]$alpha
# Extracts the data corresponding to the code
df_data_code = df_data[df_data$code == code,]
# Extracts the trend corresponding to the code
......@@ -181,7 +185,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
}
# If the p value is under the threshold
if (df_trend_code_per$p <= p_threshold){
if (df_trend_code_per$p <= alpha){
# Stores the averaged trend
TrendValue_code[j, i, k] = trendValue
# Otherwise
......@@ -221,7 +225,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
# Extracts the trend corresponding to the
# current variable
df_trend = list_df2plot[[i]]$trend
p_threshold = list_df2plot[[i]]$p_threshold
alpha = list_df2plot[[i]]$alpha
# Extract the variable of the plot
var = list_df2plot[[i]]$var
# Extract the type of the variable to plot
......@@ -267,7 +271,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
}
# If the p value is under the threshold
if (df_trend_code_per$p <= p_threshold){
if (df_trend_code_per$p <= alpha){
# Gets the color associated to the averaged trend
color_res = get_color(trendValue,
minTrendValue[j, i],
......@@ -406,7 +410,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
minBreakValue = apply(breakValue_code, c(1, 2),
min, na.rm=TRUE)
maxBreakValue = apply(breakValue_code, c(1, 2),
max, na.rm=TRUE)
max, na.rm=TRUE)
# Blanks vector to store color info
Fill_mean = c()
Color_mean = c()
......@@ -446,8 +451,17 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
slice = nCode
}
allType = c()
for (i in 1:nbp) {
allType = c(allType, list_df2plot[[i]]$type)
}
countType = rle(sort(allType))
df_countType = tibble(type=countType$values, n=countType$lengths)
nbpMax = max(df_countType$n)
# Gets all the different type of plots
Type = levels(factor(Type_trend))
Type = levels(factor(allType))
nbType = length(Type)
# For all the type of plots
for (itype in 1:nbType) {
......@@ -471,12 +485,15 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
nMat = as.integer(nsubCodefL/slice) + 1
# For all the pages
for (iMat in 1:nMat) {
n_page = ifL + nfL*(itype-1)
N_page = nfL*2
# Print the matrix name
print(paste('Matrix ', iMat, '/', nMat,
' of ', type,
' for region : ', fL,
" (",
round((ifL + nfL*(itype-1)) / (nfL*2) * 100,
round(n_page / N_page * 100,
0),
" %)",
sep=''))
......@@ -529,7 +546,10 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
# Fixes the height and width of the table according to
# the number of station and the number of column to draw
height = nsubCode
width = nbpMod * 2 * nPeriod_trend + nPeriod_trend + nPeriod_mean * nbpMod + nPeriod_mean + nbpMod
# width = nbpMod * 2 * nPeriod_trend + nPeriod_trend + nPeriod_mean * nbpMod + nPeriod_mean + nbpMod
width = nbpMax * 2 * nPeriod_trend + nPeriod_trend + nPeriod_mean * nbpMax + nPeriod_mean + nbpMax
# Fixes the size of the plot area to keep proportion right
options(repr.plot.width=width, repr.plot.height=height)
......@@ -544,7 +564,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
axis.ticks.y=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
plot.margin=margin(t=5, r=5, b=5, l=5, unit="mm")
plot.margin=margin(t=0, r=0, b=0, l=0, unit="mm")
)
# Extracts the name of the currently hydrological
......@@ -1093,8 +1113,59 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice
dpi = 100
}
# If there is a foot note
if (foot_note) {
foot = foot_panel('tableau récapitulatif',
n_page, N_page,
resources_path,
AEAGlogo_file, INRAElogo_file,
FRlogo_file, foot_height)
# Stores the map, the title and the colorbar in a list
P = list(mat, foot)
LM = matrix(c(1,
2),
nrow=2, byrow=TRUE)
} else {
foot_height = 0
# Stores the map, the title and the colorbar in a list
P = list(mat)
LM = matrix(c(1),
nrow=1, byrow=TRUE)
}
id_foot = 2
LMcol = ncol(LM)
LMrow = nrow(LM)
LM = rbind(rep(99, times=LMcol),
LM, rep(99, times=LMcol))
LMrow = nrow(LM)
LM = cbind(rep(99, times=LMrow),
LM, rep(99, times=LMrow))
LMcol = ncol(LM)
margin_height = 0.5
row_height = (height - 2*margin_height - foot_height) / (LMrow - 3)
Hcut = LM[, 2]
heightLM = rep(row_height, times=LMrow)
heightLM[Hcut == id_foot] = foot_height
heightLM[Hcut == 99] = margin_height
col_width = (width - 2*margin_height) / (LMcol - 2)
Wcut = LM[(nrow(LM)-1),]
widthLM = rep(col_width, times=LMcol)
widthLM[Wcut == 99] = margin_height
# Arranges the graphical object
plot = grid.arrange(grobs=P, layout_matrix=LM,
heights=heightLM, widths=widthLM)
# Saving
ggsave(plot=mat,
ggsave(plot=plot,
path=outdirTmp,
filename=paste(outnameTmp,
'_', type,
......
......@@ -55,20 +55,19 @@ filedir =
# Name of the file that will be analysed from the BH directory
# (if 'all', all the file of the directory will be chosen)
filename =
# ""
c(
""
# c(
# "S2235610_HYDRO_QJM.txt",
# "P1712910_HYDRO_QJM.txt",
# "P0885010_HYDRO_QJM.txt",
# "O5055010_HYDRO_QJM.txt",
# "O0384010_HYDRO_QJM.txt",
# "S4214010_HYDRO_QJM.txt",
"Q7002910_HYDRO_QJM.txt"
# "Q7002910_HYDRO_QJM.txt"
# "O3035210_HYDRO_QJM.txt"
# "O0554010_HYDRO_QJM.txt",
# "O1584610_HYDRO_QJM.txt"
)
# )
## AGENCE EAU ADOUR GARONNE SELECTION
......@@ -78,8 +77,8 @@ AGlistdir =
""
AGlistname =
""
# "Liste-station_RRSE.docx"
# ""
"Liste-station_RRSE.docx"
## NIVALE SELECTION
......@@ -103,8 +102,8 @@ period1 = c("1968-01-01", "1988-12-31")
period2 = c("2000-01-01", "2020-12-31")
mean_period = list(period1, period2)
# p value thresold
p_thresold = 0.1
# alpha the risk
alpha = 0.1
# Sampling span of the data
sampleSpan = c('05-01', '11-30')
......@@ -192,8 +191,7 @@ if (AGlistname != ""){
'longueur_serie'))
# Get filenames of the selection
filename = df_selec_AG[df_selec_AG$ok,]$filename
filename = df_selec_AG[df_selec_AG$ok,]$filename
# Extract metadata about selected stations
df_meta_AG = extract_meta(computer_data_path, filedir, filename)
# Extract data about selected stations
......@@ -210,7 +208,6 @@ if (INlistname != ""){
# Get filenames of the selection
filename = df_selec_IN[df_selec_IN$ok,]$filename
# Extract metadata about selected stations
df_meta_IN = extract_meta(computer_data_path, filedir, filename)
# Extract data about selected stations
......@@ -239,37 +236,37 @@ df_meta = get_lacune(df_data, df_meta)
df_meta = get_hydrograph(df_data, df_meta, period=mean_period[[1]])$meta
### 3.2. Trend analysis
# QA trend
res_QAtrend = get_QAtrend(df_data, df_meta,
period=trend_period,
p_thresold=p_thresold)
# QMNA tend
res_QMNAtrend = get_QMNAtrend(df_data, df_meta,
period=trend_period,
p_thresold=p_thresold,
sampleSpan=sampleSpan)
# VCN10 trend
res_VCN10trend = get_VCN10trend(df_data, df_meta,
period=trend_period,
p_thresold=p_thresold,
sampleSpan=sampleSpan)
# Start date for low water trend
res_DEBtrend = get_DEBtrend(df_data, df_meta,
period=trend_period,
p_thresold=p_thresold,
sampleSpan=sampleSpan,
thresold_type='VCN10',
select_longest=TRUE)
# res_DEBtrend = read_listofdf(resdir, 'res_DEBtrend')
# Center date for low water trend
res_CENtrend = get_CENtrend(df_data, df_meta,
period=trend_period,
p_thresold=p_thresold,
sampleSpan=sampleSpan)
# # QA trend
# res_QAtrend = get_QAtrend(df_data, df_meta,
# period=trend_period,
# alpha=alpha)
# # QMNA tend
# res_QMNAtrend = get_QMNAtrend(df_data, df_meta,
# period=trend_period,
# alpha=alpha,
# sampleSpan=sampleSpan)
# # VCN10 trend
# res_VCN10trend = get_VCN10trend(df_data, df_meta,
# period=trend_period,
# alpha=alpha,
# sampleSpan=sampleSpan)
# # Start date for low water trend
# res_DEBtrend = get_DEBtrend(df_data, df_meta,
# period=trend_period,
# alpha=alpha,
# sampleSpan=sampleSpan,
# thresold_type='VCN10',
# select_longest=TRUE)
# # res_DEBtrend = read_listofdf(resdir, 'res_DEBtrend')
# # Center date for low water trend
# res_CENtrend = get_CENtrend(df_data, df_meta,
# period=trend_period,
# alpha=alpha,
# sampleSpan=sampleSpan)
### 3.3. Break analysis
# df_break = get_break(res_QAtrend$data, df_meta)
......@@ -289,7 +286,7 @@ df_shapefile = ini_shapefile(computer_data_path,
fr_shpdir, fr_shpname,
bs_shpdir, bs_shpname,
sbs_shpdir, sbs_shpname,
rv_shpdir, rv_shpname, riv=FALSE)
rv_shpdir, rv_shpname, riv=TRUE)
### 4.1. Simple time panel to criticize station data
# Plot time panel of debit by stations
......@@ -307,7 +304,7 @@ df_shapefile = ini_shapefile(computer_data_path,
### 4.2. Analysis layout
datasheet_layout(toplot=c(
'datasheet',
# 'matrix',
'matrix',
'map'
),
df_meta=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