Photo by Hari Nandakumar on Unsplash
Source Materials
The following materials are modified from Leander Anderegg’s niche modeling exercise.
1. Background
This week, you will practice function making with rasters and create a generalizable workflow to determine the climate envelope (or the climate where a species currently lives) of two endemic species to California:
- Tule elk (Cervus canadensis nannodes)
- Yellow-billed magpie (Pica nutalli)
2. Get Started
- Create an
.Rproj
as your version controlled project for Week 8 - Create a Quarto document inside your project
- Download this data folder from Google Drive and move it inside your project
- Load all necessary packages and read spatial objects
library(tidyverse)
library(sf)
library(terra)
library(dismo)
library(tmap)
<- read_csv(here::here("data", "magpie_obvs.csv"))
magpie <- read_csv(here::here("data", "tule_elk_obvs.csv"))
tule_elk
<- here::here("data", "climate", "wc2.1_2.5m")
bioclim_dir <- list.files(bioclim_dir, pattern = glob2rx("*.tif$"), full.names = TRUE)
bioclim <- bioclim[
bioclim_sort # Sort filepaths based on numeric suffix
order(
# Extract numeric suffix of filenames and convert to numeric
as.numeric(gsub(".*_(\\d+)\\.tif$", "\\1", bioclim)))]
<- rast(bioclim_sort) bioclim_rast
3. Your Task
Now, to meet this week’s learning objectives, your task:
- Update the
bioclim_rast
layer names to match the Bioclimatic variables usingnames()
- Use
st_as_sf
to convert and find the geographic extent of species occurrence datamagpie
usingst_bbox()
- Crop
bioclim_rast
to match the extent of species occurrence datamagpie
- Extract points from the cropped
bioclim_rast
for each occurrence inmagpie
- Create “background values” by using
dismo::randomPoints()
to generate random sample points from the croppedbioclim_rast
- Extract points from
bioclim_rast
for each random sample point generated in Step #5 - Plot species climate niche and background climate (temperature vs. precipitation)
- Modify steps 2-7 into a generalizable workflow for other species occurrence data
- Try your new function with species occurrence data
tule_elk