knitr::opts_chunk$set(echo = TRUE) knitr::opts_knit$set(root.dir = "~/Google Drive/Academic Work Folder/BBS.occurrences/Clark_etal_analysis") library(knitr) opts_chunk$set(tidy.opts=list(width.cutoff=50),tidy=TRUE)
This appendix describes how to calculate mean PRISM climate variables, altitudes and NDVI values for 40km-radius buffers around BBS sample sites. These matrices can be accessed in the BBS.occurrences
library using data('Bird.phy.distances')
and data('Site.descriptors')
.
First, we need to download the raw climate data for each point in the dataset. Specify a file path for downloading PRISM climate data, and set this as the option for the prism
library to store and access files
dir.create("/PRISM/ppt") filepath <- "/PRISM/ppt" options(prism.path = filepath)
Download monthly min temp data for the entire USA, starting the year prior to the first year of surveys
prism::get_prism_monthlys(type="ppt", year = 2002:2009, mon = 1:12, keepZip = F)
Load the species occurrence dataset, which lists the binary occurrences of 303 avian species (stored in columns) across sites
library(BBS.occurrences) data("Site.descriptors")
We need to extract unique sample sites so that they can be intersected with the prism
rasters
# install.packages('sp') library(dplyr) points <- Site.descriptors %>% dplyr::ungroup() %>% dplyr::select(Latitude, Longitude) %>% dplyr::distinct()
Extract mean estimates for PRISM climate variables (for precipitation, in this case) from 40km buffers around each point. If space for storing the raw files is an issue, use argument delete_files = TRUE
to ensure files are deleted once calculations are complete
buffer <- 40000 points.ppt <- meanPRISM(points = points, var_name = 'Precipitation', buffer = buffer, filepath = filepath, n_cores = 3, delete_files = FALSE) save(points.ppt, file = './Analysis_data/points.ppt.rda')
\pagebreak
Repeat the above procedure for each climate variable (temp.min
, temp.mean
, and temp.max
). Load all the saved climate datasets and join together in a single dataframe
load('points.ppt.rda') load('points.tmean.rda') load('points.tmin.rda') load('points.tmax.rda') monthly_climate_data = points.ppt %>% left_join(points.tmax) %>% left_join(points.tmean) %>% left_join(points.tmin)
load('./Analysis_data/points.ppt.rda') load('./Analysis_data/points.tmean.rda') load('./Analysis_data/points.tmin.rda') load('./Analysis_data/points.tmax.rda') monthly_climate_data = points.ppt %>% left_join(points.tmax) %>% left_join(points.tmean) %>% left_join(points.tmin)
Process to return climate variables describing conditions during the previous Spring season and during the previous year to be used as predictors in analyses. Ignore warnings here, these are just to showcase that a small number of specific points have no available measurements for certain months
climate.predictors <- processPRISM(monthly_climate_data)
Next, we download and extract altitude data for each site (again, with a 40km buffer). Here, we utilise a geotif file of the Aster Global Digital Elevation map that is available from NASA
altitudes <- processAltitudes(points = points, n_cores = 3)
We next download and extract Normalised Difference Vegetation Index (NDVI) values around 40km buffers. These functions rely in the gimms
R package. Note, the downloads will take up to a few hours and will need several GB of space!
gimms_folder <- '/Gimms_NDVI/' gimms::downloadGimms(x = 2003, y = 2009, dsn = gimms_folder) ndvi <- processNDVI(filepath = gimms_folder, points = points, buffer = 40000, n_cores = 3)
Finally, join these predictors to the Site.descriptors
file and save. Note, the climate predictors and other site description variables can be directly accessed in the BBS.occurrences
library using data('Site.descriptors')
.
Site.descriptors <- Site.descriptors %>% dplyr::ungroup() %>% dplyr::left_join(climate.predictors) %>% dplyr::left_join(altitudes) %>% dplyr::left_join(ndvi) save(Site.descriptors, file = './Analysis_data/ Site.descriptors.rda')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.