3 Vector: Animal oceanographers

3.1 Import spatial data from .csv files

One of the core components of R are data.frame objects. You can turn tabular text files, spreadsheets and databases into data.frame objects. Having spatial coordinates in your data.frame will allow you to easily turn it into a spatial object.

In this example we will import a dataset of CTD (conductivity, temperature, depth) profiles from oceanographic sensors that were equipped on Southern Elephant Seals. This is a subset of the MEOP-CTD in-situ data collection.

## [1] "data.frame"
##          species    ptt         tag                date      lon      lat
## 1 Southern ellie 113368 ct77-167-12 2012-03-17 10:40:00 110.5548 -66.4558
## 2 Southern ellie 113368 ct77-167-12 2012-03-17 14:20:00 110.3725 -66.3939
## 3 Southern ellie 113368 ct77-167-12 2012-03-17 23:20:00 110.4566 -66.3640
## 4 Southern ellie 113368 ct77-167-12 2012-03-18 01:10:00 110.4468 -66.3704
## 5 Southern ellie 113368 ct77-167-12 2012-03-18 10:30:00 110.4070 -66.3601
## 6 Southern ellie 113368 ct77-167-12 2012-03-18 14:40:00 110.4506 -66.3885
##    scientific_name
## 1 Mirounga leonina
## 2 Mirounga leonina
## 3 Mirounga leonina
## 4 Mirounga leonina
## 5 Mirounga leonina
## 6 Mirounga leonina

Transform the data.frame into a sp class object:

## [1] NA

We need to set the CRS of the spatial layer:

Using EPSG codes can be more convenient that using larger strings. You can find more about EPSG codes at the Spatial Reference website.

We can now plot the data to see how it looks:

As with the previous practical, adding some layers to give context to the data would be ideal:

## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Git\spatial_data_analysis\data\ne\ne_110m_admin_0_countries", layer: "ne_110m_admin_0_countries"
## with 177 features
## It has 94 fields
## Integer64 fields read as strings:  POP_EST NE_ID

3.3 Movement trajectory data

Trajectories represent the mobility of objects, such as people, vehicle or animals. Trajectories contain temporally sequenced location and time values (x, y, t) recorded from different devices (e.g. GPS, video-monitoring). In the following example, we will subset the MEOP-CTD dataset by selecting the trajectory of a single southern elephant seal (i.e., tag ct77-167-12).

3.4 Convex hull polygon

Creating a convex hull around a set of points is another common GIS operation. This essentially creates the smallest polygon possible that can contain a given set of points. Variations in the parameters determining the characteristics of the polygon can also be applied, but for this example we will use the default settings. In R, this can be created with one line of code, utilising the mcp function:

3.6 Animated plots for movement data

First, we will convert the trajectory data into a move object:

Trajectories from animals or humans can be recorded at irregular sampling intervals. To explore data using animations, we need to generate unique time frames. Therefore, we have to interpolate the trajectory at regular time intervals:

The next step is to create individual frames for each time step:

## Processing movement data...
## Approximated animation duration: ˜ 9.12s at 25 fps for 228 frames
## Retrieving and compositing basemap imagery...
## Assigning raster maps to frames...
## Creating frames...

We can preview one of the frames:

Finally, we can generate an animation by combining all individual frames. This function takes a while…

Animation in lonlat

Animation in lonlat

3.6.1 Extra bonus material

We will use a custom base map in raster format. We will explain more information about raster in the following module of the workshop.

Now, we will transform both the track and the base map into a polar projection

Prepare individual frames for animation. Note this time there are several differences in the code:

## Processing movement data...
## Approximated animation duration: ˜ 9.12s at 25 fps for 228 frames
## Assigning raster maps to frames...
## Creating frames...

This time, we will remove the axis labels:

Finally, we can generate an animation by combining all individual frames. This function takes a while…

Animation in polar projection

Animation in polar projection

3.7 Retrieve animal observations using R client for APIs

Several public online databases offer the posibility to extract their information using an application programming interface (API). An API is a set of routines, protocols, and tools for building software applications. There are some R packages that allow the connection to those APIs in order to retrieve information.

Here, we show the use of one client for the Ocean Biogeographic Information System that allow us to extract species occurrence records: