Newer
Older
#
# *1 INRAE, France
# louis.heraut@inrae.fr
#
# This file is part of ash R toolbox.
#
# ash R toolbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# ash R toolbox is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ash R toolbox. If not, see <https://www.gnu.org/licenses/>.
# ///
#
#
# script.R
#
# Script file to manage the trend analysis of the Adour-Garonne basin.
# Performs the necessary calls to processing and plotting functions in
# order to realise the hydrologic trend analysis of stations according
# to the input parameters. The nearest area belove is where you need to
# write your prefer parameters for the analysis. See the 'README.txt'
# file for more information.
############## START OF REGION TO MODIFY (without risk) ##############
computer_data_path =
"/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data"
# "C:\\Users\\louis.heraut\\Documents\\CDD_stationnarite\\data"
# Work path (it needs to end with '/ASH' directory)
computer_work_path =
"/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/ASH"
# "C:\\Users\\louis.heraut\\Documents\\CDD_stationnarite\\ASH"
## BANQUE HYDRO
# Path to the directory where Banque Hydro (BH) data is stored
# from the work path
filedir =
# ""
"BanqueHydro_Export2021"
## MANUAL SELECTION
# Name of the file that will be analysed from the BH directory
# (if 'all', all the file of the directory will be chosen)
# "P1712910_HYDRO_QJM.txt",
# "P0885010_HYDRO_QJM.txt",
# "O5055010_HYDRO_QJM.txt",
# "O0554010_HYDRO_QJM.txt",
# "O1584610_HYDRO_QJM.txt"
## 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
## NIVALE SELECTION
# Path to the 'txt' list file of station from INRAE that will be analysed
INlistdir =
periodAll = c("1800-01-01", "2020-12-31")
periodSub = c("1968-01-01", "2020-12-31")
trend_period = list(periodAll, periodSub)
# Time period to mean
period1 = c("1968-01-01", "1988-12-31")
period2 = c("2000-01-01", "2020-12-31")
# Sampling span of the data
sampleSpan = c('05-01', '11-30')
## MAP
# Path to the shapefile for france contour from 'computer_data_path'
# Path to the shapefile for basin shape from 'computer_data_path'
bs_shpdir = 'map/bassin'
bs_shpname = 'BassinHydrographique.shp'
# Path to the shapefile for sub-basin shape from 'computer_data_path'
sbs_shpdir = 'map/sous_bassin'
sbs_shpname = 'SousBassinHydrographique.shp'
# Path to the shapefile for river shape from 'computer_data_path'
############### END OF REGION TO MODIFY (without risk) ###############
# Set working directory
setwd(computer_work_path)
# Sourcing R file
source('processing/extract.R', encoding='UTF-8')
source('processing/format.R', encoding='UTF-8')
source('processing/analyse.R', encoding='UTF-8')
source('plotting/layout.R', encoding='UTF-8')
# Result directory
resdir = file.path(computer_work_path, 'results')
if (!(file.exists(resdir))) {
dir.create(resdir)
}
print(paste('resdir :', resdir))
# Figure directory
figdir = file.path(computer_work_path, 'figures')
if (!(file.exists(figdir))) {
dir.create(figdir)
}
# Resources directory
resources_path = file.path(computer_work_path, 'resources')
if (!(file.exists(resources_path))) {
dir.create(resources_path)
# Logo filename
AEAGlogo_file = 'agence-de-leau-adour-garonne_logo.png'
INRAElogo_file = 'Logo-INRAE_Transparent.png'
FRlogo_file = 'Republique_Francaise_RVB.png'
# Initialization of null data frame if there is no data selected
if (AGlistname != ""){
# Get only the selected station from a list station file
df_selec_AG = get_selection_AG(computer_data_path,
AGlistdir,
AGlistname,
cnames=c('code',
'station',
'BV_km2',
'axe_principal_concerne',
'longueur_serie',
'commentaires',
'choix'),
# Extract metadata about selected stations
df_meta_AG = extract_meta(computer_data_path, filedir, filename)
# Extract data about selected stations
df_data_AG = extract_data(computer_data_path, filedir, filename)
# Get only the selected station from a list station file
df_selec_IN = get_selection_IN(computer_data_path,
INlistdir,
INlistname)
# Extract metadata about selected stations
df_meta_IN = extract_meta(computer_data_path, filedir, filename)
# Extract data about selected stations
df_data_IN = extract_data(computer_data_path, filedir, filename)
### 2.3. Manual selection
if (AGlistname == "" & INlistname == "") {
# Extract metadata about selected stations
df_meta_AG = extract_meta(computer_data_path, filedir, filename)
# Extract data about selected stations
df_data_AG = extract_data(computer_data_path, filedir, filename)
}
### 2.4. Data join
df_join = join(df_data_AG, df_data_IN, df_meta_AG, df_meta_IN)
### 3.1. Compute other parameters for stations
# Time gap
# Hydrograph
df_meta = get_hydrograph(df_data, df_meta, period=mean_period[[1]])$meta
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# # 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)
# df_break = get_break(res_QAtrend$data, df_meta)
# df_break = get_break(res_QMNAtrend$data, df_meta)
# df_break = get_break(res_VCN10trend$data, df_meta)
# cumulative(df_break$Date, df_meta, dyear=8,
# figdir=figdir)
## 4. PLOTTING
# Shapefile importation in order to it only once time
df_shapefile = ini_shapefile(computer_data_path,
fr_shpdir, fr_shpname,
bs_shpdir, bs_shpname,
sbs_shpdir, sbs_shpname,
# Plot time panel of debit by stations
# datasheet_layout(list(df_data, df_data),
# layout_matrix=c(1, 2),
# df_meta=df_meta,
# missRect=list(TRUE, TRUE),
# info_header=TRUE,
# time_header=NULL,
# var_ratio=3,
# figdir=figdir,
# filename_opt='time')
res_DEBtrend$data,
res_CENtrend$data),
df_trend=list(res_QAtrend$trend,
res_QMNAtrend$trend,
res_DEBtrend$trend,
res_CENtrend$trend),
type=list('sévérité',
'sévérité',
'sévérité',
'saisonnalité',
'saisonnalité'),
trend_period=trend_period,
mean_period=mean_period,
info_header=TRUE,
time_header=df_data,
AEAGlogo_file=AEAGlogo_file,
INRAElogo_file=INRAElogo_file,
FRlogo_file=FRlogo_file)