-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmovebank_to_frictionless.Rmd
66 lines (51 loc) · 1.87 KB
/
movebank_to_frictionless.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
---
title: "Prepare Movebank data for Zenodo upload (make frictionless)"
author: "Peter Desmet"
date: "`r Sys.Date()`"
output:
html_document
---
This script prepares Movebank bird tracking data for upload to [Zenodo](https://zenodo.org):
1. Manually download data from a Movebank study (see [instructions](https://github.com/inbo/bird-tracking/issues/131)) to `data/processed/<study_acronym>`.
2. Run this script to automatically make a `datapackage.json` file based on the data.
3. Manually upload data to Zenodo.
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
```
Load libraries:
```{r}
library(magrittr)
library(here)
library(frictionless)
library(movepub) # devtools::install_github("inbo/movepub")
```
Set user-defined values:
```{r}
project_id <- "O_WESTERSCHELDE"
versioned_doi <- "https://doi.org/10.5281/zenodo.5879096"
start_year <- 2018
end_year <- 2020
```
Create file paths:
```{r}
dir <- here::here("data", "processed", project_id)
ref_data <- here::here(dir, paste0(project_id, "-reference-data.csv"))
gps_data <- here::here(dir, paste0(project_id, "-gps-", start_year:end_year, ".csv.gz"))
acc_data <- here::here(dir, paste0(project_id, "-acceleration-", start_year:end_year, ".csv.gz"))
```
## Create and write Data Package
Create Data Package, add resources and write to disk
```{r}
dataset <-
frictionless::create_package() %>%
append(c(id = versioned_doi), after = 0) %>%
movepub::add_resource("reference-data", ref_data, keys = TRUE) %>%
movepub::add_resource("gps", gps_data, keys = TRUE) %>%
movepub::add_resource("acceleration", acc_data, keys = TRUE)
frictionless::write_package(dataset, dir)
```
## Validate data package
Make sure to validate the Data Package using [frictionless-py](https://github.com/frictionlessdata/frictionless-py) from the terminal, using:
```
frictionless validate datapackage.json
```