-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport5_VMS.R
104 lines (82 loc) · 2.89 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
95
96
97
98
99
100
101
102
103
104
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 <- "NrS"
ecoreg <- "NrS"
###########
##Load data
###########
# read vms fishing effort
effort <-
sf::st_read("vms_effort.csv",
options = "GEOM_POSSIBLE_NAMES=wkt", crs = 4326)
effort <- dplyr::select(effort, -WKT)
# read vms swept area ratio
sar <-
sf::st_read("vms_sar.csv",
options = "GEOM_POSSIBLE_NAMES=wkt", crs = 4326)
sar <- dplyr::select(sar, -WKT)
#set range of years in plots
year_range = "2018-2021"
###########
## 3: VMS #
###########
#~~~~~~~~~~~~~~~#
# A. Effort map
#~~~~~~~~~~~~~~~#
gears <- c("Static", "Midwater", "Otter", "Demersal seine","Dredge", "Beam")
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",
Dredge = "Dredges",
Beam = "Beam trawls"),
mw_fishinghours = as.numeric(mw_fishinghours)
) %>%
filter(!is.na(mw_fishinghours)) %>%
filter(mw_fishinghours != 0)
# write layer
write_layer <- function(dat, fname) {
sf::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(cap_year, "_", ecoreg,"_FO_VMS_effort"))
# save plot
plot_effort_map(effort, ecoregion) +
ggtitle(paste0("Average MW Fishing hours ", year_range))
ggplot2::ggsave(file_name(cap_year,ecoreg_code,"VMS_effort_update", ext = "png", dir = "report"), width = 170, height = 200, units = "mm", dpi = 300)
# #### investigation
# library(ggplot2)
# ggplot(effort, aes(x=mw_fishinghours)) + geom_histogram()
# length(which(effort$mw_fishinghours == 0))
# breaks <- get_map_breaks(effort$mw_fishinghours)
# unique(breaks)
# x <- which(breaks == ">0 - 0 (n = 53)")
# effort[x,]
#~~~~~~~~~~~~~~~#
# A. Swept area map
#~~~~~~~~~~~~~~~#
# write layer
write_layer(sar, paste0(cap_year, "_", ecoreg,"_FO_VMS_sar"))
plot_sar_map(sar, ecoregion, what = "surface") +
ggtitle(paste0("Average surface swept area ratio ",year_range))
ggplot2::ggsave(file_name(cap_year,ecoreg_code,"VMS_sarA", ext = "png", dir = "report"), width = 170, height = 200, units = "mm", dpi = 300)
plot_sar_map(sar, ecoregion, what = "subsurface")+
ggtitle(paste0("Average subsurface swept area ratio ",year_range))
ggplot2::ggsave(file_name(cap_year,ecoreg_code,"VMS_sarB", ext = "png", dir = "report"), width = 170, height = 200, units = "mm", dpi = 300)