-
Notifications
You must be signed in to change notification settings - Fork 1
/
project_forward_tutorial.Rmd
108 lines (60 loc) · 4.51 KB
/
project_forward_tutorial.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
---
title: "Time-traveling distribution models: Back to the future"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Time periods
**Try it yourself:** Load the `raster` and `ENMeval` packages:
```{r}
```
## What data do you want?
The first step is to figure out what data we actually want to download from WorldClim. To do this, we need to pick a GCM, an RCP, a year, and what resolution we would like the data to be in (remember the resolution of a raster is the size of each grid cell). You can check out this helpful table from WorldClim to see what combinations of those three selections are available: http://www.worldclim.org/cmip5_2.5m.
### Set resolution
First, we need to set the resolution of the environmental data we want from the future -- remember the resolution of a raster is the size of each grid cell. We would like the resolution of the future environmental data to match the resolution of our current environmental data.
**Try it yourself:** Use the `res()` function to find the resolution of your masked environmental data. Notice that the resolution is two numeric values (for the two side lengths of each cell in the raster). These two numeric values should be the same. Create a variable `envsRes` that is the first element of the resolution.
```{r}
envsRes <-
```
### Pick a GCM
Now we can pick which GCM we would like to use. We are going to start by using the Hadley Centre Global Environmental Model version 2, with Earth System components (HadGEM2-ES). The "Earth System" part of the model means that it accounts for vegetation and hydrology changes as the climate changes.
**Try it yourself:** Look at the WorldClim table and find the code for the HadGEM2-ES GCM. Create a character variable `GCM` and set it to this code (using quotation marks).
```{r}
GCM <-
```
### Pick an RCP
Our final step is to pick an RCP. For this tutorial, you can pick which scenario you want to use: RCP 2.6, RCP 4.5, RCP 6, or RCP 8.5. You can read about them on the GitHub here: https://github.com/amnh/BridgeUP-STEM-BabichMorrow/blob/master/lesson_plans/s7_project_in_time/Future_climate_data.md.
**Try it yourself:** Once you select an RCP, create the variable `RCP`. Set it to be the number following "RCP", multiplied by 10 (so if you picked RCP 6, set your variable equal to 60).
```{r}
RCP <-
```
### Pick a year
We can get predicted climate data from the year 2050 and the year 2070.
**Try it yourself:** Decide whether you want to model sloth habitat in 2050 or 2070. Create the variable `time_period` and set it to be either 50 or 70, depending on your choice.
```{r}
time_period <-
```
## Download data
We can use the `getData()` function from the `raster` package to download data from WorldClim based on the variables you just selected.
**Try it yourself:** Fill in the following code to download the data. Use the Help menu for `getData` if you get stuck. Note that you need to multiply the resolution value you calculated earlier by 60 to get it in the right format for WorldClim. Then, use `names()` to see the names of the variables in the downloaded data:
```{r}
# download data
projTimeEnvs <- getData('CMIP5', var = "bio", res = , rcp = , model = , year = )
# see the names of the data
```
We need to set the names of the variables in this downloaded data so that they match the names of our current environmental data, which is in the format "bio1", "bio2", ..., "bio19". In order to set the names of `projTimeEnvs`, we can use the `paste0()` function to quickly create a vector containing "bio1", "bio2", ..., "bio19" (instead of typing out all 19 by hand).
**Try it yourself:** Use `paste0()` to set the names of `projTimeEnvs`:
```{r}
```
### Crop & mask data
**Try it yourself:** Crop and mask the future environmental data to the bounding box around the occurrence points for your species (hint: you made this bounding box in `model_selection_tutorial.Rmd`).
```{r}
```
## Project the model
Now we're ready to project your model into the future! Just like projecting the model in space, you are going to use the `maxnet.predictRaster()` function. The difference is that you will provide the future environmental data (masked to the bounding box), instead of using the environmental data from the present.
**Try it yourself:** Look at the code you wrote to project your model in space at the end of `model_selection_tutorial.Rmd`. Modify it to instead project your model in time using the future environmental data:
```{r}
# project your model into the future
# plot the projected model
```