-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport5_VMS.R
94 lines (76 loc) · 2.71 KB
/
report5_VMS.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
library(icesTAF)
library(icesFO)
library(sf)
library(ggplot2)
library(dplyr)
## Run utilies
source("bootstrap/utilities.r")
# set values for automatic naming of files:
cap_year <- 2022
cap_month <- "October"
ecoreg_code <- "GS"
year_range = "2018-2021"
##########
#Load data
##########
ecoregion <-
st_read("ecoregion.csv",
options = "GEOM_POSSIBLE_NAMES=WKT", crs = 4326
)
ecoregion <- dplyr::select(ecoregion, -WKT)
# read vms fishing effort
effort <-
st_read( "vms_effort.csv",
options = "GEOM_POSSIBLE_NAMES=wkt", crs = 4326
)
effort <- dplyr::select(effort, -WKT)
# read vms swept area ratio
sar <-
st_read( "vms_sar.csv",
options = "GEOM_POSSIBLE_NAMES=wkt", crs = 4326
)
sar <- dplyr::select(sar, -WKT)
# ~~~~~~~~~~~~~~~#
# A. Effort map
# ~~~~~~~~~~~~~~~#
gears <- c("Static", "Midwater", "Otter", "Demersal seine")
effort <-
effort %>%
dplyr::filter(fishing_category_FO %in% gears) %>%
dplyr::mutate(
fishing_category_FO =
dplyr::recode(fishing_category_FO,
Static = "Static gears",
Midwater = "Pelagic trawls and seines",
Otter = "Bottom otter trawls",
`Demersal seine` = "Bottom seines"
),
mw_fishinghours = as.numeric(mw_fishinghours)
) %>%
filter(!is.na(mw_fishinghours))
# write layer
write_layer <- function(dat, fname) {
write_sf(dat, paste0("report/", fname, ".shp"))
files <- dir("report", pattern = fname, full = TRUE)
files <- files[tools::file_ext(files) != "png"]
zip(paste0("report/", fname, ".zip"), files, extras = "-j")
file.remove(files)
}
write_layer(effort, paste0(year_cap, "_", ecoreg,"_FO_VMS_effort"))
# save plot
plot_effort_map(effort, ecoregion) +
ggtitle(paste0("Average MW Fishing hours ", year_range))
ggplot2::ggsave(paste0(cap_year, "_", ecoreg_code,"_FO_VMS_effort.png"), path = "report", width = 170, height = 200, units = "mm", dpi = 300)
# ~~~~~~~~~~~~~~~#
# A. Swept area map
# ~~~~~~~~~~~~~~~#
# write layer
write_layer(sar, paste0(year_cap, "_", ecoreg,"_FO_VMS_sar"))
plot_sar_map(sar, ecoregion, what = "surface") +
ggtitle("Average surface swept area ratio 2018-2021")
# ggsave(file_name("sar_map_surface", "png"), path = "report", width = 170, height = 200, units = "mm", dpi = 300)
ggplot2::ggsave(paste0(cap_year, "_", ecoreg_code,"_FO_sar_map_surface.png"), path = "report", width = 170, height = 200, units = "mm", dpi = 300)
plot_sar_map(sar, ecoregion, what = "subsurface") +
ggtitle("Average subsurface swept area ratio 2018-2021")
# ggsave(file_name("sar_map_subsurface", "png"), path = "report", width = 170, height = 200, units = "mm", dpi = 300)
ggplot2::ggsave(paste0(cap_year, "_", ecoreg_code,"_FO_sar_map_subsurface.png"), path = "report", width = 170, height = 200, units = "mm", dpi = 300)