knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  message = FALSE,
  comment = "#>"
)

Installing ghsllr

Just in case you have stumbled on this vignette from any other source than from within the ghsllr-package we start with some instruction on how to install it on your computer.

The ghsllr-packages does not, and will most likely never be on CRAN. Hence you can not use the base R-function install.packages to install it. This is because the ghsllr package resides on github. And in order to install packages that are on that space you need a special R-package (devtools) to install the ghsllr-package!.

So, if you have not installed devtools run this code in the console:

install.packages("devtools")

Then the next step is to run the following command in the console:

devtools::install_github("fishvice/ghsllr")

The above command will install the ghsllr-package and (hopefully) all dependent packages. The only package that I can think of that will not be installed is mapsdata. To install that run this command in the console:

install.packages("mapdata")

Hopefully this is all there is to it. And note, you don't have to run the above bunch of code every time you start an R-session. But you may want to do it occasionally, just to get the latest updates. If you only want to get the laterst update of the ghsllr-packages but not other packages then you could just do:

devtools::install_github("fishvice/ghsllr", dependencies = FALSE)

Preamble

The ghsllr-package contains a bunch of function and rmarkdown templates that aim at making some basic analysis of VMS data simple for people that may be novice to R.

Typical VMS data contain at minimum the following variables:

Additional variables, such as heading, if vessel is in harbour may also be available. Although different VMS data-sources have common variables, the variable names, the unit of the variables and the formatting of the variables may differ.

The objective of the ghsllr-packages is:

The standardized format of a VMS file has at minimum the following names and units for each variable:

Loading needed libraries

The libraries needed to run this document are:

library(mapdata)
library(tidyverse)
library(ghsllr)

And just as a note, for the absolute novice R-user, if you want to repeat any of the codes in this document you can either:

Importing and standardizing data

The function vms_import_data converts raw VMS data to a standardized form. It takes two arguments, file.name and country. The former specifies the path and the name of the raw VMS file, the latter is the country origin of the source file.

Lets read some example VMS data, in this specific case directly from an ftp site:

vms <- 
  vms_import_data(file.name = "ftp://ftp.hafro.is/pub/reiknid/einar/vms/iceland_vms.csv",
                  country = "Iceland")
glimpse(vms)

Speed and fishing categorization

Speed is one of the key metrics of VMS data, because in the absence of any additional information it may be the only source that indicates potiential fishing activity. For the vms-data one can obtain a histogram of speed using the 'vms_plot_speed'-function:

vms_plot_speed(vms)

The example shows one of the two common patterns associated with fisheries vessel speed data:

We can assign a potential fishing activity using speed with the vms_categorise_fishing-function. The argument fishing.lim takes on the lower and the upper boundaries of the speed postulated as fishing (here speed between 2.5 and 4 are assigned as fishing):

vms <- vms_categorise_fishing(vms, fishing.lim = c(2.5, 4.0))
glimpse(vms)

We have added two new variables, activity that categorizes speed into three classes, below, between and above the values specified in the argument fishing.lim used above and fishing that is TRUE if the speed is within the values. Using the vms_plot_speed again we now have:

vms_plot_speed(vms)

Rasterization

VMS data are typically large (e.g. the demo data has r nrow(vms) records, but in some cases one can have millions of observations) so that getting an graphical overview of the data requires often that the data is first summarized in some form or another. One such summation process is often referred to as gridding or rasterization (see this link for some details).

The ghsllr-package has a function called vms_rasterize-function that deals with condensing the spatial information of standardized vms-data. The user can specify the grid resolution with the grid.lim argument, where the first numerical value refers to the longitudinal resolution and the second number the latitudinal resolution. The following script uses the vms-dataframe and counts the number of observations within a 1 x 0.5 degree squares^[Given that the data is from high latitudes (Icelandic waters) this specification results in a rough square]. ...

vms.raster <-
  vms %>% 
  vms_rasterize(grid.lim = c(1, 0.5))

The new object(vms.raster) looks something like this:

vms.raster %>% glimpse()

