diff --git a/processing/extractBH.R b/processing/extractBH.R index e2e45a62d57528674b07cee52ee210d1441c7ea7..2c841d4c5f4f5ad87858825c7662819d3540d477 100644 --- a/processing/extractBH.R +++ b/processing/extractBH.R @@ -157,7 +157,7 @@ extractBH_info = function (computer_data_path, filedir, filename, verbose=TRUE) # Print information if asked if (verbose) { - print(paste("extraction of info for file :", filename)) + print(paste("extraction of BH info for file :", filename)) } # Get the file path to the data @@ -257,7 +257,7 @@ extractBH_data = function (computer_data_path, filedir, filename, verbose=TRUE) # Print information if asked if (verbose) { - print(paste("extraction of data for file :", filename)) + print(paste("extraction of BH data for file :", filename)) } # Get the file path to the data diff --git a/processing/extractNV.R b/processing/extractNV.R index 4bb8d7cddc814a15e3bb9812321c87c4297373e7..72abcd0d479bcca31dba1215bcdbd8837d603e1b 100644 --- a/processing/extractNV.R +++ b/processing/extractNV.R @@ -8,7 +8,7 @@ extractNVlist_info = function (computer_data_path, filedir, listdir, listname, v # Print information if asked if (verbose) { - print(paste("extraction of info for file :", listname)) + print(paste("extraction of NV info for file :", listname)) } # Get the file path to the data @@ -20,9 +20,11 @@ extractNVlist_info = function (computer_data_path, filedir, listdir, listname, v # Create a filelist to store all the filename codelist = c() + + dir_path = file.path(computer_data_path, filedir) + # Get all the filename in the data directory selected - filelist_tmp = list.files(file.path(computer_data_path, - filedir)) + filelist_tmp = list.files(dir_path) # For all the filename in the directory selected for (f in filelist_tmp) { @@ -35,7 +37,7 @@ extractNVlist_info = function (computer_data_path, filedir, listdir, listname, v exist = df_info$CODE %in% codelist missing = codelist[!(codelist %in% df_info$CODE)] - print(paste('station missing :', missing)) + print(paste('missing station info for :', missing)) df_info = df_info[exist,] @@ -47,18 +49,26 @@ extractNVlist_info = function (computer_data_path, filedir, listdir, listname, v L93Y=df_info$Y_L2E, surface_km2=df_info$S_km2, altitude_m=df_info$Alt, - file_path=paste(df_info$CODE, '.txt', sep='') + file_path=file.path(dir_path, + paste(df_info$CODE, '.txt', sep='')) ) + df_info = bind_rows(df_info, + data.frame(code=missing, + file_path=file.path(dir_path, + paste(missing, + '.txt', + sep='')))) + return (df_info) } # Example -# df_info = extractNVlist_info( -# "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data", -# 'France207', -# '', -# 'liste_bv_principaux_global.txt') +df_info = extractNVlist_info( + "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data", + 'France207', + '', + 'liste_bv_principaux_global.txt') # Extraction of data @@ -115,7 +125,7 @@ extractNV_data = function (computer_data_path, filedir, filename, verbose=TRUE) # Print information if asked if (verbose) { - print(paste("extraction of data for file :", filename)) + print(paste("extraction of NV data for file :", filename)) } # Get the file path to the data diff --git a/script.R b/script.R index ab8f9e0426f67a87ebc9ec1ce4433cfc61187112..960d7266b9a576f7777575a9e93a1ab8fea1af07 100644 --- a/script.R +++ b/script.R @@ -1,6 +1,7 @@ ###### A MODIFIER ###### + # Path to the data computer_data_path = "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/data" @@ -11,32 +12,46 @@ computer_work_path = "/home/louis/Documents/bouleau/INRAE/CDD_stationnarite/ASH" # "C:\\Users\\louis.heraut\\Documents\\CDD_stationnarite\\ASH" + ### BANQUE HYDRO ### -## Manual selection ## -# Path to data that will be analysed from the BanqueHydro +# Path to the directory where BH data is stored BHfiledir = - FALSE # "test" - # "BanqueHydro_Export2021" + "BanqueHydro_Export2021" + +## Manual selection ## +# Name of the file that will be analysed from the BH directory BHfilename = FALSE # c("H5920011_HYDRO_QJM.txt", "K4470010_HYDRO_QJM.txt") # "all" ## Or list selection ## -# Path to the list file of station that will be analysed +# Path to the list file of BH data that will be analysed BHlistdir = # FALSE "" + BHlistname = # FALSE "Liste-station_RRSE.docx" -BHdatadir = - # FALSE - "BanqueHydro_Export2021" + ### NIVALE ### +# Path to the directory where NV data is stored +NVfiledir = + "France207" + +# Name of the file that will be analysed from the NV directory +NVfilename = + "all" +# Path to the list file of information about station that will be analysed +NVlistdir = + "" + +NVlistname = + "liste_bv_principaux_global.txt" ######################## @@ -69,8 +84,9 @@ if (!(file.exists(figdir))) { print(paste('figdir :', figdir)) +# BANQUE HYDRO # # Get only the selected station from a list station file -if (is.character(BHlistdir) & is.character(BHlistname) & is.character(BHdatadir)){ +if (is.character(BHlistdir) & is.character(BHlistname) & is.character(BHfiledir)){ df_selec = get_selection(computer_data_path, BHlistdir, BHlistname, @@ -83,7 +99,7 @@ if (is.character(BHlistdir) & is.character(BHlistname) & is.character(BHdatadir) 'choix'), c_num=c('BV_km2', 'longueur_serie')) - BHfiledir = BHdatadir + BHfilename = df_selec[df_selec$ok,]$filename } @@ -93,9 +109,29 @@ df_info_BH = extractBH_info(computer_data_path, BHfiledir, BHfilename) # Extract data about selected stations df_data_BH = extractBH_data(computer_data_path, BHfiledir, BHfilename) + +# NIVALE # +# Extract information about selected stations +df_info_NV = extractNVlist_info(computer_data_path, NVfiledir, NVlistdir, NVlistname) +### /!\ missing station info + +# Extract data about selected stations +df_data_NV = extractNV_data(computer_data_path, NVfiledir, NVfilename) + + +common = levels(factor(df_info_NV[df_info_NV$code %in% df_info_BH$code,]$code)) +NVadd = levels(factor(df_info_NV[!(df_info_NV$code %in% df_info_BH$code),]$code)) + +df_info_NVadd = df_info_NV[df_info_NV$code %in% NVadd,] +df_info = full_join(df_info_BH, df_info_NVadd, by=c("code", "nom", "L93X", "L93Y", "surface_km2", "file_path")) + +df_data_NVadd = df_data_NV[df_data_NV$code %in% NVadd,] +df_data = full_join(df_data_BH, df_data_NVadd, by=c("Date", "Qm3s", "code")) + + # Plot time panel of debit by stations -panel(df_data_BH, df_info_BH, figdir, BHfiledir) -# panel(df_data_BH, df_info_BH, figdir, BHfiledir, is_sqrt=TRUE) +# panel(df_data, df_info, figdir, filedir) +# panel(df_data, df_info, figdir, filedir, is_sqrt=TRUE) # Compute gap parameters for stations -df_lac = get_lacune(df_data_BH, df_info_BH) +# df_lac = get_lacune(df_data, df_info)