View source: R/addEEtoSpOcc_multi.R
addEEtoSpOcc_multi | R Documentation |
Google Earth Engine (GEE) data for each pentad can be extracted
to a data frame using ABAP's addVarEEcollection
and addVarEEimage
functions. addEEtoSpOcc_multi
can then be used to add these types of data
to a list in order to fit single-species multi-season occupancy models using
stPGOcc
(spatial) or tPGOcc
(non-spatial) from the spOccupancy
package.
addEEtoSpOcc_multi(
spOcc,
ee_data,
ee_assign,
process = c("occ", "det"),
seasons = NULL
)
spOcc |
a list containing ABAP detection/non-detection data returned by
|
ee_data |
a data frame with GEE data extracted using |
ee_assign |
"site" if the covariate only varies between sites or "site-season" if the covariate varies across sites and between seasons. |
process |
either 'occ' or 'det' specifying whether the covariate is affecting occupancy or detection processes, respectively. |
seasons |
string indicating the name of the variable in |
If ee_assign = "site-year" ee_data must be a data frame-like object (sf could work)
with each covariate in one column, the pentad identifier in another column named pentad
,
and the season identifier in another column (with the same name specified in season
).
if ee_assign = "site" ee_data must be a data frame-like object
with each covariate in one column, and the pentad identifier in another column named 'pentad'.
The data list spOcc
with the additional covariates.
The numeric ranges of various GEE data can be vastly different so it is advised that you scale your covariate data before running an occupancy model.
Dominic Henry dominic.henry@gmail.com
Pachi Cervantes
abapToSpOcc_multi
, stPGOcc
,
tPGOcc
, addVarEEimage
,
addVarEEcollection
## Not run:
## rgee and ABDtools are required to annotate data with Google Earth Engine
library(rgee)
library(ABDtools)
library(dplyr)
## Extract ABAP pentad data
abap_pentads <- getRegionPentads(.region_type = "province",
.region = "Eastern Cape")
## Extract multi-season ABAP bird data
abap_multi <- getAbapData(.spp = 212,
.region_type = "province",
.region = "Eastern Cape",
.years = c(2009,2010,2011,2012))
## We will use years as occupancy reference seasons
abap_multi$year <- format(abap_multi$StartDate, "%Y")
## Create unmarked frame (with X & Y coords as site covariates)
spOcc_multi <- abapToSpOcc_multi(abap_multi, abap_pentads, seasons = "year")
str(spOcc_multi)
## Start up GEE
ee_check()
ee_Initialize(drive = TRUE)
## Create assetId for pentads of interest
assetId <- file.path(ee_get_assethome(), 'EC_pentads')
## Upload to pentads to GEE (only run this once per asset) and
## load the remote asset into R session
pentads <- uploadFeaturesToEE(feats = abap_pentads,
asset_id = assetId,
load = TRUE)
### ADD SITE-YEAR VARIABLES ###
## Create a multi-band image with mean NDVI for each year
ndvi_multiband <- EEcollectionToMultiband(collection = "MODIS/006/MOD13A2",
dates = c("2009-01-01", "2012-12-31"),
band = "NDVI",
group_type = "year",
groups = 2009:2012,
reducer = "mean",
unmask = FALSE)
## Find mean and sd NDVI value for each pentad and year from the multi-band image
ndvi_mean <- addVarEEimage(pentads, ndvi_multiband, "mean")
ndvi_sd <- addVarEEimage(pentads, ndvi_multiband, "stdDev")
## Format the data to include the pentad column and GEE values for each year
ndvi_mean <- ndvi_mean %>%
select(pentad, paste0("NDVI_", as.character(2009:2012)))
ndvi_sd <- ndvi_sd %>%
select(pentad, paste0("NDVI_", as.character(2009:2012)))
## Create a data frame with covariate columns, pentad and season.
ee_siteyear <- ndvi_mean %>%
as.data.frame() %>%
dplyr::select(-geometry) %>%
tidyr::pivot_longer(-pentad, names_to = "year", values_to = "ndvi_mean")
## Add GEE site-year data to spOccupancy data list. We will add these covariates
## to the detection process.
spOcc_multi_ee1 <- addEEtoSpOcc_multi(spOcc_multi,
ee_data = ee_siteyear,
ee_assign = "site-season",
process = "det",
seasons = "year")
str(spOcc_multi_ee1)
### ADD SITE VARIABLES ###
## Annotate data with mean elevation per pentad
elev_mean <- addVarEEimage(ee_feats = pentads,
image = "MERIT/DEM/v1_0_3",
reducer = "mean",
bands = "dem",
unmask = FALSE)
## Keep only the columns that we need
ee_site <- elev_mean %>%
as.data.frame() %>%
dplyr::select(pentad, dem_mean)
## Add GEE site data to spOccupancy data list. We will now add it to the
## occupancy process.
spOcc_multi_ee2 <- addEEtoSpOcc_multi(spOcc_multi,
ee_data = ee_site,
ee_assign = "site",
process = "occ")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.