There are few things to note here:

The objective of generating a raster is first and foremost to generate a visual representation of the data. This is done in the next step, where we use the vms_plot_raster-function:

vms.raster %>% 
  vms_plot_raster(lon.lim = c(-26.5, -11.5),
                  lat.lim = c(63, 67))

In the above case we supplied in addition numbers that express the longitudinal (lon.lim) and latitudinal (lat.lim) range of the plot we want to show. And the n again represents the number of pings within each rectangle.

The plot above represents all the vms-pings, irrespective of speed and hence potential fishing activity. If we were only interested in the latter we would need to filter the data before we call the vms_plot_raster-function. In the ghsllr we have just that type of a function, called vms_filter_data. If we were just interested in filtering out data by the speed variable one would do:

vms.fishing <- 
  vms %>% 
  vms_filter_data(speed.lim = c(2.5, 4.0))
glimpse(vms.fishing)

We now have only r nrow(vms.fishing) observations compared with r nrow(vms) in the original dataset. But these data are still not gridded. Hence we would do:

vms.raster <-
  vms.fishing %>% 
  vms_rasterize(grid.lim = c(1, 0.5))

Lets just plot this and see what we got:

vms.raster %>% 
  vms_plot_raster()

There are three things to note here:

On the last point lets try a finer resolution. In the code flow here we will start from scratch (from the standardized data) without generating any immediate objects (like vms.fishing or vms.raster as done above):

vms %>% 
  vms_filter_data(speed.lim = c(2.5, 4.0)) %>% 
  vms_rasterize(grid.lim = c(0.1, 0.05)) %>% 
  vms_plot_raster()

Now we are seeing the fine scales of the potential fishing activities. Lets try even a finer resolution:

vms.raster <- 
  vms %>% 
  vms_filter_data(speed.lim = c(2.5, 4.0)) %>% 
  vms_rasterize(grid.lim = c(0.01, 0.005)) 
vms.raster %>% 
  vms_plot_raster()

In this last plot we are observing the real fine scales that this example fishery operates on, the scale being 0.01 x 0.005 decimal degrees.

Now how fine resolution one should specify to reveal fishing location depends a little bit on the frequency of recordings in the data-source, the type of fisheries and the type of topography/hydrography that the fisheries operates on.

There is one problem with the visualization provide above - the image is very static. We can e.g. "zoom" easily in and out for different areas. There are two remedies:

  1. Create an interactive plot within R.
  2. Export the data so that it can be imported into a GIS software such as QGIS.

Interactive plot

Here we would only need to change one argument in the function vms_plot_raster. We just overwrite the default ("ggplot2") by specifying type being "leaflet":

vms.raster %>% 
  vms_plot_raster(type = "leaflet")

Exporting data

Here we can use the vms_esport_raster-function. Before you run the code below make sure you have a directory (read: folder) named "data-products" in your current working directory.

vms %>% 
  vms_filter_data(speed.lim = c(2.5, 4.0)) %>% 
  vms_rasterize(grid.lim = c(0.01, 0.01)) %>%
  vms_export_raster(file.name = "data-products/vms_raster")

You should now have an object (read: file) named "vms_raster.asc" in the "data-product" directory. This file you should be able to import into QGIS.

Vessel tracks

We may be interested in observing the track of a vessel over time in order to get a better understanding of how the fishery operates. Depending on how rich the datasource track plots can become very "crowded". Here is an example of just one vessel:

vms %>% 
  filter(vid == 4) %>% 
  vms_plot_track()

In the above code we used the function filter to limit the plot to only a vessel that has 4 as the identification code. It is definitively crowded so some additional filter of the data may be warranted. Below we have made an additional filtering of the data, only selecting data from the month of June:

vms %>% 
  filter(vid == 4,
         month == 6) %>% 
  vms_plot_track()

Experimental stuff

vms %>% 
  ghsllr:::vms_plot_calendar()
vms %>% 
  ghsllr:::vms_plot_activity()


fishvice/ghsllr documentation built on May 24, 2019, 1:36 a.m.