From 07849faa6d3ee3fa604df0a2ac9ef3480eced53d Mon Sep 17 00:00:00 2001 From: "louis.heraut" <louis.heraut@inrae.fr> Date: Mon, 28 Mar 2022 12:03:55 +0200 Subject: [PATCH] logo prefet --- Rcode/plotting/.directory | 5 +- Rcode/plotting/datasheet.R | 53 ++++++++++++++----- Rcode/plotting/layout.R | 97 +++++++++++++++++++++------------- Rcode/plotting/map.R | 31 ++++++----- Rcode/plotting/script_layout.R | 2 + Rcode/plotting/table.R | 22 ++++---- Rcode/processing/.directory | 5 +- main.R | 14 ++--- 8 files changed, 142 insertions(+), 87 deletions(-) diff --git a/Rcode/plotting/.directory b/Rcode/plotting/.directory index 385563e..fc3e268 100644 --- a/Rcode/plotting/.directory +++ b/Rcode/plotting/.directory @@ -1,4 +1,7 @@ [Dolphin] -Timestamp=2021,11,10,14,51,45 +Timestamp=2022,3,28,11,42,24 Version=4 VisibleRoles=Icons_text,Icons_size + +[Settings] +HiddenFilesShown=true diff --git a/Rcode/plotting/datasheet.R b/Rcode/plotting/datasheet.R index 546ae5f..33b8559 100644 --- a/Rcode/plotting/datasheet.R +++ b/Rcode/plotting/datasheet.R @@ -40,7 +40,16 @@ source(file.path('Rcode', 'plotting', 'shortcut.R'), encoding='UTF-8') # Manages datasheets creations for all stations. Makes the call to # the different headers, trend analysis graphs and realises arranging # every plots. -datasheet_panel = function (list_df2plot, df_meta, trend_period, mean_period, linetype_per, axis_xlim, colorForce, info_header, time_header, foot_note, layout_matrix, info_height, time_ratio, var_ratio, foot_height, paper_size, resources_path, df_shapefile, logo_dir, AEAGlogo_file, INRAElogo_file, FRlogo_file, outdirTmp_pdf, outdirTmp_png, df_page=NULL) { +datasheet_panel = function (list_df2plot, df_meta, trend_period, + mean_period, linetype_per, axis_xlim, + colorForce, info_header, time_header, + foot_note, layout_matrix, info_height, + time_ratio, var_ratio, foot_height, + paper_size, resources_path, df_shapefile, + logo_dir, PRlogo_file, AEAGlogo_file, + INRAElogo_file, FRlogo_file, + outdirTmp_pdf, outdirTmp_png, + df_page=NULL) { # The percentage of augmentation and diminution of the min # and max limits for y axis @@ -349,7 +358,7 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, mean_period, li } foot = foot_panel(footName, n_page, resources_path, - logo_dir, + logo_dir, PRlogo_file, AEAGlogo_file, INRAElogo_file, FRlogo_file, foot_height) P[[nbg]] = foot @@ -456,7 +465,13 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, mean_period, li ## 2. PANEL FOR THE DATASHEET __________________________________ ### 2.1. Time panel __________________________________________________ -time_panel = function (df_data_code, df_trend_code, var, type, linetype_per='solid', alpha=0.1, colorForce=FALSE, 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, + linetype_per='solid', alpha=0.1, + colorForce=FALSE, 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) { # Compute max and min of flow maxQ = max(df_data_code$Value, na.rm=TRUE) @@ -1332,7 +1347,10 @@ time_panel = function (df_data_code, df_trend_code, var, type, linetype_per='sol ### 2.2. Info panel __________________________________________________ # Plots the header that regroups all the info on the station -info_panel = function(list_df2plot, df_meta, trend_period=NULL, mean_period=NULL, periodHyd=NULL, df_shapefile=NULL, codeLight=NULL, df_data_code=NULL, to_do='all') { +info_panel = function(list_df2plot, df_meta, trend_period=NULL, + mean_period=NULL, periodHyd=NULL, + df_shapefile=NULL, codeLight=NULL, + df_data_code=NULL, to_do='all') { # If there is a data serie for the given code if (!is.null(df_data_code)) { @@ -1355,7 +1373,8 @@ info_panel = function(list_df2plot, df_meta, trend_period=NULL, mean_period=NULL df_shapefile=df_shapefile, codeLight=codeLight, mapType='mini', - margin=margin(t=0, r=-12, b=0, l=0, unit="mm"), + margin=margin(t=0, r=-12, b=0, l=0, + unit="mm"), showSea=FALSE, verbose=FALSE) # Otherwise @@ -1379,7 +1398,8 @@ info_panel = function(list_df2plot, df_meta, trend_period=NULL, mean_period=NULL # Converts all texts to graphical object in the right position gtext1 = richtext_grob(text1, x=0, y=1, - margin=unit(c(t=0, r=5, b=0, l=0), "mm"), + margin=unit(c(t=0, r=5, b=0, l=0), + "mm"), hjust=0, vjust=1, gp=gpar(col="#00A3A8", fontsize=14)) } else if ('code' %in% to_do) { @@ -1390,7 +1410,8 @@ info_panel = function(list_df2plot, df_meta, trend_period=NULL, mean_period=NULL # Converts all texts to graphical object in the right position gtext1 = richtext_grob(text1, x=0, y=1, - margin=unit(c(t=0, r=5, b=0, l=0), "mm"), + margin=unit(c(t=0, r=5, b=0, l=0), + "mm"), hjust=0, vjust=1, gp=gpar(col="#00A3A8", fontsize=14)) } else { @@ -1407,7 +1428,8 @@ info_panel = function(list_df2plot, df_meta, trend_period=NULL, mean_period=NULL sep='') gtext2 = richtext_grob(text2, x=0, y=1.25, - margin=unit(c(t=0, r=0, b=0, l=0), "mm"), + margin=unit(c(t=0, r=0, b=0, l=0), + "mm"), hjust=0, vjust=1, gp=gpar(col="grey20", fontsize=8)) } else { @@ -1418,7 +1440,8 @@ info_panel = function(list_df2plot, df_meta, trend_period=NULL, mean_period=NULL if ('spatial' %in% to_do | 'all' %in% to_do) { text3 = paste( "<b>", - "Superficie : ", df_meta_code$surface_km2_BH, " [km<sup>2</sup>] <br>", + "Superficie : ", df_meta_code$surface_km2_BH, + " [km<sup>2</sup>] <br>", "Altitude : ", df_meta_code$altitude_m_BH, " [m]<br>", "X = ", df_meta_code$L93X_m_BH, " [m ; Lambert93]<br>", "Y = ", df_meta_code$L93Y_m_BH, " [m ; Lambert93]", @@ -1426,7 +1449,8 @@ info_panel = function(list_df2plot, df_meta, trend_period=NULL, mean_period=NULL sep='') gtext3 = richtext_grob(text3, x=0, y=1, - margin=unit(c(t=0, r=0, b=0, l=0), "mm"), + margin=unit(c(t=0, r=0, b=0, l=0), + "mm"), hjust=0, vjust=1, gp=gpar(col="grey20", fontsize=9)) } else { @@ -1436,7 +1460,8 @@ info_panel = function(list_df2plot, df_meta, trend_period=NULL, mean_period=NULL # Time info about station if ('temporal' %in% to_do | 'all' %in% to_do) { # Computes the time span of data, the start and the end - duration = as.numeric(format(as.Date(df_meta_code$fin), "%Y")) - + duration = as.numeric(format(as.Date(df_meta_code$fin), + "%Y")) - as.numeric(format(as.Date(df_meta_code$debut), "%Y")) debut = format(as.Date(df_meta_code$debut), "%d/%m/%Y") fin = format(as.Date(df_meta_code$fin), "%d/%m/%Y") @@ -1446,12 +1471,14 @@ info_panel = function(list_df2plot, df_meta, trend_period=NULL, mean_period=NULL "Date de début : ", debut, "<br>", "Date de fin : ", fin, "<br>", "Nombre d'années : ", duration, " [ans]", "<br>", - "Taux de lacunes : ", signif(df_meta_code$tLac100, 2), " [%]", + "Taux de lacunes : ", signif(df_meta_code$tLac100, 2), + " [%]", "</b>", sep='') gtext4 = richtext_grob(text4, x=0, y=1, - margin=unit(c(t=0, r=0, b=0, l=0), "mm"), + margin=unit(c(t=0, r=0, b=0, l=0), + "mm"), hjust=0, vjust=1, gp=gpar(col="grey20", fontsize=9)) } else { diff --git a/Rcode/plotting/layout.R b/Rcode/plotting/layout.R index 6105691..1bac6bd 100644 --- a/Rcode/plotting/layout.R +++ b/Rcode/plotting/layout.R @@ -49,7 +49,7 @@ library(shadowtext) library(png) library(ggrepel) -, + # Sourcing R file source(file.path('Rcode', 'plotting', 'datasheet.R'), encoding='UTF-8') source(file.path('Rcode', 'plotting', 'map.R'), encoding='UTF-8') @@ -152,6 +152,7 @@ layout_panel = function (df_data, df_meta, layout_matrix, resdir=NULL, resources_path=NULL, logo_dir=NULL, + PRlogo_file=NULL, AEAGlogo_file=NULL, INRAElogo_file=NULL, FRlogo_file=NULL) { @@ -284,6 +285,7 @@ layout_panel = function (df_data, df_meta, layout_matrix, foot_height=foot_height, resources_path=resources_path, logo_dir=logo_dir, + PRlogo_file=PRlogo_file, AEAGlogo_file=AEAGlogo_file, INRAElogo_file=INRAElogo_file, FRlogo_file=FRlogo_file, @@ -304,6 +306,7 @@ layout_panel = function (df_data, df_meta, layout_matrix, foot_height=foot_height, resources_path=resources_path, logo_dir=logo_dir, + PRlogo_file=PRlogo_file, AEAGlogo_file=AEAGlogo_file, INRAElogo_file=INRAElogo_file, FRlogo_file=FRlogo_file, @@ -324,6 +327,7 @@ layout_panel = function (df_data, df_meta, layout_matrix, foot_height=foot_height, resources_path=resources_path, logo_dir=logo_dir, + PRlogo_file=PRlogo_file, AEAGlogo_file=AEAGlogo_file, INRAElogo_file=INRAElogo_file, FRlogo_file=FRlogo_file, @@ -336,23 +340,24 @@ layout_panel = function (df_data, df_meta, layout_matrix, # If summarize table needs to be plot if ('table' %in% to_plot) { df_page = table_panel(list_df2plot, - df_meta, - trend_period, - mean_period, - colorForce=colorForce, - slice=19, - paper_size='A3', - foot_note=foot_note, - foot_height=foot_height, - resdir=resdir, - resources_path=resources_path, - logo_dir=logo_dir, - AEAGlogo_file=AEAGlogo_file, - INRAElogo_file=INRAElogo_file, - FRlogo_file=FRlogo_file, - outdirTmp_pdf=outdirTmp_pdf, - outdirTmp_png=outdirTmp_png, - df_page=df_page) + df_meta, + trend_period, + mean_period, + colorForce=colorForce, + slice=19, + paper_size='A3', + foot_note=foot_note, + foot_height=foot_height, + resdir=resdir, + resources_path=resources_path, + logo_dir=logo_dir, + PRlogo_file=PRlogo_file, + AEAGlogo_file=AEAGlogo_file, + INRAElogo_file=INRAElogo_file, + FRlogo_file=FRlogo_file, + outdirTmp_pdf=outdirTmp_pdf, + outdirTmp_png=outdirTmp_png, + df_page=df_page) } # If datasheets needs to be plot @@ -376,6 +381,7 @@ layout_panel = function (df_data, df_meta, layout_matrix, resources_path=resources_path, df_shapefile=df_shapefile, logo_dir=logo_dir, + PRlogo_file=PRlogo_file, AEAGlogo_file=AEAGlogo_file, INRAElogo_file=INRAElogo_file, FRlogo_file=FRlogo_file, @@ -390,6 +396,7 @@ layout_panel = function (df_data, df_meta, layout_matrix, foot_height, resources_path, logo_dir=logo_dir, + PRlogo_file=PRlogo_file, AEAGlogo_file, INRAElogo_file, FRlogo_file, @@ -415,7 +422,10 @@ layout_panel = function (df_data, df_meta, layout_matrix, ## 4. PDF ORGANISATION PANEL _________________________________________ ### 4.1. Summary _____________________________________________________ -summary_panel = function (df_page, foot_note, foot_height, resources_path, logo_dir, AEAGlogo_file, INRAElogo_file, FRlogo_file, outdirTmp_pdf, outdirTmp_png) { +summary_panel = function (df_page, foot_note, foot_height, + resources_path, logo_dir, PRlogo_file, + AEAGlogo_file, INRAElogo_file, FRlogo_file, + outdirTmp_pdf, outdirTmp_png) { text_title = paste( "<b>Analyse de Stationnarité Hydrologique</b>", @@ -539,7 +549,7 @@ summary_panel = function (df_page, foot_note, foot_height, resources_path, logo_ footName = 'sommaire' foot = foot_panel(footName, 1, resources_path, - logo_dir, + logo_dir, PRlogo_file, AEAGlogo_file, INRAElogo_file, FRlogo_file, foot_height) @@ -611,7 +621,9 @@ summary_panel = function (df_page, foot_note, foot_height, resources_path, logo_ } ### 4.2. Foot note panel______________________________________________ -foot_panel = function (name, n_page, resources_path, logo_dir, AEAGlogo_file, INRAElogo_file, FRlogo_file, foot_height) { +foot_panel = function (name, n_page, resources_path, logo_dir, + PRlogo_file, AEAGlogo_file, INRAElogo_file, + FRlogo_file, foot_height) { text_page = paste( name, " <b>p. ", n_page, "</b>", @@ -634,42 +646,51 @@ foot_panel = function (name, n_page, resources_path, logo_dir, AEAGlogo_file, IN hjust=1, vjust=0.5, gp=gpar(col="#00A3A8", fontsize=6)) - AEAGlogo_path = file.path(resources_path, logo_dir, AEAGlogo_file) - INRAElogo_path = file.path(resources_path, logo_dir, INRAElogo_file) + + PRlogo_path = file.path(resources_path, logo_dir, PRlogo_file) FRlogo_path = file.path(resources_path, logo_dir, FRlogo_file) + INRAElogo_path = file.path(resources_path, logo_dir, INRAElogo_file) + AEAGlogo_path = file.path(resources_path, logo_dir, AEAGlogo_file) + - AEAGlogo_img = readPNG(AEAGlogo_path) - AEAGlogo_grob = rasterGrob(AEAGlogo_img, - y=0.49, - vjust=0.5, - width=unit(0.7*foot_height, "cm")) + PRlogo_img = readPNG(PRlogo_path) + PRlogo_grob = rasterGrob(PRlogo_img, + x=0, hjust=0, + width=unit(0.8*foot_height, "cm")) + FRlogo_img = readPNG(FRlogo_path) + FRlogo_grob = rasterGrob(FRlogo_img, + x=0, hjust=0, + width=unit(1*foot_height, "cm")) + INRAElogo_img = readPNG(INRAElogo_path) INRAElogo_grob = rasterGrob(INRAElogo_img, y=0.565, vjust=0.5, width=unit(1.08*foot_height, "cm")) - FRlogo_img = readPNG(FRlogo_path) - FRlogo_grob = rasterGrob(FRlogo_img, - x=0, hjust=0, - width=unit(1*foot_height, "cm")) + AEAGlogo_img = readPNG(AEAGlogo_path) + AEAGlogo_grob = rasterGrob(AEAGlogo_img, + y=0.49, + vjust=0.5, + width=unit(0.7*foot_height, "cm")) - P = list(void, - FRlogo_grob, INRAElogo_grob, AEAGlogo_grob, + P = list(void, PRlogo_grob, FRlogo_grob, + INRAElogo_grob, AEAGlogo_grob, gtext_page, gtext_date) # Creates the matrix layout - LM = matrix(c(1, 2, 3, 4, 5, - 1, 2, 3, 4, 6), + LM = matrix(c(1, 2, 3, 4, 5, 6, + 1, 2, 3, 4, 5, 7), nrow=2, byrow=TRUE) # And sets the relative width of each plot widths = rep(1, times=ncol(LM)) widths[2] = 0.2 - widths[3] = 0.25 - widths[4] = 0.2 + widths[3] = 0.2 + widths[4] = 0.25 + widths[5] = 0.2 # Arranges all the graphical objetcs plot = grid.arrange(grobs=P, diff --git a/Rcode/plotting/map.R b/Rcode/plotting/map.R index 6fbdc26..bae9e40 100644 --- a/Rcode/plotting/map.R +++ b/Rcode/plotting/map.R @@ -33,19 +33,16 @@ ## 1. MAP PANEL ______________________________________________________ # Generates a map plot of the tendancy of a hydrological variable -map_panel = function (list_df2plot, df_meta, df_shapefile, idPer_trend=1, - trend_period, mean_period, colorForce=FALSE, - codeLight=NULL, - mapType='trend', - margin=NULL, showSea=TRUE, - foot_note=FALSE, - foot_height=0, resources_path=NULL, - logo_dir=NULL, - AEAGlogo_file=NULL, INRAElogo_file=NULL, - FRlogo_file=NULL, df_page=NULL, - outdirTmp_pdf='', outdirTmp_png='', - verbose=TRUE) { - +map_panel = function (list_df2plot, df_meta, df_shapefile, + idPer_trend=1, trend_period, mean_period, + colorForce=FALSE, codeLight=NULL, + mapType='trend', margin=NULL, showSea=TRUE, + foot_note=FALSE, foot_height=0, + resources_path=NULL, logo_dir=NULL, + PRlogo_file=NULL, AEAGlogo_file=NULL, + INRAElogo_file=NULL, FRlogo_file=NULL, + df_page=NULL, outdirTmp_pdf='', + outdirTmp_png='', verbose=TRUE) { # Extract shapefiles df_france = df_shapefile$france @@ -67,8 +64,10 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer_trend=1, # Number of trend period nPeriod_trend = length(trend_period) - # Extracts the min and the max of the mean trend for all the station - res = short_trendExtremes(list_df2plot, Code, nPeriod_trend, nbVar, nCode, colorForce) + # Extracts the min and the max of the mean trend + # for all the station + res = short_trendExtremes(list_df2plot, Code, nPeriod_trend, + nbVar, nCode, colorForce) minTrendValue = res$min maxTrendValue = res$max } @@ -1011,7 +1010,7 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer_trend=1, foot = foot_panel(footName, n_page, resources_path, - logo_dir, + logo_dir, PRlogo_file, AEAGlogo_file, INRAElogo_file, FRlogo_file, foot_height) diff --git a/Rcode/plotting/script_layout.R b/Rcode/plotting/script_layout.R index c1fc66a..63a11ae 100644 --- a/Rcode/plotting/script_layout.R +++ b/Rcode/plotting/script_layout.R @@ -68,6 +68,7 @@ if ('station_serie_plot' %in% to_do) { figdir=figdir, resources_path=resources_path, logo_dir=logo_dir, + PRlogo_file=PRlogo_file, AEAGlogo_file=AEAGlogo_file, INRAElogo_file=INRAElogo_file, FRlogo_file=FRlogo_file) @@ -102,6 +103,7 @@ if ('station_trend_plot' %in% to_do) { resdir=resdir, resources_path=resources_path, logo_dir=logo_dir, + PRlogo_file=PRlogo_file, AEAGlogo_file=AEAGlogo_file, INRAElogo_file=INRAElogo_file, FRlogo_file=FRlogo_file) diff --git a/Rcode/plotting/table.R b/Rcode/plotting/table.R index f8dd4da..cc74168 100644 --- a/Rcode/plotting/table.R +++ b/Rcode/plotting/table.R @@ -32,18 +32,18 @@ ## 1. TABLE PANEL ___________________________________________________ -# Generates a summarizing table of the trend analyses of all station for different hydrological variables and periods. Also shows difference of means between specific periods. -table_panel = function (list_df2plot, df_meta, trend_period, mean_period, - colorForce=FALSE, slice=NULL, title=NULL, - paper_size='A3', - foot_note=FALSE, - foot_height=0, - resdir=NULL, +# Generates a summarizing table of the trend analyses of all station +# for different hydrological variables and periods. Also shows +# difference of means between specific periods. +table_panel = function (list_df2plot, df_meta, trend_period, + mean_period, colorForce=FALSE, slice=NULL, + title=NULL, paper_size='A3', + foot_note=FALSE, foot_height=0, resdir=NULL, resources_path=NULL, - logo_dir=NULL, + logo_dir=NULL, PRlogo_file=NULL, AEAGlogo_file=NULL, INRAElogo_file=NULL, - FRlogo_file=NULL, - outdirTmp_pdf='', outdirTmp_png='', + FRlogo_file=NULL, outdirTmp_pdf='', + outdirTmp_png='', df_page=NULL) { # Number of variable/plot @@ -1355,7 +1355,7 @@ table_panel = function (list_df2plot, df_meta, trend_period, mean_period, foot = foot_panel(footName, n_page, resources_path, - logo_dir, + logo_dir, PRlogo_file, AEAGlogo_file, INRAElogo_file, FRlogo_file, foot_height) diff --git a/Rcode/processing/.directory b/Rcode/processing/.directory index e0e6e40..21900c6 100644 --- a/Rcode/processing/.directory +++ b/Rcode/processing/.directory @@ -1,4 +1,7 @@ [Dolphin] -Timestamp=2021,11,10,14,51,56 +Timestamp=2022,3,28,11,42,21 Version=4 VisibleRoles=Icons_text,Icons_size + +[Settings] +HiddenFilesShown=true diff --git a/main.R b/main.R index aa1fdfc..a10a9ca 100644 --- a/main.R +++ b/main.R @@ -77,12 +77,12 @@ filedir = # (if "all", all the file of the directory will be chosen) filename = # "" - "all" - # c( + # "all" + c( # "S2235610_HYDRO_QJM.txt", # "Q7002910_HYDRO_QJM.txt", - # "O0362510_HYDRO_QJM.txt" - # ) + "O0362510_HYDRO_QJM.txt" + ) ## 3. WHAT YOU WANT TO DO ____________________________________________ # This vector regroups all the different step you want to do. For example if you write 'station_extraction', the extraction of the data for the station will be done. If you add also 'station_analyse', the extraction and then the trend analyse will be done. But if you only write, for example, 'station_plot', without having previously execute the code with 'station_extraction' and 'station_analyse', it will results in a failure. @@ -100,9 +100,9 @@ filename = # 'climate_trend_plot' : Plotting of trend analyses of climate data to_do = c( - 'station_extraction', - 'station_trend_analyse' - # 'station_trend_plot' + # 'station_extraction', + # 'station_trend_analyse', + 'station_trend_plot' ) ## 4. ANALYSIS PARAMETERS ____________________________________________ -- GitLab