Commit c09c4020 authored by Heraut Louis's avatar Heraut Louis
Browse files

New multipage plot and bh selection only

parent 0becaf7f
No related merge requests found
Showing with 56 additions and 56 deletions
+56 -56
# Usefull library # Usefull library
library(ggplot2) library(ggplot2)
library(gridExtra)
width = 30 width = 30
height = 14 height = 14
dpi = 100 dpi = 100
# Time panel # Time panel
panel = function (df_data, df_info, figdir, filedir, span=Inf) { panel = function (df_data, df_info, figdir, filedir, is_sqrt=FALSE) {
outfile = "Panels"
if (is_sqrt) {
df_data[, 'Qm3s'] = apply(df_data[, 'Qm3s'], 1, sqrt)
outfile = paste(outfile, '_sqrt', sep='')
}
outfile = paste(outfile, '.pdf', sep='')
# If there is not a dedicated figure directory it creats one # If there is not a dedicated figure directory it creats one
# outdir = file.path(figdir, filedir, paste('span_', as.character(span), '_years', sep=''))
outdir = file.path(figdir, filedir, sep='') outdir = file.path(figdir, filedir, sep='')
if (!(file.exists(outdir))) { if (!(file.exists(outdir))) {
dir.create(outdir) dir.create(outdir)
...@@ -18,28 +27,32 @@ panel = function (df_data, df_info, figdir, filedir, span=Inf) { ...@@ -18,28 +27,32 @@ panel = function (df_data, df_info, figdir, filedir, span=Inf) {
# Get all different stations code # Get all different stations code
Code = levels(factor(df_info$code)) Code = levels(factor(df_info$code))
# Create a blank list in order to store plots
plots = list()
for (code in Code) { for (code in Code) {
# Create name for the figure file # Print code of the station for the current plotting
outfile = paste('Panel_', code, '.pdf', sep='')
print(paste("Plotting for sation :", code)) print(paste("Plotting for sation :", code))
df_data_code = df_data[df_data$code==code,] df_data_code = df_data[df_data$code==code,]
# Plot # Plot
plot = p = ggplot(df_data_code, aes(x=Date, y=Qm3s)) +
ggplot(df_data_code, aes(x=Date, y=Qls)) +
geom_line() geom_line()
# Store
plots = append(plots, list(p))
# Save the plot
ggsave(path=outdir,
filename=outfile,
plot=plot,
width=width,
height=height,
dpi=dpi,
units='cm')
} }
# Saving
ggsave(path=outdir,
filename=outfile,
plot=marrangeGrob(plots, nrow=1, ncol=1),
width=29.7, height=21, units='cm', dpi=100
)
} }
......
...@@ -57,24 +57,6 @@ get_selection = function (computer_data_path, listdir, listname, ...@@ -57,24 +57,6 @@ get_selection = function (computer_data_path, listdir, listname,
# Get the file path to the data # Get the file path to the data
list_path = file.path(computer_data_path, listdir, listname) list_path = file.path(computer_data_path, listdir, listname)
# Extract the data as a data frame
# df_list = read.table(list_path,
# header=TRUE,
# sep=';',
# dec=',',
# quote='',
# skip=0,
# nrows=3,
# strip.white=TRUE,
# comment.char="",
# colClasses=c("character",
# "character",
# "numeric",
# "character",
# "numeric",
# "character",
# "character"))
sample_data = read_docx(list_path) sample_data = read_docx(list_path)
content = docx_summary(sample_data) content = docx_summary(sample_data)
table_cells <- content %>% filter(content_type == "table cell") table_cells <- content %>% filter(content_type == "table cell")
...@@ -285,7 +267,7 @@ extract_data = function (computer_data_path, filedir, filename, verbose=TRUE) { ...@@ -285,7 +267,7 @@ extract_data = function (computer_data_path, filedir, filename, verbose=TRUE) {
header=TRUE, header=TRUE,
na.strings=c(' -99', ' -99.000'), na.strings=c(' -99', ' -99.000'),
sep=';', sep=';',
skip=41)[,1:2] skip=41)
# Extract all the information for the station # Extract all the information for the station
df_info = extract_info(computer_data_path, filedir, filename, verbose=FALSE) df_info = extract_info(computer_data_path, filedir, filename, verbose=FALSE)
...@@ -294,7 +276,8 @@ extract_data = function (computer_data_path, filedir, filename, verbose=TRUE) { ...@@ -294,7 +276,8 @@ extract_data = function (computer_data_path, filedir, filename, verbose=TRUE) {
# Create a tibble with the date as Date class and the code of the station # Create a tibble with the date as Date class and the code of the station
df_data = tibble(Date=as.Date(as.character(df_data$Date), df_data = tibble(Date=as.Date(as.character(df_data$Date),
format="%Y%m%d"), format="%Y%m%d"),
df_data[-1], Qm3s=df_data$Qls * 1E-3,
df_data[-1:-2],
code=code) code=code)
return (df_data) return (df_data)
......
### A MODIFIER ### ###### A MODIFIER ######
# Path to the data # Path to the data
computer_data_path = computer_data_path =
...@@ -11,32 +11,35 @@ computer_work_path = ...@@ -11,32 +11,35 @@ computer_work_path =
"/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/ASH" "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/ASH"
# "C:\\Users\\louis.heraut\\Documents\\CDD_stationnarite\\ASH" # "C:\\Users\\louis.heraut\\Documents\\CDD_stationnarite\\ASH"
# Manual selection ### BANQUE HYDRO ###
# Path to data that will be analysed ## Manual selection ##
filedir = # Path to data that will be analysed from the BanqueHydro
BHfiledir =
FALSE FALSE
# "test" # "test"
# "BanqueHydro_Export2021" # "BanqueHydro_Export2021"
filename = BHfilename =
FALSE FALSE
# c("H5920011_HYDRO_QJM.txt", "K4470010_HYDRO_QJM.txt") # c("H5920011_HYDRO_QJM.txt", "K4470010_HYDRO_QJM.txt")
# "all" # "all"
# Or list selection ## Or list selection ##
# Path to the list file of station that will be analysed # Path to the list file of station that will be analysed
listdir = BHlistdir =
# FALSE # FALSE
"" ""
listname = BHlistname =
"Liste-station_RRSE.docx"
# FALSE # FALSE
BHdir = "Liste-station_RRSE.docx"
"BanqueHydro_Export2021" BHdatadir =
# FALSE # FALSE
"BanqueHydro_Export2021"
# selecdir = "RRSE_selection" ### NIVALE ###
################## ########################
# Set working directory # Set working directory
...@@ -66,10 +69,10 @@ print(paste('figdir :', figdir)) ...@@ -66,10 +69,10 @@ print(paste('figdir :', figdir))
# Get only the selected station from a list station file # Get only the selected station from a list station file
if (is.character(listdir) & is.character(listname) & is.character(BHdir)){ if (is.character(BHlistdir) & is.character(BHlistname) & is.character(BHdatadir)){
df_selec = get_selection(computer_data_path, df_selec = get_selection(computer_data_path,
listdir, BHlistdir,
listname, BHlistname,
cnames=c('code', cnames=c('code',
'station', 'station',
'BV_km2', 'BV_km2',
...@@ -79,18 +82,19 @@ if (is.character(listdir) & is.character(listname) & is.character(BHdir)){ ...@@ -79,18 +82,19 @@ if (is.character(listdir) & is.character(listname) & is.character(BHdir)){
'choix'), 'choix'),
cisnum=c('BV_km2', cisnum=c('BV_km2',
'longueur_serie')) 'longueur_serie'))
filedir = BHdir BHfiledir = BHdatadir
filename = df_selec$filename BHfilename = df_selec$filename
} }
# Extract information about selected stations # Extract information about selected stations
df_info = extract_info(computer_data_path, filedir, filename) df_info = extract_info(computer_data_path, BHfiledir, BHfilename)
# Extract data about selected stations # Extract data about selected stations
df_data = extract_data(computer_data_path, filedir, filename) df_data = extract_data(computer_data_path, BHfiledir, BHfilename)
# Plot time panel of debit by stations # Plot time panel of debit by stations
panel(df_data, df_info, figdir, filedir) panel(df_data, df_info, figdir, BHfiledir)
# panel(df_data, df_info, figdir, BHfiledir, is_sqrt=TRUE)
# Compute gap parameters for stations # Compute gap parameters for stations
df_lac = get_lacune(df_data, df_info) df_lac = get_lacune(df_data, df_info)
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