Intro

ddim package provided convenient helper functions for accessing Movebank Env-DATA annotation service with script.

The code took reference from Elie's ABoVE and other movebank related tutorials like Bald Eagle Code Example by Mariëlle van Toor.

We assume you already have a Env-Data backend account and saved in R environment.

if (!require("remotes")) install.packages("remotes")
remotes::install_github("ctmm-initiative/ddim")

if (!require("pacman")) install.packages("pacman")
pacman::p_load(purrr, stringr, lubridate, data.table, glue, XML, RCurl)
# we need a folder to save the data and temporary files. A sub folder is created on working folder
task_folder <- "env_data"
dir.create(task_folder)

# save your account infor in R environment like following
file.edit("~/.Renviron")
# movebank_envdata_user = "user name"
# movebank_envdata_pass = "password"
# refresh environement after saving 
readRenviron("~/.Renviron")

Workflow

Env-DATA Track Annotation Service can annotate tracking data or a gridded area.

track request

With tracking data request, you upload a csv which specified location and time to be annotated.

There are some specific requirements for the tracking data. Function to_track_df will take a data frame of latitudes, longitudes and times and generates the data file. See function help for details.

You can build a specific request by creating a parameter list, which will be similar to the track annotation page form.

library(ctmm)
library(data.table)
library(purrr)
library(ddim)

data(buffalo)

dt <- buffalo[[1]] %>% data.frame %>% to_track_df
# create request by specifying details
para_list_track <- list(type_name = "modis-land/MOD13A1.006",
                        variable_names = c("500m 16 days NDVI", "500m 16 days NIR reflectance"),
                        variable_labels = c("NDVI", "reflectance"),
                        interpolation_method = "nearest-neighbour",
                        spatial_distance_function = "euclidean")
ddim:::complete_parameters("track", para_list_track)
submit_track_request(dt,
                     para_list_track,
                     user = Sys.getenv("movebank_envdata_user"),
                     password = Sys.getenv("movebank_envdata_pass"))

A browser window of request status will be opened after request was submitted. please save the url as this is the only way to retrieve result later. The url is also printed in R console.

grid request

Alternatively, you can request annotation on a gridded area. ddim can start from a ctmm telemetry object (be it location data frame or home range object), build a grid within the object bounding box. We have some helper functions to make ndvi and evi request extremely simple, all parameters that can be inferred or having default value are covered under the hood.

data("buffalo")
tele <- buffalo
create_envdata_request("NDVI", extent(tele), buffer = 0.1) %>% 
  submit_grid_request(user = Sys.getenv("movebank_envdata_user"),
                      password = Sys.getenv("movebank_envdata_pass"))

download result

After some time, you can revisit the request status url, if the status is available, you can download the result using the status url as parameter. Result will be downloaded and automatically uncompressed into a folder.

# result is saved to current folder by default. You will need to change parameter to your status url
download_result("http://www.bioinfo.mpg.de/orn-gateway/status.jsp?access-key=2682055319626802928")

combine result to stack

Result is saved in raster format by default, and you can combine the multiple snapshots result into a raster stack easily.

# assuming this is your uncompressed result folder created by download_result
tiff_folder <- "data/569057 EVI tiff/250m 16 days EVI"
res_stack <- process_data_folder(tiff_folder)
plot(res_stack@layers[[1]])


ctmm-initiative/DDIM documentation built on Nov. 12, 2021, 7:48 a.m.