diff --git a/plotting/datasheet.R b/plotting/datasheet.R index 56ecfb63ba9c28ec4dd6895e475f379e19aa9640..0cc1f5ede05c6c54ec2851818fea37e49db79ea8 100644 --- a/plotting/datasheet.R +++ b/plotting/datasheet.R @@ -429,7 +429,7 @@ datasheet_panel = function (list_df2plot, df_meta, trend_period, info_header, ti lim_pct=lim_pct) # Stores the plot - P[[i+nbh]] = p + P[[i+nbh]] = p } if (!is.null(df_page)) { diff --git a/plotting/layout.R b/plotting/layout.R index cb2437bb9983b85542d4f9e1710cdda1e6ab8523..e0c659253eb640c0340fc6ec3e253229620780ef 100644 --- a/plotting/layout.R +++ b/plotting/layout.R @@ -488,7 +488,7 @@ palette_tester = function (n=256) { ### Summary panel summary_panel = function (df_page, foot_note, foot_height, resources_path, AEAGlogo_file, INRAElogo_file, FRlogo_file, outdirTmp) { - + text_title = paste( "<b>Analyse de Stationnarité Hydrologique</b>", sep='') @@ -499,8 +499,6 @@ summary_panel = function (df_page, foot_note, foot_height, resources_path, AEAGl Sec_name = rle(df_page$section)$values nSec = length(Sec_name) - - nlim = 50 text_sum1 = '' text_page1 = '' @@ -508,7 +506,7 @@ summary_panel = function (df_page, foot_note, foot_height, resources_path, AEAGl text_page2 = '' nline = 0 - nline_max = 25 + nline_max = 58 for (idS in 1:nSec) { sec_name = Sec_name[idS] subSec_name = rle(df_page$subsection[df_page$section == sec_name])$values @@ -534,7 +532,7 @@ summary_panel = function (df_page, foot_note, foot_height, resources_path, AEAGl n_page = df_page$n[df_page$section == sec_name & df_page$subsection == subsec_name][1] - line = paste(" ", idS, ".", idSS, ". ", + line = paste(idS, ".", idSS, ". ", subsec_name, "<br>", sep='') page = paste("p.", n_page, "<br>", sep='') @@ -549,16 +547,23 @@ summary_panel = function (df_page, foot_note, foot_height, resources_path, AEAGl nline = nline + 1 } } + if (nline <= nline_max) { + text_sum1 = paste(text_sum1, "<br>", sep='') + text_page1 = paste(text_page1, "<br>", sep='') + } else { + text_sum2 = paste(text_sum2, "<br>", sep='') + text_page2 = paste(text_page2, "<br>", sep='') + } + nline = nline + 1 } - # text_sum1 = gsub("é", "é", text_sum1) - text_sum1 = gsub(" ", "<span style='color:white'>_</span>", - text_sum1) + + # text_sum1 = gsub(" ", "<span style='color:white'>_</span>", + # text_sum1) text_sum1 = gsub('[.]', '.', text_sum1) text_page1 = gsub('[.]', '.', text_page1) - # text_sum2 = gsub("é", "é", text_sum2) - text_sum2 = gsub(" ", "<span style='color:white'>_</span>", - text_sum2) + # text_sum2 = gsub(" ", "<span style='color:white'>_</span>", + # text_sum2) text_sum2 = gsub('[.]', '.', text_sum2) text_page2 = gsub('[.]', '.', text_page2) @@ -640,7 +645,7 @@ summary_panel = function (df_page, foot_note, foot_height, resources_path, AEAGl title_height = 0.75 subtitle_height = 1.25 margin_size = 0.5 - page_width = 0.5 + page_width = 2 height = 29.7 width = 21 diff --git a/plotting/map.R b/plotting/map.R index 991e0c3354f7887d8f586f4c03359002ec95c990..d86006ad4c3b09575f021b5fca9b9764aaa8e2a1 100644 --- a/plotting/map.R +++ b/plotting/map.R @@ -629,8 +629,8 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer_trend=1, # For the station to highlight geom_point(data=plot_map_code, aes(x=lon, y=lat), - shape=21, size=1.5, stroke=0.5, - color='#00A3A8', fill='#00A3A8') + shape=21, size=1.5, stroke=0.25, + color='grey97', fill='#00A3A8') } # Extracts the position of the tick of the colorbar diff --git a/processing/analyse.R b/processing/analyse.R index b0b841a7b6826cedd55d8a2822b0d22ffa72c5a9..6ee5525f3be62205b29a3c63b268581f0fb8eba6 100644 --- a/processing/analyse.R +++ b/processing/analyse.R @@ -97,11 +97,12 @@ get_intercept = function (df_Xtrend, df_Xlist, unit2day=365.25) { ### 1.1. QA # Realise the trend analysis of the average annual flow (QA) # hydrological variable -get_QAtrend = function (df_data, df_meta, period, alpha) { +get_QAtrend = function (df_data, df_meta, period, alpha, yearLac_day) { # Removes incomplete data from time series - df_data = remove_incomplete_data(df_data, df_meta, - yearLac_pct=1, yearStart='01-01') + df_data = missing_data(df_data, df_meta, + yearLac_day=yearLac_day, + yearStart='01-01') # Make sure to convert the period to a list period = as.list(period) @@ -150,11 +151,11 @@ get_QAtrend = function (df_data, df_meta, period, alpha) { ### 1.2. QMNA # Realise the trend analysis of the monthly minimum flow in the # year (QMNA) hydrological variable -get_QMNAtrend = function (df_data, df_meta, period, alpha, sampleSpan) { +get_QMNAtrend = function (df_data, df_meta, period, alpha, sampleSpan, yearLac_day) { # Removes incomplete data from time series - df_data = remove_incomplete_data(df_data, df_meta, - yearLac_pct=1, yearStart='01-01') + df_data = missing_data(df_data, df_meta, + yearLac_day=yearLac_day, yearStart='01-01') # Samples the data df_data = sampling_data(df_data, df_meta, sampleSpan=sampleSpan) @@ -219,11 +220,11 @@ get_QMNAtrend = function (df_data, df_meta, period, alpha, sampleSpan) { ### 1.3. VCN10 # Realises the trend analysis of the minimum 10 day average flow # over the year (VCN10) hydrological variable -get_VCN10trend = function (df_data, df_meta, period, alpha, sampleSpan) { +get_VCN10trend = function (df_data, df_meta, period, alpha, sampleSpan, yearLac_day) { # Removes incomplete data from time series - df_data = remove_incomplete_data(df_data, df_meta, - yearLac_pct=1, yearStart='01-01') + df_data = missing_data(df_data, df_meta, + yearLac_day=yearLac_day, yearStart='01-01') # Samples the data df_data = sampling_data(df_data, df_meta, @@ -327,7 +328,7 @@ which_underfirst = function (L, UpLim, select_longest=TRUE) { return (id) } -get_DEBtrend = function (df_data, df_meta, period, alpha, sampleSpan, thresold_type='VCN10', select_longest=TRUE) { +get_DEBtrend = function (df_data, df_meta, period, alpha, sampleSpan, yearLac_day, thresold_type='VCN10', select_longest=TRUE) { # Get all different stations code Code = levels(factor(df_meta$code)) @@ -352,18 +353,18 @@ get_DEBtrend = function (df_data, df_meta, period, alpha, sampleSpan, thresold_t } # Removes incomplete data from time series - df_data = remove_incomplete_data(df_data, - df_meta=df_meta, - yearLac_pct=1) + df_data = missing_data(df_data, + df_meta=df_meta, + yearLac_day=yearLac_day) # Samples the data df_data = sampling_data(df_data, df_meta=df_meta, sampleSpan=sampleSpan) # Removes incomplete data from the averaged time series - df_data_roll = remove_incomplete_data(df_data_roll, - df_meta=df_meta, - yearLac_pct=1) + df_data_roll = missing_data(df_data_roll, + df_meta=df_meta, + yearLac_day=yearLac_day) # Samples the data df_data_roll = sampling_data(df_data_roll, df_meta=df_meta, @@ -481,7 +482,7 @@ get_DEBtrend = function (df_data, df_meta, period, alpha, sampleSpan, thresold_t ### 1.5. CEN date # Realises the trend analysis of the date of the minimum 10 day # average flow over the year (VCN10) hydrological variable -get_CENtrend = function (df_data, df_meta, period, alpha, sampleSpan) { +get_CENtrend = function (df_data, df_meta, period, alpha, sampleSpan, yearLac_day) { # Get all different stations code Code = levels(factor(df_meta$code)) @@ -503,9 +504,9 @@ get_CENtrend = function (df_data, df_meta, period, alpha, sampleSpan) { } # Removes incomplete data from time series - df_data_roll = remove_incomplete_data(df_data_roll, df_meta, - yearLac_pct=1, - yearStart='01-01') + df_data_roll = missing_data(df_data_roll, df_meta, + yearLac_day=yearLac_day, + yearStart='01-01') # Samples the data df_data_roll = sampling_data(df_data_roll, df_meta, sampleSpan=sampleSpan) @@ -523,10 +524,10 @@ get_CENtrend = function (df_data, df_meta, period, alpha, sampleSpan) { df_CENlist = prepare(df_data_roll, colnamegroup=c('code')) # Compute the yearly min over the averaged data df_CENEx = extract.Var(data.station=df_CENlist, - funct=which.min, - period=per, - timestep='year', - pos.datetime=1) + funct=which.min, + period=per, + timestep='year', + pos.datetime=1) # Converts index of the CEN to the julian date associated df_CENEx = prepare_date(df_CENEx, df_CENlist) diff --git a/processing/format.R b/processing/format.R index 731578bd173017a45b3233e1f306faa003f3e43b..316169a0f80cf0b853d61d704e8740ae87e6c7d1 100644 --- a/processing/format.R +++ b/processing/format.R @@ -31,6 +31,7 @@ # Usefull library library(dplyr) +library(Hmisc) ## 1. BEFORE TREND ANALYSE @@ -80,8 +81,8 @@ join = function (df_data_AG, df_data_IN, df_meta_AG, df_meta_IN) { return (list(data=df_data, meta=df_meta)) } -### 1.2. Remove incomplete data -remove_incomplete_data = function (df_data, df_meta, yearLac_pct=1, yearStart='01-01', Code=NULL) { +### 1.2. Manages missing data +missing_data = function (df_data, df_meta, yearLac_day=3, yearStart='01-01', Code=NULL) { if (is.null(Code)) { # Get all different stations code @@ -129,9 +130,20 @@ remove_incomplete_data = function (df_data, df_meta, yearLac_pct=1, yearStart='0 yearLacMiss_pct = nbNA/nbDate * 100 - if (yearLacMiss_pct > yearLac_pct) { + if (nbNA > yearLac_day) { df_data_code_year$Value = NA df_data_code[OkYear,] = df_data_code_year + + } else if (nbNA <= yearLac_day & nbNA > 1) { + DateJ = as.numeric(df_data_code_year$Date) + Value = df_data_code_year$Value + + Value = approxExtrap(x=DateJ, + y=Value, + xout=DateJ, + method="linear", + na.rm=TRUE)$y + df_data_code$Value[OkYear] = Value } } df_data[df_data$code == code,] = df_data_code @@ -150,19 +162,23 @@ sampling_data = function (df_data, df_meta, sampleSpan=c('05-01', '11-30'), Code } else { nCode = length(Code) } - - sampleStart = as.Date(paste('1970', sampleSpan[1], sep='-')) - sampleEnd = as.Date(paste('1970', sampleSpan[2], sep='-')) + + # 1972 is leap year reference is case of leap year comparison + sampleStart = as.Date(paste('1972', sampleSpan[1], sep='-')) + sampleEnd = as.Date(paste('1972', sampleSpan[2], sep='-')) for (code in Code) { # Extracts the data corresponding to the code df_data_code = df_data[df_data$code == code,] DateMD = substr(df_data_code$Date, 6, 10) - Date = paste('1970', DateMD, sep='-') + Date = paste('1972', DateMD, sep='-') df_data_code$Value[Date < sampleStart | Date > sampleEnd] = NA + # Leap year verification + # print(df_data_code[df_data_code$Date > as.Date("1992-02-25"),]) + df_data[df_data$code == code,] = df_data_code } diff --git a/script.R b/script.R index 6eb0fb9ea5d2aed0900c1a2e6ffd78f5bbea4257..a8ce827b0026981f29f7c456b3aff311f3d4b7de 100644 --- a/script.R +++ b/script.R @@ -55,19 +55,20 @@ filedir = # Name of the file that will be analysed from the BH directory # (if 'all', all the file of the directory will be chosen) filename = - # "" - c( + "" + # c( # "S2235610_HYDRO_QJM.txt", # "P1712910_HYDRO_QJM.txt", # "P0885010_HYDRO_QJM.txt", # "O5055010_HYDRO_QJM.txt", # "O0384010_HYDRO_QJM.txt", # "S4214010_HYDRO_QJM.txt", - "Q7002910_HYDRO_QJM.txt" + # "Q7002910_HYDRO_QJM.txt" + # "Q0214010_HYDRO_QJM.txt" # "O3035210_HYDRO_QJM.txt" # "O0554010_HYDRO_QJM.txt", # "O1584610_HYDRO_QJM.txt" - ) + # ) ## AGENCE EAU ADOUR GARONNE SELECTION @@ -77,8 +78,8 @@ AGlistdir = "" AGlistname = - "" - # "Liste-station_RRSE.docx" + # "" + "Liste-station_RRSE.docx" ## NIVALE SELECTION @@ -105,6 +106,9 @@ mean_period = list(period1, period2) # alpha the risk alpha = 0.1 +# Number of missing days per year before remove the year +yearLac_day = 3 + # Sampling span of the data sampleSpan = c('05-01', '11-30') @@ -239,19 +243,22 @@ df_meta = get_hydrograph(df_data, df_meta, period=mean_period[[1]])$meta # QA trend res_QAtrend = get_QAtrend(df_data, df_meta, period=trend_period, - alpha=alpha) + alpha=alpha, + yearLac_day=yearLac_day) # QMNA tend res_QMNAtrend = get_QMNAtrend(df_data, df_meta, period=trend_period, alpha=alpha, - sampleSpan=sampleSpan) + sampleSpan=sampleSpan, + yearLac_day=yearLac_day) # VCN10 trend res_VCN10trend = get_VCN10trend(df_data, df_meta, period=trend_period, alpha=alpha, - sampleSpan=sampleSpan) + sampleSpan=sampleSpan, + yearLac_day=yearLac_day) # Start date for low water trend res_DEBtrend = get_DEBtrend(df_data, df_meta, @@ -259,14 +266,16 @@ res_DEBtrend = get_DEBtrend(df_data, df_meta, alpha=alpha, sampleSpan=sampleSpan, thresold_type='VCN10', - select_longest=TRUE) + select_longest=TRUE, + yearLac_day=yearLac_day) # 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) + sampleSpan=sampleSpan, + yearLac_day=yearLac_day) ### 3.3. Break analysis # df_break = get_break(res_QAtrend$data, df_meta) @@ -286,7 +295,7 @@ df_shapefile = ini_shapefile(computer_data_path, fr_shpdir, fr_shpname, bs_shpdir, bs_shpname, sbs_shpdir, sbs_shpname, - rv_shpdir, rv_shpname, riv=FALSE) + rv_shpdir, rv_shpname, riv=TRUE) ### 4.1. Simple time panel to criticize station data # Plot time panel of debit by stations diff --git a/script_install.R b/script_install.R index 762033e8f281c249e65199797f045d7bb31b418d..6f05ba5956e5ffb38e99716ab0d32e240fdecd2a 100644 --- a/script_install.R +++ b/script_install.R @@ -16,6 +16,7 @@ install.packages("RColorBrewer") install.packages('trend') install.packages("shadowtext") install.packages("png") +install.packages("Hmisc") # linux