-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinterrex_to_movebank.Rmd
120 lines (101 loc) · 4.44 KB
/
interrex_to_movebank.Rmd
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
title: "Prepare Interrex (meta)data for Movebank upload"
author: "Peter Desmet"
date: "`r Sys.Date()`"
output:
html_document
---
This script prepares [Interrex](http://interrex-tracking.com/) bird tracking data for upload to [Movebank](https://www.movebank.org/) For a project, it downloads **reference data** from a Google spreadsheet where these data are maintained and transforms these to the [Movebank data format](https://www.movebank.org/node/2381) using `dplyr::mutate()` (see below). **GPS data** are automatically synced with Movebank (see `Live Feeds` in a Movebank study).
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
```
Load libraries:
```{r}
library(tidyverse)
library(here)
```
## Get Interrex tag and bird information from spreadsheet
```{r}
metadata <- readr::read_csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vSJAdGCKUnFn_9TuTN5RFs2V7wdRytJ-TgePX-eVH6mALcupdF0VqDQ6MJVBDxJG1cjRWv7fu30jzNq/pub?gid=0&single=true&output=csv")
metadata_colnames <- colnames(metadata)
```
Set user-defined values:
```{r}
project_id <- "HG_JUVENILE"
```
## Get reference data (metadata)
For a project, get data on animals, tags and deployments in the [Movebank reference data format](https://www.movebank.org/node/27).
Note: [UvA-BiTS reference data](../sql/movebank_ref.sql) has some fields that are not available in the Interrex metadata. These are indicated with `NOT AVAILABLE` below and are not included in `movebank_ref_data.csv`, as their empty values would lead to import errors in Movebank. Since UvA-BiTS has more fields, use `bind_rows(uvabits_project_metadata, interrex_project_metadata)` (UvA-BiTS first) to have all columns in the right order when you want to combine metadata.
Map data:
```{r get_ref_data}
movebank_ref_data <-
metadata %>%
dplyr::filter(project == project_id) %>%
dplyr::mutate(
# animal-comments: NOT AVAILABLE
`animal-id` = dplyr::coalesce(metal_ring, colour_ring),
`animal-nickname` = animal_name,
`animal-ring-id` = colour_ring,
`animal-sex` = dplyr::recode(sex,
"F" = "f",
"M" = "m",
"X" = "u",
.missing = "u"
),
`animal-taxon` = scientific_name,
`alt-project-id` = project_id,
`animal-life-stage` = dplyr::recode(age,
"A" = "adult",
"J" = "juvenile"
),
`animal-mass` = animal_weight,
`attachment-type` = "harness",
`deploy-off-timestamp` = format(
as.POSIXct(track_session_end_date, tz = "UTC", format = "%Y-%m-%d %H:%M:%S"),
"%Y-%m-%dT%H:%M:%SZ"
),
`deploy-on-latitude` = release_latitude,
`deploy-on-longitude` = release_longitude,
`deploy-on-measurements` = animal_measurements,
`deploy-on-timestamp` = format(
as.POSIXct(track_session_start_date, tz = "UTC", format = "%Y-%m-%d %H:%M:%S"),
"%Y-%m-%dT%H:%M:%SZ"
),
`deployment-comments` = track_session_remarks,
`deployment-end-type` = dplyr::case_when(
stringr::str_detect(tolower(track_session_remarks), "dead") ~ "dead",
stringr::str_detect(tolower(track_session_remarks), "predated") ~ "dead",
stringr::str_detect(tolower(track_session_remarks), "victim") ~ "dead",
stringr::str_detect(tolower(track_session_remarks), "defect") ~ "equipment failure",
stringr::str_detect(tolower(track_session_remarks), "malfunction") ~ "equipment failure",
TRUE ~ NA_character_
),
# deployment-id: NOT AVAILABLE
# location-accuracy-comments: NOT AVAILABLE, there is no location-error-numerical/vertical-error-numerical in the gps data
`manipulation-type` = dplyr::case_when(
stringr::str_detect(release_location, "Nieuwpoort") ~ "manipulated other",
# Birds from HG_JUVENILE that were released at Nieuwpoort were hatched from egg or raised as chicks
# e.g. placed in controlled environment and subjected to behavioural studies
TRUE ~ "none"
),
`study-site` = release_location,
# tag-firmware: NOT AVAILABLE
`tag-readout-method` = "phone network",
`sensor-type` = "GPS",
`tag-id` = serial_number,
`tag-manufacturer-name` = "Interrex",
`tag-mass` = tag_weight,
`tag-serial-no` = serial_number,
.keep = "none"
) %>%
dplyr::filter(!is.na(`animal-id`)) %>%
dplyr::arrange(`tag-id`)
```
Save to CSV:
```{r}
readr::write_csv(movebank_ref_data, file = here("data", "processed", project_id, "movebank_ref_data.csv"), na = "")
```
## Get gps data (detections)
Done via live feed.
## Get acceleration data
Not applicable.