diff --git a/plotting/layout.R b/plotting/layout.R index afb19ca3b3e442a51b6971665b23536730a7a216..44a84f98694cbbeeb6bb3c9952d901a4ba0c005b 100644 --- a/plotting/layout.R +++ b/plotting/layout.R @@ -130,11 +130,12 @@ datasheet_layout = function (df_data, df_meta, layout_matrix, isplot=c('datasheet', 'matrix', 'map'), figdir='', filedir_opt='', filename_opt='', variable='', df_trend=NULL, - p_threshold=0.1, unit2day=365.25, type='', - trend_period=NULL, mean_period=NULL, - axis_xlim=NULL, missRect=FALSE, - time_header=NULL, info_header=TRUE, - info_ratio=1, time_ratio=2, var_ratio=3, + p_threshold=0.1, unit2day=365.25, var='', + type='', trend_period=NULL, + mean_period=NULL, axis_xlim=NULL, + missRect=FALSE, time_header=NULL, + info_header=TRUE, info_ratio=1, + time_ratio=2, var_ratio=3, df_shapefile=NULL) { # Name of the document @@ -195,6 +196,12 @@ datasheet_layout = function (df_data, df_meta, layout_matrix, unit2day = replicate(nbp, unit2day) }} + if (all(class(var) != 'list')) { + var = list(var) + if (length(var) == 1) { + var = replicate(nbp, var) + }} + if (all(class(type) != 'list')) { type = list(type) if (length(type) == 1) { @@ -217,7 +224,7 @@ datasheet_layout = function (df_data, df_meta, layout_matrix, trend=df_trend[[i]], p_threshold=p_threshold[[i]], unit2day=unit2day[[i]], - type=type[[i]], + var=var[[i]], type=type[[i]], missRect=missRect[[i]]) # Stores it list_df2plot[[i]] = df2plot diff --git a/plotting/map.R b/plotting/map.R index 5dc1e2c830b9a27d83c453877e2717cd7141536b..9e6eb743a094ef8cc65f89defc3fd88ad07a86fc 100644 --- a/plotting/map.R +++ b/plotting/map.R @@ -156,7 +156,7 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' } # Computes the mean of the data on the period - dataMean = mean(df_data_code_per$Qm3s, na.rm=TRUE) + dataMean = mean(df_data_code_per$Value, na.rm=TRUE) # Normalises the trend value by the mean of the data trendMean = df_trend_code_per$trend / dataMean @@ -187,13 +187,13 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' break } # Extracts the variable of the plot - type = list_df2plot[[i]]$type + var = list_df2plot[[i]]$var # Createsa name for the map - outname = paste('map_', type, sep='') + outname = paste('map_', var, sep='') # If there is the verbose option if (verbose) { # Prints the name of the map - print(paste('Map for variable : ', type, + print(paste('Map for variable : ', var, " (", round(i/nbp*100, 1), " %)", sep='')) } @@ -368,7 +368,7 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' } # Computes the mean of the data on the period - dataMean = mean(df_data_code_per$Qm3s, na.rm=TRUE) + dataMean = mean(df_data_code_per$Value, na.rm=TRUE) # Normalises the trend value by the mean of the data trendMean = df_trend_code_per$trend / dataMean @@ -485,7 +485,7 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' size=0.6, color="#00A3A8") + # Writes title geom_shadowtext(data=tibble(x=-0.3, y=0.2, - label=type), + label=var), aes(x=x, y=y, label=label), fontface="bold", color="#00A3A8", diff --git a/plotting/matrix.R b/plotting/matrix.R index 0bdf77343edfc8ea321e7a43e6d01bf9436a8df0..f8454d5175d045ddb94a539bef6b3f8c3bf1f434 100644 --- a/plotting/matrix.R +++ b/plotting/matrix.R @@ -156,7 +156,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice } # Computes the mean of the data on the period - dataMean = mean(df_data_code_per$Qm3s, na.rm=TRUE) + dataMean = mean(df_data_code_per$Value, na.rm=TRUE) # Normalises the trend value by the mean of the data trendMean = df_trend_code_per$trend / dataMean @@ -180,7 +180,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Blank vectors to store info about trend analyses Periods_trend = c() NPeriod_trend = c() - Type_trend = list() + Var_trend = list() Code_trend = c() Pthresold_trend = c() TrendMean_trend = c() @@ -200,7 +200,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice df_trend = list_df2plot[[i]]$trend p_threshold = list_df2plot[[i]]$p_threshold # Extract the variable of the plot - type = list_df2plot[[i]]$type + var = list_df2plot[[i]]$var # Extracts the data corresponding to the code df_data_code = df_data[df_data$code == code,] # Extracts the trend corresponding to the code @@ -229,7 +229,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice } # Computes the mean of the data on the period - dataMean = mean(df_data_code_per$Qm3s, na.rm=TRUE) + dataMean = mean(df_data_code_per$Value, na.rm=TRUE) # Normalises the trend value by the mean of the data trendMean = df_trend_code_per$trend / dataMean @@ -256,7 +256,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Stores info needed to plot Periods_trend = append(Periods_trend, Periods) NPeriod_trend = append(NPeriod_trend, j) - Type_trend = append(Type_trend, type) + Var_trend = append(Var_trend, var) Code_trend = append(Code_trend, code) Pthresold_trend = append(Pthresold_trend, Pthresold) TrendMean_trend = append(TrendMean_trend, trendMean) @@ -272,7 +272,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Blank vectors to store info about breaking analysis Periods_mean = c() NPeriod_mean = c() - Type_mean = list() + Var_mean = list() Code_mean = c() DataMean_mean = c() BreakMean_mean = c() @@ -302,7 +302,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # the current variable df_data = list_df2plot[[i]]$data # Extract the variable of the plot - type = list_df2plot[[i]]$type + var = list_df2plot[[i]]$var # Extracts the data corresponding to the code df_data_code = df_data[df_data$code == code,] @@ -323,7 +323,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice sep=' / ') # Mean of the flow over the sub period - dataMean = mean(df_data_code_per$Qm3s, + dataMean = mean(df_data_code_per$Value, na.rm=TRUE) # If this in not the first period @@ -346,7 +346,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Stores info needed to plot Periods_mean = append(Periods_mean, Periods) NPeriod_mean = append(NPeriod_mean, j) - Type_mean = append(Type_mean, type) + Var_mean = append(Var_mean, var) Code_mean = append(Code_mean, code) DataMean_mean = append(DataMean_mean, dataMean) BreakMean_mean = append(BreakMean_mean, @@ -435,7 +435,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Extracts those info subPeriods_trend = Periods_trend[CodefL_trend] subNPeriod_trend = NPeriod_trend[CodefL_trend] - subType_trend = Type_trend[CodefL_trend] + subVar_trend = Var_trend[CodefL_trend] subCode_trend = Code_trend[CodefL_trend] subPthresold_trend = Pthresold_trend[CodefL_trend] subTrendMean_trend = TrendMean_trend[CodefL_trend] @@ -448,7 +448,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Extracts right info subPeriods_mean = Periods_mean[CodefL_mean] subNPeriod_mean = NPeriod_mean[CodefL_mean] - subType_mean = Type_mean[CodefL_mean] + subVar_mean = Var_mean[CodefL_mean] subCode_mean = Code_mean[CodefL_mean] subDataMean_mean = DataMean_mean[CodefL_mean] subBreakMean_mean = BreakMean_mean[CodefL_mean] @@ -500,8 +500,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice subPeriods_trend[subNPeriod_trend == j] NPeriods_trend_per = subNPeriod_trend[subNPeriod_trend == j] - Type_trend_per = - subType_trend[subNPeriod_trend == j] + Var_trend_per = + subVar_trend[subNPeriod_trend == j] Code_trend_per = subCode_trend[subNPeriod_trend == j] Pthresold_trend_per = @@ -517,7 +517,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Converts the vector of hydrological variable to # a vector of integer associated to those variable - Xtmp = as.integer(factor(as.character(Type_trend_per))) + Xtmp = as.integer(factor(as.character(Var_trend_per))) # Computes X position of the column for the period dates Xc = j + (j - 1)*nbp*2 # Computes X positions of columns for the mean of @@ -620,11 +620,11 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # For all variable for (i in 1:nbp) { # Extract the variable of the plot - type = list_df2plot[[i]]$type + var = list_df2plot[[i]]$var mat = mat + # Writes the type of the variable annotate('text', x=X[i], y=max(Y) + 0.82, - label=bquote(.(type)), + label=bquote(.(var)), hjust=0.5, vjust=0.5, size=3.25, color='grey20') + # Writes the unit of the variable @@ -634,7 +634,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice size=2, color='grey40') + # Writes the type of the averaged variable annotate('text', x=Xm[i], y=max(Y) + 0.82, - label=bquote('µ'*.(type)), + label=bquote('µ'*.(var)), hjust=0.5, vjust=0.5, size=3.25, color='grey20') + # Writes the unit of the averaged variable @@ -678,8 +678,8 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice subPeriods_mean[subNPeriod_mean == j] NPeriods_mean_per = subNPeriod_mean[subNPeriod_mean == j] - Type_mean_per = - subType_mean[subNPeriod_mean == j] + Var_mean_per = + subVar_mean[subNPeriod_mean == j] Code_mean_per = subCode_mean[subNPeriod_mean == j] DataMean_mean_per = @@ -693,7 +693,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Converts the vector of hydrological variable to # a vector of integer associated to those variable - Xtmp_mean = as.integer(factor(as.character(Type_mean_per))) + Xtmp_mean = as.integer(factor(as.character(Var_mean_per))) # Computes X position of the column for the period dates Xc_mean = j + (j - 1)*nbp + X[length(X)] # Computes X positions of columns for the mean of @@ -818,11 +818,11 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # For all variables for (i in 1:nbp) { # Extract the variable of the plot - type = list_df2plot[[i]]$type + var = list_df2plot[[i]]$var mat = mat + # Writes the type of the averaged variable annotate('text', x=Xm_mean[i], y=max(Y) + 0.82, - label=bquote('µ'*.(type)), + label=bquote('µ'*.(var)), hjust=0.5, vjust=0.5, size=3.25, color='grey20') + # Writes the unit of the averaged variable @@ -837,7 +837,7 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # Writes the type of the breaking variable annotate('text', x=Xr_mean[i], y=max(Y) + 0.82, - label=bquote('d'*.(type)), + label=bquote('d'*.(var)), hjust=0.5, vjust=0.5, size=3.25, color='grey20') + # Writes the unit of the breaking variable diff --git a/processing/analyse.R b/processing/analyse.R index a56cf5741fd4a204db398c3a6b17e29c12790dcc..9e8eb65ba0f4292107c600aeffc4e26d389bf05e 100644 --- a/processing/analyse.R +++ b/processing/analyse.R @@ -80,7 +80,7 @@ get_intercept = function (df_Xtrend, df_Xlist, unit2day=365.25) { & df_Xtrend$period_end == End[i]) # Compute mean of flow and time period - mu_X = mean(df_data_code_per$Qm3s, na.rm=TRUE) + mu_X = mean(df_data_code_per$Value, na.rm=TRUE) mu_t = as.numeric(mean(c(Start[i], End[i]), na.rm=TRUE)) / unit2day @@ -223,7 +223,7 @@ get_VCN10trend = function (df_data, df_meta, period, p_thresold) { df_data_code = tibble(Date=rollmean(df_data_code$Date, 10, fill=NA), - Qm3s=rollmean(df_data_code$Qm3s, + Value=rollmean(df_data_code$Value, 10, fill=NA), code=c) @@ -291,7 +291,7 @@ get_dateVCN10trend = function (df_data, df_meta, period, p_thresold) { df_data_code = df_data[df_data$code == c,] # Perform the roll mean of the flow over 10 days df_data_code = tibble(Date=df_data_code$Date, - Qm3s=rollmean(df_data_code$Qm3s, + Value=rollmean(df_data_code$Value, 10, fill=NA), code=c) @@ -365,10 +365,10 @@ get_break = function (df_data, df_meta, p_thresold=0.05) { # Get the associated data df_data_code = df_data[df_data$code == code,] # Remove NA data - df_data_codeNoNA = df_data_code[!is.na(df_data_code$Qm3s),] + df_data_codeNoNA = df_data_code[!is.na(df_data_code$Value),] # Perform the break analysis thanks to the Pettitt test - res_break = pettitt.test(df_data_codeNoNA$Qm3s) + res_break = pettitt.test(df_data_codeNoNA$Value) # Extract p value p_value = res_break$p @@ -386,8 +386,8 @@ get_break = function (df_data, df_meta, p_thresold=0.05) { df_data_codeNoNA$Date[ibreak]) Code_break = append(Code_break, code) } - # step1 = mean(df_data_codeNoNA$Qm3s[1:ibreak]) - # step2 = mean(df_data_codeNoNA$Qm3s[(ibreak+1):nbreak]) + # step1 = mean(df_data_codeNoNA$Value[1:ibreak]) + # step2 = mean(df_data_codeNoNA$Value[(ibreak+1):nbreak]) } # Create a tibble with the break analysis results df_break = tibble(code=Code_break, Date=as.Date(date_break)) diff --git a/processing/extract.R b/processing/extract.R index 20e36435b13e4a3dc92690fdf83b3d02f2d928aa..1207e0457ae43615c4421044d1ac6b086e1a4b01 100644 --- a/processing/extract.R +++ b/processing/extract.R @@ -457,7 +457,7 @@ extract_data = function (computer_data_path, filedir, filename, # of the station df_data = tibble(Date=as.Date(as.character(df_data$Date), format="%Y%m%d"), - Qm3s=df_data$Qls * 1E-3, + Value=df_data$Qls * 1E-3, df_data[-1:-2], code=code) return (df_data) diff --git a/processing/format.R b/processing/format.R index c0a5de02aa873d96a79d68142185d1bcacab00b2..1068f9857d513ab6622dba3f5fd08c4028455845 100644 --- a/processing/format.R +++ b/processing/format.R @@ -51,7 +51,7 @@ prepare = function(df_data, colnamegroup=NULL) { # Creates a new tibble of data with a group column data = tibble(Date=df_data$Date, group=group_indices(df_data), - Qm3s=df_data$Qm3s) + Value=df_data$Value) # Gets the different value of the group Gkey = group_keys(df_data) @@ -73,7 +73,7 @@ reprepare = function(df_XEx, df_Xlist, colnamegroup=NULL) { # Changes the column name of the results of the # 'extract.Var' function - colnames(df_XEx) = c('Date', 'group', 'Qm3s') + colnames(df_XEx) = c('Date', 'group', 'Value') # Converts Date column as character df_XEx$Date = as.character(df_XEx$Date) diff --git a/script.R b/script.R index e4f30aa9b3a5f25a7ff3e5d77c03fdf4df424403..037d0c2d9886bf4fc372eb4a888455720c1d376c 100644 --- a/script.R +++ b/script.R @@ -57,19 +57,19 @@ filedir = filename = # "" - c( - "S2235610_HYDRO_QJM.txt", - "P1712910_HYDRO_QJM.txt", - "P0885010_HYDRO_QJM.txt", - "O5055010_HYDRO_QJM.txt", - "O0384010_HYDRO_QJM.txt" - ) - # c( + # "S2235610_HYDRO_QJM.txt", + # "P1712910_HYDRO_QJM.txt", + # "P0885010_HYDRO_QJM.txt", + # "O5055010_HYDRO_QJM.txt", + # "O0384010_HYDRO_QJM.txt" + # ) + + c( # "S4214010_HYDRO_QJM.txt" # "O0384010_HYDRO_QJM.txt", - # "Q7002910_HYDRO_QJM.txt" - # ) + "Q7002910_HYDRO_QJM.txt" + ) @@ -274,7 +274,7 @@ df_shapefile = ini_shapefile(computer_data_path, # layout_matrix=c(1, 2), # df_meta=df_meta, # missRect=list(TRUE, TRUE), - # type=list('Q', 'sqrt(Q)'), + # var=list('Q', 'sqrt(Q)'), # info_header=TRUE, # time_header=NULL, # var_ratio=3, @@ -296,7 +296,8 @@ datasheet_layout(isplot=c( res_QMNAtrend$trend, res_VCN10trend$trend, res_dateVCN10trend$trend), - type=list('QA', 'QMNA', 'VCN10', 'VCN10 date'), + var=list('QA', 'QMNA', 'VCN10', 'date du VCN10'), + type=list('flow', 'flow', 'flow', 'date'), layout_matrix=matrix(c(1, 2, 3, 4), ncol=1),