-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_request.R
51 lines (40 loc) · 1.22 KB
/
model_request.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
library(icesTAF)
library(data.table)
library(icesVMS)
library(sfdSAR)
library(dplyr)
library(ggplot2)
library(sf)
source("utilities.R")
mkdir("model")
for (yr in 2013:2019) {
if (file.exists(paste0("model/request_", yr, ".RData"))) next
try({
msg("doing ", yr)
vms <- fread("data/vms_complete.csv")
vms <- vms %>% filter(year == yr)
vms_output <-
vms %>%
filter(
!is.na(gear_group) & gear_group != "" & c_square != "" & country != "NO"
) %>%
mutate(quarter = ceiling(month / 12 * 4)) %>%
group_by(year, quarter, gear_group, c_square) %>%
vms_summarise() %>%
select(
year, quarter, c_square, gear_group, fishinghours, totweight, surface_sar, anonymous
) %>%
mutate(
fishinghours_cat = get_cat(fishinghours),
fishinghours_cat_low = catlow(fishinghours_cat),
fishinghours_cat_high = cathigh(fishinghours_cat),
fishinghours = replace(fishinghours, !anonymous, NA),
totweight_cat = get_cat(totweight),
totweight_cat_low = catlow(totweight_cat),
totweight_cat_high = cathigh(totweight_cat),
totweight = replace(totweight, !anonymous, NA)
) %>%
vms_add_spatial()
save(vms_output, file = paste0("model/output_", yr, ".RData"))
})
}