/
running_processes_examples.Rmd
306 lines (285 loc) · 16.6 KB
/
running_processes_examples.Rmd
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
---
title: "Running processes examples"
output: rmarkdown::html_vignette
description: |
Description of running processes examples.
vignette: |
%\VignetteIndexEntry{Running processes examples}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::knitr}
editor_options:
chunk_output_type: console
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
<div style="text-align: justify">
## Process philosophy
The Topical Tuna Treatment (T3) aim to provide a support for the data manipulation of tropical tuna surface fisheries. This support can take many different forms and have various objectives associated. For that purpose, T3 can be processes in various ways, depending of what question(s) drive your reflexion. You will find below several examples for running process and help you regarding your personnal work. Furthermore, don't hesitate to take a look on the issues webpage of the package (https://github.com/OB7-IRD/t3/issues) or send a mail to ob7@ird.fr if you need specific support.
Furthermore, in the following functions the "database_con" argument refers to an R object which contains connection information with an avdth database. For more detail about connections available check the function documentation. In addition, the argument "output_path" refer to the output directory on your computer. The function associated, "initiate_directory", will create the output structure for the process.
## Running the process step by step
Globaly, the T3 process have 3 differents parts that you can run independently from each other. But in some case you could want to run the entire process step by step, for example to "follow" several particular data with accuracy. In the code below, you will find an example of all the process run step by step. The parameters associated are display in the section called "setup". You can modified them to customize the example. If you more information regarding functions arguments take à look to the R function documentation (or in the reference website section https://ob7-ird.github.io/t3/reference/index.html)
```{r echo=TRUE, eval=FALSE}
# setup ----
library(t3)
periode_reference <- as.integer(c(2006,
2007,
2008))
target_year <- as.integer(2008)
period_duration <- as.integer(2)
# countries for the France fleet
countries <- c("FRA",
"MYT")
# code 1 for the Atlantic Ocean
ocean <- as.integer(1)
# code 1 for landing data
sample_type <- as.integer(1)
# for french fleet YFT, SKJ, BET, ALB, MIX and LOT
species_rf1_fr <- as.integer(c(1, 2, 3, 4, 9, 11))
# output directories initiation
final_output_path <- initiate_directory(output_path = output_path,
level = "all")
# output format
output_format <- "eu"
# generation of the confidence interval
confidence_interval <- TRUE
# model creation ----
object_model_data <- t3:::object_model_data$new()
# object trips creation
object_model_data$trips_object_creation(data_source = "avdth_db",
periode_reference = periode_reference,
countries = countries,
oceans = ocean,
db_con = database_con)
# object activities creation
object_model_data$activities_object_creation(data_source = "avdth_db",
periode_reference = periode_reference,
countries = countries,
oceans = ocean,
db_con = database_con)
# object elementarycatches creation
object_model_data$elementarycatches_object_creation(data_source = "avdth_db",
periode_reference = periode_reference,
countries = countries,
oceans = ocean,
db_con = database_con)
# object elementarylandings creation
object_model_data$elementarylandings_object_creation(data_source = "avdth_db",
periode_reference = periode_reference,
countries = countries,
oceans = ocean,
db_con = database_con)
# object wells creation
object_model_data$wells_object_creation(data_source = "avdth_db",
periode_reference = periode_reference,
countries = countries,
oceans = ocean,
sample_type = sample_type,
db_con = database_con)
# model creation: set durations data
object_model_data$setdurationrefs_data(data_source = "csv",
data_path = system.file("setdurationrefs.csv",
package = "t3"),
periode_reference = periode_reference,
countries = countries)
# model creation: length steps data
object_model_data$lengthsteps_data(data_source = "csv",
data_path = system.file("lengthsteps.csv",
package = "t3"))
# model creation: sample sets data
object_model_data$samplesets_data(data_source = "avdth_db",
periode_reference = periode_reference,
countries = countries,
oceans = ocean,
db_con = database_con)
# model creation: length weight relationships data
object_model_data$lengthweightrelationships_data(data_source = "csv",
data_path = system.file("lengthweightrelationships.csv",
package = "t3"))
# initialisation object for full trips class
object_full_trips <- t3:::full_trips$new()
# object full_trip creation
object_full_trips$create_full_trips(object_trips = object_model_data$.__enclos_env__$private$trips)
# add activities to trips selected
object_full_trips$add_activities(object_activities = object_model_data$.__enclos_env__$private$activities)
# filter by reference year
object_full_trips$filter_by_time_period_reference(time_periode_reference = periode_reference)
# add elementarycatches to trips selected
object_full_trips$add_elementarycatches(object_elementarycatches = object_model_data$.__enclos_env__$private$elementarycatches)
# add elementarylandings to trips selected
object_full_trips$add_elementarylandings(object_elementarylandings = object_model_data$.__enclos_env__$private$elementarylandings)
# add well(s) and sample(s) to trip(s) selected
object_full_trips$add_wells_samples(object_wells = object_model_data$.__enclos_env__$private$wells)
# level 1 ---
# level 1.1: rf1
object_full_trips$rf1(species_rf1 = species_rf1_fr,
global_output_path = final_output_path,
output_format = output_format)
# level 1.2: rf2
object_full_trips$rf2(global_output_path = final_output_path,
output_format = output_format)
# level 1.3: logbook weigth categories conversion ----
object_full_trips$conversion_weigth_category(global_output_path = final_output_path,
output_format = output_format)
# level 1.4: set count
object_full_trips$set_count(global_output_path = final_output_path,
output_format = output_format)
# level 1.5: set duration
object_full_trips$set_duration(set_duration_ref = object_model_data$.__enclos_env__$private$setdurationrefs,
global_output_path = final_output_path,
output_format = output_format)
# level 1.6: time at sea
object_full_trips$time_at_sea(global_output_path = final_output_path,
output_format = output_format)
# level 1.7: fishing time
object_full_trips$fishing_time(global_output_path = final_output_path,
output_format = output_format)
# level 1.8: searching time
object_full_trips$searching_time(global_output_path = final_output_path,
output_format = output_format)
# level 2 ----
# level 2.1: sample length class ld1 to lf conversion
object_full_trips$sample_length_class_ld1_to_lf(length_step = object_model_data$.__enclos_env__$private$lengthsteps,
global_output_path = final_output_path,
output_format = output_format)
# level 2.2: sample number measured extrapolation
object_full_trips$sample_number_measured_extrapolation(global_output_path = final_output_path,
output_format = output_format)
# level 2.3: sample step length class standardisation
object_full_trips$sample_length_class_step_standardisation(global_output_path = final_output_path,
output_format = output_format)
# level 2.4: well set weight categories
object_full_trips$well_set_weigth_categories(sample_set = object_model_data$.__enclos_env__$private$samplesets,
global_output_path = final_output_path,
output_format = output_format)
# level 2.5: standardised sample creation
object_full_trips$standardised_sample_creation(global_output_path = final_output_path,
output_format = output_format)
# level 2.6: sample number standardisation
object_full_trips$standardised_sample_set_creation(length_weight_relationship_data = object_model_data$.__enclos_env__$private$lengthweightrelationships,
global_output_path = final_output_path,
output_format = output_format)
# level 2.7: raised factors determination
object_full_trips$raised_factors_determination(global_output_path = final_output_path,
output_format = output_format)
# level 2.8: samples number standardisation at set scale
object_full_trips$raised_standardised_sample_set(global_output_path = final_output_path,
output_format = output_format)
# level 3 ----
process_level3 <- object_full_trips$path_to_level3()
# level 3.1: data preparatory
process_level3 <- object_full_trips$data_preparatory(inputs_level3 = process_level3[[1]],
output_directory = final_output_path,
target_year = target_year,
period_duration = period_duration)
# level 3.2: random forest models ----
process_level3$output_level3_process2 <- object_full_trips$random_forest_models(output_level3_process1 = process_level3$output_level3_process1$data_lb_sample_screened$data4mod)
# level 3.3: models checking ----
process_level3$output_level3_process3 <- object_full_trips$models_checking(output_level3_process2 = process_level3$output_level3_process2,
output_directory = process_level3$output_directory)
# level 3.4: data formatting for predictions ----
process_level3$output_level3_process4 <- object_full_trips$data_formatting_for_predictions(inputs_level3 = process_level3$raw_inputs_level3,
output_level3_process1 = process_level3$output_level3_process1$data_lb_sample_screened$data4mod,
target_year = target_year)
# level 3.5: predictions ----
process_level3$output_level3_process5 <- object_full_trips$model_predictions(output_level3_process2 = process_level3$output_level3_process2,
output_level3_process4 = process_level3$output_level3_process4,
output_directory = process_level3$output_directory,
ci = confidence_interval)
```
## Shortcut functions
Through the following codes, you will be able to run separely each part of the treatment.
```{r echo=TRUE, eval=FALSE}
# setup ----
library(t3)
periode_reference <- as.integer(c(2006,
2007,
2008))
target_year <- as.integer(2008)
period_duration <- as.integer(2)
# countries for the France fleet
countries <- c("FRA",
"MYT")
# code 1 for the Atlantic Ocean
ocean <- as.integer(1)
# code 1 for landing data
sample_type <- as.integer(1)
# for french fleet YFT, SKJ, BET, ALB, MIX and LOT
species_rf1 <- as.integer(c(1, 2, 3, 4, 9, 11))
# output directories initiation
final_output_path <- initiate_directory(output_path = output_path,
level = "all")
# output format
output_format <- "eu"
# generation of the confidence interval
confidence_interval <- TRUE
# data model initialisation ----
t3_process <- t3::data_model_initialisation(data_source = "avdth_db",
db_con = database_con,
periode_reference = periode_reference,
countries = countries,
oceans = ocean,
sample_type = sample_type)
# level 1 ----
t3_process[[2]] <- t3::t3_level1(object_model_data = t3_process[[1]],
object_full_trips = t3_process[[2]],
species_rf1 = species_rf1,
output_path = final_output_path,
output_format = output_format)
# level 2 ----
t3_process[[2]] <- t3::t3_level2(object_model_data = t3_process[[1]],
object_full_trips = t3_process[[2]],
output_path = final_output_path,
output_format = output_format)
# level 3 ----
t3_process[[3]] <- t3_process$object_full_trips$path_to_level3()
names(t3_process)[3] <- "process_level3"
t3_process[[3]] <- t3::t3_level3(inputs_level3 = t3_process[[3]][[1]],
target_year = target_year,
period_duration = period_duration,
ci = confidence_interval,
output_path = final_output_path,
output_format = output_format)
```
## Global shortcut function
The last section presents an example of a function able to run all the t3 process through one command line. Like before, you can "play" with the arguments to customise the function, especially if you want to skip part(s) of the process.
```{r echo=TRUE, eval=FALSE}
# setup ----
library(t3)
periode_reference <- as.integer(c(2006,
2007,
2008))
target_year <- as.integer(2008)
period_duration <- as.integer(2)
# countries for the France fleet
countries <- c("FRA",
"MYT")
# code 1 for the Atlantic Ocean
ocean <- as.integer(1)
# code 1 for landing data
sample_type <- as.integer(1)
# for french fleet YFT, SKJ, BET, ALB, MIX and LOT
species_rf1 <- as.integer(c(1, 2, 3, 4, 9, 11))
# output format
output_format <- "eu"
# generation of the confidence interval
confidence_interval <- TRUE
# process ----
t3_process_all <- t3::t3_process(process = "all",
data_source = "avdth_db",
db_con = database_con,
output_path = output_path,
output_format = "eu",
periode_reference = periode_reference,
countries = countries,
oceans = ocean,
sample_type = sample_type,
species_rf1 = species_rf1,
target_year = target_year,
period_duration = period_duration,
ci = confidence_interval)
```
</div>