addEEtoUnmarked_single: Add Google Earth Engine covariate data to a single-season...

View source: R/addEEtoUnmarked_single.R

addEEtoUnmarked_singleR Documentation

Add Google Earth Engine covariate data to a single-season Unmarked frame

Description

Google Earth Engine (GEE) data for each pentad can be extracted to a data frame using ABAP's addVarEEcollection and addVarEEimage functions. addEEtoUnmarked_single can then be used to add these types of data to a single-season Unmarked frame. GEE data can subsquently be used as covariates in single-season occupancy models such as occu, occuRN, stan_occu or stan_occuRN.

Usage

addEEtoUnmarked_single(umf, ee_data)

Arguments

umf

a single-season Unmarked frame containing ABAP detection/non-detection data returned by abapToUnmarked_single.

ee_data

a data frame with GEE data extracted using addVarEEcollection or addVarEEimage. The data frame needs to contain a column called pentads with the pentad ID from data extracted using the GEE functions. The remaining columns should only contain the GEE covariate values that are intended to be added to the unmarked frame. For ease of use in occupancy model formula notation it's recommended that the variable names in the data frame are concise and informative, and don't contain spaces. See the example below for how to create this data frame after extracting GEE data.

Value

an object of class unmarkedFrameOccu with survey and site covariates.

Note

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. This can be done within the formula notation of the various occu functions.

Author(s)

Dominic Henry dominic.henry@gmail.com
Pachi Cervantes

See Also

abapToUnmarked_single, addVarEEimage, addVarEEcollection

Examples

## Not run: 
library(rgee)
library(ABDtools)
library(unmarked)
library(dplyr)

## Extract ABAP pentad data
abap_pentads <- getRegionPentads(.region_type = "province",
                                .region = "Eastern Cape")

## Extract single season ABAP bird data
abap_single <- getAbapData(.spp_code = 212,
                          .region_type = "province",
                          .region = "Eastern Cape",
                          .years = 2012)

## Create unmarked frame (with X & Y coords as site covariates)
umf_single <- abapToUnmarked_single(abap_single, abap_pentads)
summary(umf_single)

## Start up GEE
ee_check()
ee_Initialize(drive = TRUE)

## Create assetId for pentads of interest
assetId <- sprintf("%s/%s", ee_get_assethome(), 'EC_pentads')

## Upload to pentads to GEE (only run this once per asset)
uploadFeaturesToEE(pentads = abap_pentads,
                   asset_id = assetId,
                   load = FALSE)

## Load the remote asset into R session
pentads <- ee$FeatureCollection(assetId)

## Extract spatial mean NDVI for each pentad
ndvi_mean <- addVarEEcollection(ee_pentads = pentads,
                                  collection = "MODIS/006/MOD13A2",
                                  dates = c("2010-01-01", "2013-01-01"),
                                  temp_reducer = "mean",
                                  spt_reducer = "mean",
                                  bands = "NDVI")

## Extract spatial standard deviation of NDVI for each pentad
ndvi_sd <- addVarEEcollection(ee_pentads = pentads,
                                  collection = "MODIS/006/MOD13A2",
                                  dates = c("2010-01-01", "2013-01-01"),
                                  temp_reducer = "mean",
                                  spt_reducer = "stdDev",
                                  bands = "NDVI")

## Extract spatial minimum land surface temperature for each pentad
lst_min <- addVarEEcollection(ee_pentads = pentads,
                                 collection = "MODIS/061/MOD11A1",
                                 dates = c("2010-01-01", "2011-01-01"),
                                 temp_reducer = "mean",
                                 spt_reducer = "min",
                                 bands = "LST_Day_1km")

## Extract spatial maximum land surface temperature for each pentad
lst_max <- addVarEEcollection(ee_pentads = pentads,
                                 collection = "MODIS/061/MOD11A1",
                                 dates = c("2010-01-01", "2011-01-01"),
                                 temp_reducer = "mean",
                                 spt_reducer = "max",
                                 bands = "LST_Day_1km")

## Create a site covariate data frame for input into addEEtoUnmarked_single().
## Note the first column is called "pentad" which is a requirement for the function to work properly.
my_ee_data <- bind_cols(pentad = ndvi_mean$pentad,
                     ndvi_SD = ndvi_sd$NDVI_stdDev,
                     ndvi_MEAN = ndvi_mean$NDVI_mean,
                     temp_MIN = lst_min$LST_Day_1km_min,
                     temp_MAX = lst_max$LST_Day_1km_max)

## Add GEE covariates to unmarked frame
umf_single_ee <- addEEtoUnmarked_single(umf = umf_single,
                                       ee_data = my_ee_data)
summary(umf_single_ee)

## A slightly different example:
## Annotate ABAP data with multiple bands from a GEE collection
pentads_tc <- addVarEEcollection(ee_pentads = pentads,
                                 collection = "IDAHO_EPSCOR/TERRACLIMATE",
                                 dates = c("2010-01-01", "2011-01-01"),
                                 temp_reducer = "mean",
                                 spt_reducer = "mean",
                                 bands = c("tmmx", "tmmn"))

## Select the variables to transfer to the unmarked frame, making sure
## 'pentad' is amongst them
my_ee_data <- pentads_tc %>%
    select(pentad, tmmx_mean, tmmn_mean)

## Add GEE covariates to unmarked frame
umf_single_ee <- addEEtoUnmarked_single(umf = umf_single,
                                        ee_data = my_ee_data)

summary(umf_single_ee)


## End(Not run)

AfricaBirdData/ABAP documentation built on Aug. 4, 2024, 4:41 p.m.