-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDemo4_Beyond_ReLTER.Rmd
More file actions
215 lines (163 loc) · 6.59 KB
/
Demo4_Beyond_ReLTER.Rmd
File metadata and controls
215 lines (163 loc) · 6.59 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
---
title: "Going beyond ReLTER"
author: "Alessandro Oggioni, Micha Silver, Paulo Tagliolato"
date: "13/04/2022"
output:
ioslides_presentation:
smaller: true
logo: eLTER_logo_small.png
css: styles.css
---
```{r beyond-setup, include=FALSE, purl=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## What can be done with ReLTER outputs
```{r beyond-load-packages, message=FALSE, warning=FALSE}
pkg_list <- c("sf", "terra", "ReLTER", "tmap")
lapply(pkg_list, require, character.only = TRUE)
```
----
#### Each function returns an `R` object
- Site metadata and info returned as a `tibble`
* save as an `R` dataset (keeps R stucture), or
* save to csv file
- Boundaries are returned as an `sf` spatial vector layer.
* save to a shapefile, or geopackage
- EO data are returned as a `SpatRaster` object (from the `terra` package)
* save as geotiff
----
#### Example from the Doñana site in Spain
```{r beyond-donana}
donana = get_ilter_generalinfo(country_name = "Spain",
site_name = "Doñana")
donana_id = donana$uri
donana_polygon <- get_site_info(donana_id, category = "Boundaries")
donana_meta <- get_site_info(donana_id,
c("Affiliations", "Contacts", "Parameters"))
# Get the Corine landcover from ODS
donana_clc <- get_site_ODS(donana_id, "clc2018")
```
----
Save data and spatial layers for use later, or in other GIS software
```{r beyond-donana-saving}
# For this demo, save to temporary directory
output_dir = tempdir()
saveRDS(donana_meta, file.path(output_dir, "Donana_metadat.Rds"))
# Remove extra columns from polygon
donana_polygon <- donana_polygon[,c("title", "boundaries", "geoCoord", "geoElev.avg")]
st_write(donana_polygon,
file.path(output_dir, "donana_polygon.gpkg"), append=FALSE)
writeRaster(donana_clc,
file.path(output_dir, "Donana_Corine2018.tif"),
overwrite=TRUE)
```
## Rocker ReLTER
A Docker image for [ReLTER](https://github.com/ropensci/ReLTER) package.
#### Capabilities
Run RStudio with preinstalled ReLTER package through Docker.
----
#### Quick setup
1. Follow the instructions to
[install Docker on your computer](https://docs.docker.com/get-docker/).
1. Open a terminal ("command prompt" in Windows) and write the following command to download the
[rocker_relter](https://hub.docker.com/r/ptagliolato/rocker_relter) image
```{bash docker1, eval=FALSE}
docker pull ptagliolato/rocker_relter
```
1. Run the image:
```{bash docker2, eval=FALSE}
docker run -e PASSWORD=yourpassword -p 8080:8787 \
ptagliolato/rocker_relter
```
* This will run RStudio on port 8080, you can change the port as you like.
* You can change "yourpassword" with the password you prefer.
* If you close the terminal, the image will stop. To avoid this, add "-d" before "-e"
to run "detached" from the terminal.
* See further options in the last section.
#### Open your browser at [localhost:8080](localhost:8080) and login with
user: rstudio
password: yourpassword
----
#### Run experimental features of ReLTER package
ReLTER package is evolving. You can run some of the features recently
added to the package (namely those presented in eLTER Plus deliverable D.4.1
to retrieve and manage biodiversity data from GBIF, OBIS and iNaturalist) by using
the alternative image "dev__withImprovements":
```{bash docker3, eval=FALSE}
docker pull ptagliolato/rocker_relter:dev__withImprovements
docker run -e PASSWORD=yourpassword -p 8080:8787 \
ptagliolato/rocker_relter:dev__withImprovements
```
#### Preserve your work (use a docker volume)
When you stop a docker container, the files created within it are lost. In order to preserve your work across
different runs, link a local volume (in this example, the current working directory, $(pwd)) to the container:
```{bash docker4, eval=FALSE}
docker run -d -v $(pwd):/home/rstudio -e PASSWORD=yourpassword \
-p 8080:8787 ptagliolato/rocker_relter
```
## Merging other data
The site boundary, obtained from https://DEIMS.org can be used to crop and mask EO data from other sources. In this section we show use of global EO data acquired from a new `R` package `geodata`. Elevation from the Shuttle Radar Terrain Mission (SRTM) and species distribution from Global Biodiversity Information Facility (GBIF) will be downloaded, cropped to a site boundary and compared. The Gran Paradiso National Park will be used, and this example will examine *Capra ibex* sitings
#### Get Gran Paradiso boundary
```{r get-paradiso}
paradiso <- get_ilter_generalinfo(country_name = "Italy",
site_name = "Gran Paradiso")
paradiso_id <- paradiso[2,]$uri
paradiso_boundary <- get_site_info(paradiso_id, "Boundaries")
```
----
#### Install `geodata` package and download SRTM over Northern Italy
```{r get-srtm}
# Get the geodata package
if (!require(geodata)) {
install.packages("geodata", dependencies = TRUE)
library(geodata)
}
italy_srtm <- elevation_3s(lon = 7.5, lat = 47.5, path = tempdir())
paradiso_srtm <- mask(crop(italy_srtm, vect(paradiso_boundary)),
vect(paradiso_boundary))
names(paradiso_srtm) <- "Elev"
```
----
#### Query GBIF for *Capra ibex*
```{r get-gbif}
# Download data
ibex <- sp_occurrence("Capra", species = "ibex",
ext = ext(paradiso_boundary))
ibex <- ibex[,c("lon", "lat")]
ibex <- ibex[complete.cases(ibex),]
# Convert to `sf`
ibex_points <- st_as_sf(ibex, coords = c("lon", "lat"), crs = "EPSG:4326")
```
----
#### Now extract elevation from SRTM at each Ibex siting location
```{r correlation}
ibex_elev <- extract(x = paradiso_srtm, y=vect(ibex_points))
ibex_points <- cbind(ibex_points, ibex_elev)
hist(ibex_points$Elev, breaks=20,
main = "Distribution of Ibex sitings by elevation")
```
----
Prepare hill-shade raster
```{r ibex-plot}
# Create hillshade raster
slope <- terrain(paradiso_srtm, "slope", unit = "radians")
aspect <- terrain(paradiso_srtm, "aspect", unit="radians")
hill_shade = shade(slope, aspect, angle=35, direction = 310)
```
----
Prepare a plot, including hillshade effect
```{r ibex-plot2}
tm_basemap("OpenStreetMap.Mapnik") +
tm_shape(hill_shade) +
tm_raster(alpha = 0.4, palette = "Greys",
n=8, legend.show = FALSE) +
tm_shape(paradiso_boundary) +
tm_borders(col = "purple", lwd = 2) +
tm_shape(ibex_points) +
tm_symbols(size=0.2, col = "red")
```
## Future plans
- Acquire MODIS products
* Time series
- Acquire species distribution from GBIF: https://www.gbif.org/dataset/search
- Acquire high resolution landcover data from ESA Worldcover: https://esa-worldcover.org/