diff --git a/plotting/panel.R b/plotting/panel.R index 79a330b60550e03cf6e1518396aa80e03b87eca1..ba163204dbdc2e337b6aa46402188d5132f23941 100644 --- a/plotting/panel.R +++ b/plotting/panel.R @@ -1,15 +1,24 @@ # Usefull library library(ggplot2) +library(gridExtra) width = 30 height = 14 dpi = 100 # 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 - # outdir = file.path(figdir, filedir, paste('span_', as.character(span), '_years', sep='')) outdir = file.path(figdir, filedir, sep='') if (!(file.exists(outdir))) { dir.create(outdir) @@ -18,28 +27,32 @@ panel = function (df_data, df_info, figdir, filedir, span=Inf) { # Get all different stations code Code = levels(factor(df_info$code)) + # Create a blank list in order to store plots + plots = list() + for (code in Code) { - # Create name for the figure file - outfile = paste('Panel_', code, '.pdf', sep='') + # Print code of the station for the current plotting print(paste("Plotting for sation :", code)) df_data_code = df_data[df_data$code==code,] # Plot - plot = - ggplot(df_data_code, aes(x=Date, y=Qls)) + + p = ggplot(df_data_code, aes(x=Date, y=Qm3s)) + 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 + ) + + } diff --git a/processing/extract.R b/processing/extract.R index 4f7f383f2191aeaff1fb9621336a3020c337e120..a636b77fefda5196abc2a3a88ee58cd275689ec6 100644 --- a/processing/extract.R +++ b/processing/extract.R @@ -57,24 +57,6 @@ get_selection = function (computer_data_path, listdir, listname, # Get the file path to the data 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) content = docx_summary(sample_data) table_cells <- content %>% filter(content_type == "table cell") @@ -285,7 +267,7 @@ extract_data = function (computer_data_path, filedir, filename, verbose=TRUE) { header=TRUE, na.strings=c(' -99', ' -99.000'), sep=';', - skip=41)[,1:2] + skip=41) # Extract all the information for the station 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) { # 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), format="%Y%m%d"), - df_data[-1], + Qm3s=df_data$Qls * 1E-3, + df_data[-1:-2], code=code) return (df_data) diff --git a/script.R b/script.R index 6a357f1ead97ebd77487adfb28c73442b8c63eb3..37994b7d7d808f5352d678888f4dd5ab1c9ff9e8 100644 --- a/script.R +++ b/script.R @@ -1,5 +1,5 @@ -### A MODIFIER ### +###### A MODIFIER ###### # Path to the data computer_data_path = @@ -11,32 +11,35 @@ computer_work_path = "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/ASH" # "C:\\Users\\louis.heraut\\Documents\\CDD_stationnarite\\ASH" -# Manual selection -# Path to data that will be analysed -filedir = +### BANQUE HYDRO ### +## Manual selection ## +# Path to data that will be analysed from the BanqueHydro +BHfiledir = FALSE # "test" # "BanqueHydro_Export2021" -filename = +BHfilename = FALSE # c("H5920011_HYDRO_QJM.txt", "K4470010_HYDRO_QJM.txt") # "all" -# Or list selection +## Or list selection ## # Path to the list file of station that will be analysed -listdir = +BHlistdir = # FALSE "" -listname = - "Liste-station_RRSE.docx" +BHlistname = # FALSE -BHdir = - "BanqueHydro_Export2021" + "Liste-station_RRSE.docx" +BHdatadir = # FALSE + "BanqueHydro_Export2021" -# selecdir = "RRSE_selection" +### NIVALE ### + + -################## +######################## # Set working directory @@ -66,10 +69,10 @@ print(paste('figdir :', figdir)) # 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, - listdir, - listname, + BHlistdir, + BHlistname, cnames=c('code', 'station', 'BV_km2', @@ -79,18 +82,19 @@ if (is.character(listdir) & is.character(listname) & is.character(BHdir)){ 'choix'), cisnum=c('BV_km2', 'longueur_serie')) - filedir = BHdir - filename = df_selec$filename + BHfiledir = BHdatadir + BHfilename = df_selec$filename } # 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 -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 -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 df_lac = get_lacune(df_data, df_info)