-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_extraction.R
111 lines (96 loc) · 3.81 KB
/
script_extraction.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
# Copyright 2021-2023 Louis Héraut (louis.heraut@inrae.fr)*1,
# Éric Sauquet (eric.sauquet@inrae.fr)*1
#
# *1 INRAE, France
#
# This file is part of Explore2 R toolbox.
#
# Explore2 R toolbox 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.
#
# Explore2 R toolbox 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 Explore2 R toolbox.
# If not, see <https://www.gnu.org/licenses/>.
CARD_extract_data = function () {
data = ASHE::read_tibble(filedir=tmppath,
filename=paste0("data", sep,
files_name_opt.,
subset_name, ".fst"))
meta = ASHE::read_tibble(filedir=tmppath,
filename=paste0("meta", sep,
files_name_opt.,
subset_name, ".fst"))
if (type == "piezometrie") {
data = dplyr::rename(data, Q_obs=H_obs, Q_sim=H_sim)
}
for (i in 1:length(extract_data)) {
extract = extract_data[[i]]
CARD_management(CARD=CARD_path,
tmp=tmppath,
layout=c(paste0(extract$name, "_", rank), "[",
extract$variables, "]"),
overwrite=TRUE,
verbose=subverbose)
if (extract$type == "criteria") {
simplify = TRUE
expand = FALSE
} else if (extract$type == "serie") {
simplify = FALSE
if ("expand" %in% names(extract)) {
expand = extract$expand
} else {
expand = TRUE
}
}
if (grepl("diagnostic", mode)) {
cancel_lim = TRUE
} else if (grepl("projection", mode)) {
cancel_lim = FALSE
}
if (isSim & !isObs) {
suffix = NULL
} else {
suffix = extract$suffix
}
res = CARD_extraction(data,
CARD_path=CARD_path,
CARD_tmp=tmppath,
CARD_dir=paste0(extract$name, "_", rank),
period_default=period_extract,
simplify=simplify,
suffix=suffix,
expand_overwrite=expand,
cancel_lim=cancel_lim,
rm_duplicates=TRUE,
dev=FALSE,
verbose=subverbose)
ASHE::write_tibble(res$dataEX,
filedir=tmppath,
filename=paste0("dataEX_", extract$name, sep,
files_name_opt.,
subset_name, ".fst"))
ASHE::write_tibble(res$metaEX,
filedir=tmppath,
filename=paste0("metaEX_", extract$name, sep,
files_name_opt.,
subset_name, ".fst"))
rm ("res")
gc()
}
rm ("data")
gc()
rm ("meta")
gc()
}
## 1. EXTRACTION OF DATA ______________________________________________
if ('extract_data' %in% to_do) {
ASHE::post("### Extracting data")
CARD_extract_data()
}