In this tutorial we will learn how to run some basic spatial analyses based on maximum likelihood tracks, probability surfaces and simulated fishing effort data (kernel densities).
To run this tutorial we will need RchivalTag version >= 0.1.5 and oceanmap version >= 0.13. You can find the newest versions of both packages on github
## install or load package
# install.packages("RchivalTag") # from CRAN
# library(xfun)
# install_github("rkbauer/oceanmap") # newest version from github
# install_github("rkbauer/RchivalTag") # newest version from github
library("RchivalTag")
## Package overview and version:
?RchivalTag
help(package="RchivalTag") ## list of functions
library(oceanmap)
In the RchivalTag tutorial 4 we have seen how to visualize the different GPE3 model outputs (i.e. Probability surfaces vs Maximum likelihood tracks). As you remember we can read and plot these outputs via the ggplot_geopos-function (or via the get_geopos and the leaflet_geopos-functions).
pos_file <- system.file("example_files/15P1019-104659-1-GPE3.csv",package="RchivalTag")
xlim <- c(-6.0, 16.5)
ylim <- c(34.0, 44.5)
ggobj <- ggplotmap(lon = xlim, lat = ylim)
ggobj <- ggplot_geopos(pos_file,ggobj = ggobj)
ggobj
kmz_file <- system.file("example_files/15P0986-15P0986-2-GPE3.kmz",package="RchivalTag")
ggobj <- ggplotmap(lon = xlim, lat = ylim)
ggobj <- ggplot_geopos(kmz_file,ggobj = ggobj,prob_lim = 0.95)
ggobj
Many marine biologging studies seek to understand the vulnerability of a target species, i.e. vs. different kinds of fishing activities. Assume we are interested in the overlap of areas of high fishing effort and the tracks of our tagged animal. To study such a scenario, I have simulated some fishing effort data, with each position representing a fishing activity. For simplicity, we will not further address any simulated fishing effort that actually falls on land.
We can generate kernel densities from this data and transform those in probability surfaces:
The code below shows how to extract a specific contour line (probability surface) from this data.
library(maptools)
prob_lim <- 50
cl <- try(rasterToContour(catch_prob, levels = prob_lim), silent = T)
p <- maptools::SpatialLines2PolySet(cl)
spolys <- maptools::PolySet2SpatialPolygons(p,close_polys = T)
spolys <- rgeos:::gBuffer(spolys,byid = T,width=0)
plotmap(xlim = xlim, ylim=ylim)
fillcol <- rgb(173, 216, 230, max = 255, alpha = 125, names = "blue50")
plot(spolys,add=T,col=fillcol,lty="dashed")
This contour, extracted as a SpatialPolygons-object can be used to calculate the overlap of our tracks with the fishing effort data. To do so, we calculate the overlap based on the percentage of maximum likelihood positions that are located inside the contourline of the fishing effort probability surface:
plotmap(xlim = xlim, ylim=ylim)
fillcol <- rgb(173, 216, 230, max = 255, alpha = 125, names = "blue50")
plot(spolys,add=T,col=fillcol,lty="dashed")
pos_file <- system.file("example_files/15P1019-104659-1-GPE3.csv",package="RchivalTag")
mlt <- get_geopos(pos_file)
Loading tagging tracks from file: /home/work/R/x86_64-pc-linux-gnu-library/3.6/RchivalTag/example_files/15P1019-104659-1-GPE3.csv
points(mlt$Lon,mlt$Lat,pch=19)
smlt <- SpatialPoints(mlt[,c("Lon","Lat")])
sp::proj4string(smlt) <- sp::proj4string(spolys)
overlapping_pos <- over(smlt,spolys) # 1 indicating overlap, NA no overlap
# percentage of maximum likelihood positions located inside the fishing effort probability surface
overlap_perc <- round(100*length(which(!is.na(overlapping_pos)))/nrow(mlt),1)
overlap_perc
[1] 0
Or we can calculate the overlap based on the GPE3 probability surfaces:
plotmap(xlim = xlim, ylim=ylim)
fillcol <- rgb(173, 216, 230, max = 255, alpha = 125, names = "blue50")
plot(spolys,add=T,col=fillcol,lty="dashed")
# load example track as SpatialPolygonsDataFrame
pos <- get_geopos(kmz_file, prob_lim = 0.95)
Loading tagging tracks from file: /home/work/R/x86_64-pc-linux-gnu-library/3.6/RchivalTag/example_files/15P0986-15P0986-2-GPE3.kmz
extracted kml-file from provided kmz-file
tracks <- try(unionSpatialPolygons(pos,IDs=rep(1,length(pos))),silent=T) # merge track polygons
trackcol <- rgb(144, 238, 144, max = 255, alpha = 125, names = "lightgreen")
plot(tracks,add=T,col=trackcol)
sharedpol <- intersect(tracks,spolys)
TrackArea <- raster::area(tracks)
SharedArea_perc <- round(100*raster::area(sharedpol)/TrackArea,2)
SharedArea_perc
[1] 61.35
Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".
For attribution, please cite this work as
Bauer (2021, June 1). Marine Biologging & Data Science | Blog: RchivalTag Tutorial | Part 8 - Spatial Analyses. Retrieved from http://oceantags.com/posts/RchivalTag_Tutorials_Part8_Spatial_Analayses/
BibTeX citation
@misc{bauer2021rchivaltag, author = {Bauer, Robert K.}, title = {Marine Biologging & Data Science | Blog: RchivalTag Tutorial | Part 8 - Spatial Analyses}, url = {http://oceantags.com/posts/RchivalTag_Tutorials_Part8_Spatial_Analayses/}, year = {2021} }