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)
# "S2235610_HYDRO_QJM.txt",
# "P1712910_HYDRO_QJM.txt",
# "P0885010_HYDRO_QJM.txt",
# "O5055010_HYDRO_QJM.txt",
# "O0384010_HYDRO_QJM.txt",
# "S4214010_HYDRO_QJM.txt",
"Q0214010_HYDRO_QJM.txt"
# "O3035210_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
""
# "Liste-station_RRSE.docx"
## NIVALE SELECTION
# Path to the 'txt' list file of station from INRAE that will be analysed
# Generated with :
# create_selection(computer_data_path, 'dirname', 'example.txt')
INRAElistdir =
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")
# Number of missing days per year before remove the year
yearLac_day = 3
# Sampling span of the data
sampleSpan = c('05-01', '11-30')
############### END OF REGION TO MODIFY (without risk) ###############
## 1. FILE STRUCTURE _________________________________________________
# 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)
AEAGlogo_file = 'agence-de-leau-adour-garonne_logo.png'
INRAElogo_file = 'Logo-INRAE_Transparent.png'
FRlogo_file = 'Republique_Francaise_RVB.png'
# Path to the shapefile for france contour from 'computer_data_path'
fr_shpdir = 'map/france'
fr_shpname = 'gadm36_FRA_0.shp'
# 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'
rv_shpdir = 'map/river'
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
### 2.1. Selection of the Agence de l'eau Adour-Garonne ______________
if (AEAGlistname != "") {
# Get only the selected station from a list station file
df_selec_AEAG = get_selection_AEAG(computer_data_path,
AEAGlistdir,
AEAGlistname,
cnames=c('code',
'station',
'BV_km2',
'axe_principal_concerne',
'longueur_serie',
'commentaires',
'choix'),
# Extract metadata about selected stations
df_meta_AEAG = extract_meta(computer_data_path, filedir, filename)
# Extract data about selected stations
df_data_AEAG = extract_data(computer_data_path, filedir, filename)
### 2.2. INRAE selection _____________________________________________
# Get only the selected station from a list station file
df_selec_INRAE = get_selection_INRAE(computer_data_path,
INRAElistdir,
INRAElistname)
filename = df_selec_INRAE[df_selec_INRAE$ok,]$filename
# Extract metadata about selected stations
df_meta_INRAE = extract_meta(computer_data_path, filedir, filename)
# Extract data about selected stations
df_data_INRAE = extract_data(computer_data_path, filedir, filename)
### 2.3. Manual selection ____________________________________________
# Extract metadata about selected stations
df_meta_AEAG = extract_meta(computer_data_path, filedir, filename)
# Extract data about selected stations
df_data_AEAG = 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)
## 3. ANALYSE ________________________________________________________
var = list(
'QA',
'QMNA',
'VCN10',
'tDEB',
'tCEN'
)
type = list(
'sévérité',
'sévérité',
'sévérité',
'saisonnalité',
'saisonnalité'
)
glose = list(
"Moyenne annuelle du débit journalier",
"Minimum annuel de la moyenne mensuelle du débit journalier",
"Minimum annuel de la moyenne sur 10 jours du débit journalier",
"Début d'étiage (jour de l'année de la première moyenne sur 10 jours sous le maximum des VCN10)",
"Centre d'étiage (jour de l'année du VCN10)"
)
### 3.1. Compute other parameters for stations _______________________
# Hydrograph
df_meta = get_hydrograph(df_data, df_meta, period=mean_period[[1]])$meta
### 3.2. Trend analysis ______________________________________________
res = get_QAtrend(df_data, df_meta,
period=trend_period,
alpha=alpha,
yearLac_day=yearLac_day)
df_QAdata = res$data
df_QAmod = res$mod
res_QAtrend = res$analyse
res = get_QMNAtrend(df_data, df_meta,
period=trend_period,
alpha=alpha,
sampleSpan=sampleSpan,
yearLac_day=yearLac_day)
df_QMNAdata = res$data
df_QMNAmod = res$mod
res_QMNAtrend = res$analyse
res = get_VCN10trend(df_data, df_meta,
period=trend_period,
alpha=alpha,
sampleSpan=sampleSpan,
yearLac_day=yearLac_day)
df_VCN10data = res$data
df_VCN10mod = res$mod
res_VCN10trend = res$analyse
res = get_tDEBtrend(df_data, df_meta,
period=trend_period,
alpha=alpha,
sampleSpan=sampleSpan,
thresold_type='VCN10',
select_longest=TRUE,
yearLac_day=yearLac_day)
df_tDEBdata = res$data
df_tDEBmod = res$mod
res_tDEBtrend = res$analyse
res = get_tCENtrend(df_data, df_meta,
period=trend_period,
alpha=alpha,
sampleSpan=sampleSpan,
yearLac_day=yearLac_day)
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)
# 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,
## 4. SAVING _________________________________________________________
# for (v in var) {
# df_datatmp = get(paste('df_', v, 'data', sep=''))
# df_modtmp = get(paste('df_', v, 'mod', sep=''))
# res_trendtmp = get(paste('res_', v, 'trend', sep=''))
# # Modified data saving
# write_dfdata(df_datatmp, df_modtmp, resdir, optdir='modified_data',
# filedir=v)
# # Trend analysis saving
# write_listofdf(res_trendtmp, resdir, optdir='trend_analyse',
# filedir=v)
# }
# res_tDEBtrend = read_listofdf(resdir, 'res_tDEBtrend')
## 5. PLOTTING _______________________________________________________
df_shapefile = ini_shapefile(resources_path,
fr_shpdir, fr_shpname,
bs_shpdir, bs_shpname,
sbs_shpdir, sbs_shpname,
### 5.1. Simple time panel to criticize station data _________________
# 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')
### 5.2. Analysis layout _____________________________________________
res_QAtrend$data,
res_QMNAtrend$data,
res_VCN10trend$data,
res_tDEBtrend$data,
res_QAtrend$trend,
res_QMNAtrend$trend,
res_VCN10trend$trend,
res_tDEBtrend$trend,
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)