diff --git a/plotting/map.R b/plotting/map.R index 257bc7abacac12dda2b94cb99e22c2c6a5b13069..cdba53ce6c316e2f16a97824249bc411e525b4c1 100644 --- a/plotting/map.R +++ b/plotting/map.R @@ -69,46 +69,53 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' } } - # Blank list to store time info by station code - Start_code = vector(mode='list', length=nCode) - End_code = vector(mode='list', length=nCode) - Code_code = vector(mode='list', length=nCode) - Periods_code = vector(mode='list', length=nCode) - # For all the code - for (j in 1:nCode) { + tab_Start = array(rep('', nCode*nbp*nPeriod_max), + dim=c(nCode, nbp, nPeriod_max)) + tab_End = array(rep('', nCode*nbp*nPeriod_max), + dim=c(nCode, nbp, nPeriod_max)) + tab_Code = array(rep('', nCode*nbp*nPeriod_max), + dim=c(nCode, nbp, nPeriod_max)) + tab_Periods = array(rep('', nCode*nbp*nPeriod_max), + dim=c(nCode, nbp, nPeriod_max)) + + # For all code + for (k in 1:nCode) { # Gets the code - code = Code[j] - # Extracts the trend corresponding to the code - df_trend_code = df_trend[df_trend$code == code,] + code = Code[k] - # Extract start and end of trend periods - Start = df_trend_code$period_start - End = df_trend_code$period_end - # Get the name of the different period - UStart = levels(factor(Start)) - UEnd = levels(factor(End)) - - # Compute the max of different start and end - # so the number of different period - nPeriod = max(length(UStart), length(UEnd)) - - # Vector to store trend period - Periods = c() - # For all the period - for (i in 1:nPeriod_max) { - # Stocks period - Periods = append(Periods, - paste(substr(Start[i], 1, 4), - substr(End[i], 1, 4), - sep=' / ')) + for (i in 1:nbp) { + df_trend = list_df2plot[[i]]$trend + # Extracts the trend corresponding to the code + df_trend_code = df_trend[df_trend$code == code,] + + # Extract start and end of trend periods + Start = df_trend_code$period_start + End = df_trend_code$period_end + # Get the name of the different period + UStart = levels(factor(Start)) + UEnd = levels(factor(End)) + + # Compute the max of different start and end + # so the number of different period + nPeriod = max(length(UStart), length(UEnd)) + + # For all the period + for (j in 1:nPeriod_max) { + # Stocks period + Periods = paste(Start[j], + End[j], + sep=' / ') + + tab_Start[k, i, j] = as.character(Start[j]) + tab_End[k, i, j] = as.character(End[j]) + tab_Code[k, i, j] = code + tab_Periods[k, i, j] = Periods + + } } - # Stores time info by station - Start_code[[j]] = Start - End_code[[j]] = End - Code_code[[j]] = code - Periods_code[[j]] = Periods } + # Blank array to store mean of the trend for each # station, perdiod and variable TrendMean_code = array(rep(1, nPeriod_max*nbp*nCode), @@ -134,9 +141,9 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' df_trend_code = df_trend[df_trend$code == code,] # Gets the associated time info - Start = Start_code[Code_code == code][[1]][j] - End = End_code[Code_code == code][[1]][j] - Periods = Periods_code[Code_code == code][[1]][j] + Start = tab_Start[k, i, j] + End = tab_End[k, i, j] + Periods = tab_Periods[k, i, j] # Extracts the corresponding data for the period df_data_code_per = @@ -334,7 +341,9 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' trend = c() p_threshold_Ok = c() # For all code - for (code in Code) { + for (k in 1:nCode) { + # Gets the code + code = Code[k] # Extracts the data corresponding to the current variable df_data = list_df2plot[[i]]$data # Extracts the trend corresponding to the @@ -347,8 +356,13 @@ map_panel = function (list_df2plot, df_meta, df_shapefile, idPer=1, outdirTmp='' df_trend_code = df_trend[df_trend$code == code,] # Gets the associated time info - Start = Start_code[Code_code == code][[1]][idPer] - End = End_code[Code_code == code][[1]][idPer] + # Start = Start_code[Code_code == code][[1]][idPer] + # End = End_code[Code_code == code][[1]][idPer] + + # Gets the associated time info + Start = tab_Start[k, i, idPer] + End = tab_End[k, i, idPer] + Periods = tab_Periods[k, i, idPer] # Extracts the corresponding data for the period df_data_code_per = diff --git a/plotting/matrix.R b/plotting/matrix.R index c043b1882b83049c4ad1ee0f324a19eccc9bd9e2..6b50d4f2f89eda31f6ed2d75ed4783f723157082 100644 --- a/plotting/matrix.R +++ b/plotting/matrix.R @@ -70,44 +70,53 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice } } - # Blank list to store time info by station code - Start_code = vector(mode='list', length=nCode) - End_code = vector(mode='list', length=nCode) - Code_code = vector(mode='list', length=nCode) - Periods_code = vector(mode='list', length=nCode) - # For all the code - for (j in 1:nCode) { + tab_Start = array(rep('', nCode*nbp*nPeriod_max), + dim=c(nCode, nbp, nPeriod_max)) + tab_End = array(rep('', nCode*nbp*nPeriod_max), + dim=c(nCode, nbp, nPeriod_max)) + tab_Code = array(rep('', nCode*nbp*nPeriod_max), + dim=c(nCode, nbp, nPeriod_max)) + tab_Periods = array(rep('', nCode*nbp*nPeriod_max), + dim=c(nCode, nbp, nPeriod_max)) + + # For all code + for (k in 1:nCode) { # Gets the code - code = Code[j] - # Extracts the trend corresponding to the code - df_trend_code = df_trend[df_trend$code == code,] - - # Extract start and end of trend periods - Start = df_trend_code$period_start - End = df_trend_code$period_end - # Get the name of the different period - UStart = levels(factor(Start)) - UEnd = levels(factor(End)) - - # Compute the max of different start and end - # so the number of different period - nPeriod = max(length(UStart), length(UEnd)) - # Vector to store trend period - Periods = c() - # For all the trend period - for (i in 1:nPeriod_trend) { - # Stocks period - Periods = append(Periods, - paste(Start[i], - End[i], - sep=' / ')) + code = Code[k] + + for (i in 1:nbp) { + df_trend = list_df2plot[[i]]$trend + # Extracts the trend corresponding to the code + df_trend_code = df_trend[df_trend$code == code,] + + # Extract start and end of trend periods + Start = df_trend_code$period_start + End = df_trend_code$period_end + # Get the name of the different period + UStart = levels(factor(Start)) + UEnd = levels(factor(End)) + + # Compute the max of different start and end + # so the number of different period + nPeriod = max(length(UStart), length(UEnd)) + + # For all the period + for (j in 1:nPeriod_max) { + # Stocks period + Periods = paste(Start[j], + End[j], + sep=' / ') + + tab_Start[k, i, j] = as.character(Start[j]) + tab_End[k, i, j] = as.character(End[j]) + tab_Code[k, i, j] = code + tab_Periods[k, i, j] = Periods + + } } - # Stores time info by station - Start_code[[j]] = Start - End_code[[j]] = End - Code_code[[j]] = code - Periods_code[[j]] = Periods } + + # Blank array to store mean of the trend for each # station, perdiod and variable @@ -134,9 +143,9 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice df_trend_code = df_trend[df_trend$code == code,] # Gets the associated time info - Start = Start_code[Code_code == code][[1]][j] - End = End_code[Code_code == code][[1]][j] - Periods = Periods_code[Code_code == code][[1]][j] + Start = tab_Start[k, i, j] + End = tab_End[k, i, j] + Periods = tab_Periods[k, i, j] # Extracts the corresponding data for the period df_data_code_per = @@ -191,7 +200,9 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice # For all the trend period for (j in 1:nPeriod_trend) { # For all code - for (code in Code) { + for (k in 1:nCode) { + # Gets the code + code = Code[k] # For all variable for (i in 1:nbp) { # Extracts the data corresponding to the current variable @@ -210,9 +221,9 @@ matrix_panel = function (list_df2plot, df_meta, trend_period, mean_period, slice df_trend_code = df_trend[df_trend$code == code,] # Gets the associated time info - Start = Start_code[Code_code == code][[1]][j] - End = End_code[Code_code == code][[1]][j] - Periods = Periods_code[Code_code == code][[1]][j] + Start = tab_Start[k, i, j] + End = tab_End[k, i, j] + Periods = tab_Periods[k, i, j] # Extracts the corresponding data for the period df_data_code_per = diff --git a/processing/analyse.R b/processing/analyse.R index cda2470bdfec193ef759cccdfb51b0202d4da69b..b8ae689e56e9c0616f166203f653ae862acdc0c3 100644 --- a/processing/analyse.R +++ b/processing/analyse.R @@ -320,6 +320,7 @@ get_tINItrend = function (df_data, df_meta, period, p_thresold) { for (k in 1:nCode) { # Gets the code code = Code[k] + # print(code) per.start = df_meta$start_year[df_meta$code == code] per.start = paste(sprintf("%02d", per.start), '-01', sep='') @@ -387,18 +388,22 @@ get_tINItrend = function (df_data, df_meta, period, p_thresold) { per.start=per.start) # print('hh') + # print(df_tINIEx_code) # Store the results - df_tINIEx = bind_rows(df_tINIEx, df_tINIEx_code) + df_tINIEx = bind_rows(df_tINIEx, df_tINIEx_code) df_tINIlist$data = bind_rows(df_tINIlist$data, df_tINIlist_code$data) + df_tINIlist$info = bind_rows(df_tINIlist$info, df_tINIlist_code$info) # print('ii') } + + # print('11') # Compute the trend analysis df_tINItrend = Estimate.stats(data.extract=df_tINIEx, @@ -414,7 +419,7 @@ get_tINItrend = function (df_data, df_meta, period, p_thresold) { df_tINIExB = df_tINIEx } - print(per.start) + # print(per.start) # Specify the period of analyse df_tINItrend = get_period(per, df_tINItrend, df_tINIEx, diff --git a/processing/format.R b/processing/format.R index fde65227d705f8194503192f024b2373cee39d10..a46934fef19d3fd7853a0602238fb6738f40bb69 100644 --- a/processing/format.R +++ b/processing/format.R @@ -169,6 +169,8 @@ prepare_date = function(df_XEx, df_Xlist, per.start="01-01") { df_XEx$values[OkXEx_code] = XEx_code } + df_XEx$datetime = as.double(df_XEx$datetime) + return (df_XEx) } @@ -294,11 +296,11 @@ get_period = function (per, df_Xtrend, df_XEx, df_Xlist) { iStart = which.min(abs(DateStart - as.Date(per[1]))) iEnd = which.min(abs(DateEnd - as.Date(per[2]))) - print(nrow(df_XEx)) - print(as.Date(DateStart[iStart])) - print(head(df_XEx)) - print(tail(df_XEx)) - print(as.Date(DateEnd[iEnd])) + # print(nrow(df_XEx)) + # print(as.Date(DateStart[iStart])) + # print(head(df_XEx)) + # print(tail(df_XEx)) + # print(as.Date(DateEnd[iEnd])) # Stores the start and end of the trend analysis df_Xtrend$period_start[id] = as.Date(DateStart[iStart]) diff --git a/script.R b/script.R index 8a1f5805f75ea37376a92e0af7d6f743483bcd9a..db71de4bc7e11166aec1d4bc0dcf868eabb1f8bb 100644 --- a/script.R +++ b/script.R @@ -58,13 +58,15 @@ filename = # "" 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" + # "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", + "O3035210_HYDRO_QJM.txt", + "O3121010_HYDRO_QJM.txt" ) @@ -286,8 +288,8 @@ df_shapefile = ini_shapefile(computer_data_path, ### 4.2. Analysis layout datasheet_layout(toplot=c( - 'datasheet' - # 'matrix', + # 'datasheet', + 'matrix', # 'map' ), df_meta=df_meta,