-
Notifications
You must be signed in to change notification settings - Fork 1
/
1_download.Rmd
121 lines (91 loc) · 2.78 KB
/
1_download.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
121
---
title: "Download GBIF occurrences"
author:
- Damiano Oldoni
- Peter Desmet
date: "`r Sys.Date()`"
output:
html_document:
toc: true
toc_depth: 3
toc_float: true
number_sections: true
---
In this document we download (alien) species occurrences for Belgium from [GBIF](https://www.gbif.org), to feed alien species indicators and emerging species assessments.
# Setup
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
```
Load libraries:
```{r load_libraries}
library(tidyverse) # To do data science
library(here) # To find files
library(rgbif) # To use GBIF services
library(trias) # To use functions developed for TrIAS
library(lubridate) # To work with dates
```
# Define download query parameters
## Taxa
We don't filter on taxa in the download step as we need data at class level for compensating research effort bias (see [indicators](https://github.com/trias-project/indicators) repository) later.
## Countries
Occurrences from Belgium:
```{r define_countries}
countries <- c("BE")
```
## Basis of record
All types of occurrences, except `FOSSIL SPECIMEN` and `LIVING SPECIMEN`, which can have misleading location information (e.g. location of captive animal).
```{r define_basis_of_record}
basis_of_record <- c(
"OBSERVATION",
"HUMAN_OBSERVATION",
"MATERIAL_SAMPLE",
"LITERATURE",
"PRESERVED_SPECIMEN",
"UNKNOWN",
"MACHINE_OBSERVATION"
)
```
## Year
Occurrences with a valid year:
```{r define_year}
year_begin <- 1000
year_end <- year(Sys.Date())
```
## Geographic coordinates
Occurrences with valid geographic coordinates:
```{r define_hasCoordinate}
hasCoordinate <- TRUE
```
# Download GBIF occurrences
## Trigger download
**Note**: GBIF credentials are required in the next step.
Trigger download:
```{r trigger_gbif_download}
# Reuse existing download (comment to trigger new download)
gbif_download_key <- "0031758-231002084531237"
# Trigger new download (commented by default)
# gbif_download_key <- occ_download(
# pred_in("country", countries),
# pred_in("basisOfRecord", basis_of_record),
# pred_gte("year", year_begin),
# pred_lte("year", year_end),
# pred("hasCoordinate", hasCoordinate),
# user = rstudioapi::askForPassword("GBIF username"),
# pwd = rstudioapi::askForPassword("GBIF password"),
# email = rstudioapi::askForPassword("Email address for notification")
# )
```
## Check status of download
```{r check_metadata}
metadata <- occ_download_meta(key = gbif_download_key)
metadata$key
metadata$status
```
Write download to list of downloads and check pending downloads:
```{r update_download_list}
update_download_list(
file = here::here("data", "raw", "gbif_downloads.tsv"),
download_to_add = gbif_download_key,
input_checklist = ""
)
```