-
Notifications
You must be signed in to change notification settings - Fork 1
/
script_create.R
137 lines (111 loc) · 5.56 KB
/
script_create.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Copyright 2022-2024 Louis Héraut ([email protected])*1,
# Éric Sauquet ([email protected])*1,
# Michel Lang ([email protected])*1,
# Jean-Philippe Vidal ([email protected])*1,
# Benjamin Renard ([email protected])*1
#
# *1 INRAE, France
#
# This file is part of MAKAHO R shiny app.
#
# MAKAHO R shiny app is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# MAKAHO R shiny app is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MAKAHO R shiny app.
# If not, see <https://www.gnu.org/licenses/>.
## 0. LIBRARY _________________________________________________________
library(stringr)
library(dplyr)
## 1. PATH ___________________________________________________________
computer_data_path = '/home/louis/Documents/bouleau/INRAE/data/'
MAKAHO_data_path = "data"
## 2. RRSE ___________________________________________________________
data_RRSE_path = file.path(MAKAHO_data_path, 'fst', 'data_RRSE.fst')
meta_RRSE_path = file.path(MAKAHO_data_path, 'fst', 'meta_RRSE.fst')
if (!file.exists(data_RRSE_path) | !file.exists(meta_RRSE_path)) {
data_RRSE = create_data_HYDRO(computer_data_path,
file.path(hydrologie, "RRSE"),
"all")
meta_RRSE = create_meta_HYDRO(computer_data_path,
file.path(hydrologie, "RRSE"),
"all")
meta_RRSE = get_lacune(data_RRSE, meta_RRSE)
# hydrograph
write_tibble(data_RRSE,
filedir=file.path(MAKAHO_data_path, 'fst'),
filename='data_RRSE.fst')
write_tibble(meta_RRSE,
filedir=file.path(MAKAHO_data_path, 'fst'),
filename='meta_RRSE.fst')
}
## 3. Explore2 _______________________________________________________
NC_path = "/home/louis/Documents/bouleau/INRAE/data/Explore2/hydrologie/diagnostic/SMASH_20230303.nc"
tools_path = "/home/louis/Documents/bouleau/INRAE/project/Explore2_project/Explore2_toolbox/tools.R"
codes_hydro_selection_path = file.path(computer_data_path, "Explore2", "hydrologie", "Selection_points_simulation_V20230510.txt")
codes_hydro_check_security_path = file.path(computer_data_path, "Explore2", "hydrologie", "Selection_stations_EDF_def.csv")
data_Explore2_path = file.path(MAKAHO_data_path, 'fst',
'data_Explore2.fst')
meta_Explore2_path = file.path(MAKAHO_data_path, 'fst',
'meta_Explore2.fst')
if (!file.exists(data_Explore2_path) |
!file.exists(meta_Explore2_path)) {
codes_selection_data = read_tibble(codes_hydro_selection_path)
codes_selection_data = dplyr::filter(codes_selection_data,
!grepl("Supprimer", X))
secure_codes =
as.character(read.csv2(codes_hydro_check_security_path)$CODE)
### /!\ ###
codes_selection_data =
codes_selection_data[!(codes_selection_data$CODE %in%
secure_codes),]
###########
codes_selection_data =
codes_selection_data[codes_selection_data$Référence %in% 1,]
codes8_selection = codes_selection_data$CODE
codes10_selection = codes_selection_data$SuggestionCode
codes8_selection = codes8_selection[!is.na(codes8_selection)]
codes10_selection = codes10_selection[!is.na(codes10_selection)]
CodeSUB8 = codes8_selection
CodeSUB10 = codes10_selection
source(tools_path)
data_sim = NetCDF_to_tibble(NC_path,
chain="SMASH",
type="hydrologie",
mode="diagnostic")
data_sim$Code = convert_codeNtoM(data_sim$Code, N=10, M=8)
Code = levels(factor(data_sim$Code))
Code_filename = paste0(Code, "_HYDRO_QJM.txt")
meta_Explore2 = create_meta_HYDRO(
computer_data_path,
"Explore2/hydrologie/Explore2 HYDRO QJM critiques 2023",
Code_filename,
verbose=FALSE)
data_obs = create_data_HYDRO(
computer_data_path,
"Explore2/hydrologie/Explore2 HYDRO QJM critiques 2023",
Code_filename,
val2keep=c(val_E2=0),
verbose=FALSE)
data_obs = dplyr::arrange(data_obs, Code)
meta_Explore2 = get_lacune(data_obs, meta_Explore2)
data_Explore2 = dplyr::inner_join(data_obs,
dplyr::select(data_sim,
c("Code", "Date",
"P", "Pl", "Ps", "T")),
by=c("Code", "Date"))
# hydrograph
write_tibble(data_Explore2,
filedir=file.path(MAKAHO_data_path, 'fst'),
filename='data_Explore2.fst')
write_tibble(meta_Explore2,
filedir=file.path(MAKAHO_data_path, 'fst'),
filename='meta_Explore2.fst')
}