How do habitat variables interact with comparisons of cougar activity and mule deer, elk, and human activity over the diel cycle?
Based on the literature, relevant variables that may impact cougar-prey interactions include ruggedness, tree cover, and edge habitat variables. I would take the following steps to address how these spatial variables influence species interactions: 1. Create layers for each of the spatial variables based on existing methods in the wildlife literature. 2. Buffer camera-trap point locations with a 250 meter radius. 3. Overlay habitat variables with buffered camera-trap point locations. 4. Export the proportion of each habitat class within the buffers around each camera location, then save results in a CSV file connecting habitat variables to each camera-trap location. 5. Assign habitat variables to species activity data by a common variable- namely the camera site. 6. Model species temporal activity at each site using habitat variables as predictors- either using GAM or logistical regression. 7. Incorporate presence/absence of the other three target species into each species model to determine whether activity changes based on community interactions.
My primary spatial data includes: 1. USGS 10-meter DEM data from the UT AGRC - ruggedness/topography/elevation 2. SWReGAP landcover data link - landcover 3. LANDFIRE Existing Vegetation Cover link- edge 4. Camera-trap coordinates
These data are connected, through camera-trap site names, to species detection data collected during my undergraduate research with the USU Cougar Project. This dataset includes camera site, date, time, and species detected for each time the camera was self-triggered by an animal.
(See below for visualizations of each dataset)
I transformed each of the datasets into a UTM Zone 12 projection because of the local scale of my study area. This will also be of use when I am buffering because UTM has a clear unit - the meter - to work with.
# Set up R workspace
setwd('C:/Users/Maggie/Documents/GEOG4950/Project')
library(sp)
library(rgdal)
library(raster)
getClass("Spatial")
## Class "Spatial" [package "sp"]
##
## Slots:
##
## Name: bbox proj4string
## Class: matrix CRS
##
## Known Subclasses:
## Class "SpatialPoints", directly
## Class "SpatialMultiPoints", directly
## Class "SpatialGrid", directly
## Class "SpatialLines", directly
## Class "SpatialPolygons", directly
## Class "SpatialPointsDataFrame", by class "SpatialPoints", distance 2
## Class "SpatialPixels", by class "SpatialPoints", distance 2
## Class "SpatialMultiPointsDataFrame", by class "SpatialMultiPoints", distance 2
## Class "SpatialGridDataFrame", by class "SpatialGrid", distance 2
## Class "SpatialLinesDataFrame", by class "SpatialLines", distance 2
## Class "SpatialPixelsDataFrame", by class "SpatialPoints", distance 3
## Class "SpatialPolygonsDataFrame", by class "SpatialPolygons", distance 2
# Read in spatial data - note: I have already cropped these ones (roughly) to the extent of my study area
dem <- raster('DEM_cropped.tif')
gap <- raster('gap_cropped.tif')
evc <- raster('evc_crop.tif')
# Check coordinate systems - note: these were reprojected to UTM Zone 12 during the process of cropping
dem@crs
## CRS arguments:
## +proj=utm +zone=12 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m
## +no_defs
gap@crs
## CRS arguments:
## +proj=utm +zone=12 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m
## +no_defs
evc@crs
## CRS arguments:
## +proj=utm +zone=12 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m
## +no_defs
# Create camera-trap point layer and set projection as UTM Zone 12 N.
cam_data <- read.csv('CameraUTMs.csv',sep="\t")
cam_data <- as.data.frame(cam_data)[1:37,] # need to find paperwork for a few sites at the end of the full CSV...
pts <- list(cam_data$UTM_Easting, cam_data$UTM_Northing)
prj = dem@crs
data <- as.data.frame(pts)
cams <- SpatialPointsDataFrame(data=data, coords=pts, proj4string=prj)
class(cams) # double check class as spatial points df
## [1] "SpatialPointsDataFrame"
## attr(,"package")
## [1] "sp"
cams@proj4string # double check in UTM 12 N
## CRS arguments:
## +proj=utm +zone=12 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m
## +no_defs
names(cams@data) <- c("UTM_Easting","UTM_Northing")
cams@data <- cbind(cams@data,cam_data[2])
For the habitat variables created to be of any use in species activity models, I need to link species detection data to camera locations by camera site name.
photo <- read.csv('C:/Users/Maggie/Documents/GEOG4950/Project/photo data.csv')
photo <- as.data.frame(photo)
unique(photo$Site) # double check that values match
## [1] LC3 LC8 LC5 LC6 LC7 GC1 GC2
## [8] LC2 DC2 LC4 LC1 Sawmill 03_07 03_04
## [15] 03_01 03_05 05_04 05_03 05_08 05_07 05_07_02
## [22] 05_05 05_01 07_04 07_02 07_01 09_04 04_06
## [29] 04_07 04_05 04_01 04_04 09_05 09_08 08_09
## [36] 09_07 09_02 09_01
## 38 Levels: 03_01 03_04 03_05 03_07 04_01 04_04 04_05 04_06 04_07 ... Sawmill
unique(cams$Site)
## [1] GC1 GC2 DC1 DC2 LC1 LC2 LC3
## [8] LC4 LC5 LC7 03_01 03_03 03_04 03_05
## [15] 03_07 Sawmill 05_01 02_09 05_04 05_07 05_07_02
## [22] 05_08 RH1 RH2 07_01 07_02 07_04 09_01
## [29] 09_04 09_05 09_07 09_08 04_01 04_02 04_04
## [36] 04_05 04_06
## 39 Levels: 02_09 03_01 03_03 03_04 03_05 03_07 04_01 04_02 04_04 ... Sawmill
total <- merge(photo,cams@data,by=c("Site"))
I extracted camera-traps with cougar detections and plotted these against the number of deer photos at each camera site. Surprisingly enough, the cougar detections appear to be occuring at camera sites where less deer were photographed.
library(spdplyr)
## Warning: package 'spdplyr' was built under R version 3.4.3
## Loading required package: dplyr
## Warning: package 'dplyr' was built under R version 3.4.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:raster':
##
## intersect, select, union
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library("sp")
library("latticeExtra")
## Warning: package 'latticeExtra' was built under R version 3.4.3
## Loading required package: lattice
## Loading required package: RColorBrewer
library(RColorBrewer)
unique(total$Species)
## [1] Snowshoe Hare Squirrel Flying Squirrel
## [4] Weasel Coyote Moose
## [7] Mule Deer Elk Human
## [10] Domestic Dog Horse (domestic) Red Fox
## [13] Raccoon Cottontail Rabbit Cougar
## [16] Unknown Bird Rat
## [19] Striped Skunk Cattle Mountain Goat
## [22] Mink Domestic Sheep
## 23 Levels: Bird Cattle Cottontail Rabbit Cougar Coyote ... Weasel
head(total)
## Site Date Time Species Inds Cam_Model hour
## 1 03_01 12/2/2016 0:23 Snowshoe Hare 1 PC85 RAPIDFIRE PRO 0
## 2 03_01 11/3/2016 13:40 Squirrel 1 PC85 RAPIDFIRE PRO 13
## 3 03_01 11/18/2016 20:52 Flying Squirrel 1 PC85 RAPIDFIRE PRO 20
## 4 03_01 11/3/2016 9:05 Squirrel 1 PC85 RAPIDFIRE PRO 9
## 5 03_01 11/13/2016 0:18 Squirrel 1 PC85 RAPIDFIRE PRO 0
## 6 03_01 11/13/2016 0:18 Squirrel 1 PC85 RAPIDFIRE PRO 0
## minute Season Behavior PUCO UTM_Easting UTM_Northing
## 1 23 FA16 NA 0 454449 4635345
## 2 40 FA16 NA 0 454449 4635345
## 3 52 FA16 NA 0 454449 4635345
## 4 5 FA16 NA 0 454449 4635345
## 5 18 FA16 NA 0 454449 4635345
## 6 18 FA16 NA 0 454449 4635345
puma <- total %>%
group_by(Site) %>%
filter(Species=="Cougar") %>%
summarize(inds=sum(Inds))
## Warning: package 'bindrcpp' was built under R version 3.4.3
deer <- total %>%
group_by(Site) %>%
filter(Species=="Mule Deer") %>%
summarize(inds=sum(Inds))
puma <- merge(cams,puma,by="Site")
for (i in 1:37) if(is.na(puma$inds[i])) puma$inds[i] <- 0
deer <- merge(cams,deer,by="Site")
for (i in 1:37) if(is.na(deer$inds[i])) deer$inds[i] <- 0
class(puma); class(deer)
## [1] "SpatialPointsDataFrame"
## attr(,"package")
## [1] "sp"
## [1] "SpatialPointsDataFrame"
## attr(,"package")
## [1] "sp"
puma <- puma[puma$inds!=0,]
pal <- brewer.pal(n=11,name='RdYlGn')
p <- spplot(deer[2:37,], # plot census tracts
"inds", # `AREAWATR` as choropleth sybmoblized variable
col.regions=pal, # specify color palette
cuts=10, # specify # breaks (n-1 from pal)
col='transparent',
main="Cougar Detections Compared\n to Deer Photos at Camera-Traps") # title
p + layer(panel.points(puma$UTM_Easting, puma$UTM_Northing, col="black", pch=3), data=puma)
Creating an edge layer will require a binary layer coding trees vs. no trees. Here, I reclassified the Existing Vegetation Cover raster first into cover types, and then into trees/no trees.
new_cover <- c(10,100,110,120,150,154,100,109,119,129,154,172,0,1,2,3,4,5)
mat3 <- matrix(data=new_cover,ncol=3)
evc2 <- reclassify(evc,rcl=mat3)
plot(evc2)
# 0 = developed, 1 = tree cover, 2 = shrubs, 3 = herbs, 4 = tree canopy, 5 = other canopy
mat4 <- matrix(data = c(0,1,1,1,5,0),byrow=TRUE,ncol=3)
trees <- reclassify(evc2,rcl=mat4)
plot(trees)
To get an idea of what may be driving cougar detections, I plotted all camera-traps against each habitat layer, while also recoloring camera-traps where cougars were detected. * Elevation: The camera-traps seem to largely be located in low (white) and mid-elevation (red) areas, although a few are located at high elevations (green). Cougar detections seem to be focused in upper mid-elevation (orange/yellow) areas. * Tree Cover: Most of the camera-traps appear to be located in cover and near edges between tree cover and no tree cover. Cougar detections appear to largely occur in the locations where tree cover and lack of tree cover meet. * Landcover: Cameras appear to primarily be located in areas with red/yellow labels, cougar detections appear to occur in whichever landcover class is yellow.
library(ggmap)
# transform all spatial layers to crs that ggmap uses
crs <- CRS("+init=epsg:4269")
cams_crs <- spTransform(cams,crs)
puma_crs <- spTransform(puma,crs)
dem_crs <- projectRaster(dem,crs=crs)
tree_crs <- projectRaster(trees,crs=crs)
gap_crs <- projectRaster(gap,crs=crs)
# convert shapefile data to data frames for mapping and define variable names
cams_df <- data.frame(cams_crs)
names(cams_df) <- c("UTM_E","UTM_N","Site","x.coord","y.coord","optional")
puma_df <- data.frame(puma_crs)
names(puma_df) <- c("Site","UTM_E","UTM_N","inds","x.coord","y.coord","optional")
# specify basemap
base_map <- get_map(location="logan", zoom=10, maptype="terrain", source="google", crop=T)
# Visualizing camera-traps and cougar detections in relation to DEM layer
ggmap(base_map) + # baselayer
# dem raster
inset_raster(as.raster(dem_crs),
xmin = dem_crs@extent[1],
xmax = dem_crs@extent[2],
ymin = dem_crs@extent[3],
ymax = dem_crs@extent[4]) +
# all camera-traps
geom_point(data=cams_df,mapping=aes(x=x.coord,y=y.coord)) +
# camera-traps where cougars detected
geom_point(data=puma_df,mapping=aes(x=x.coord,y=y.coord),color="red") +
ggtitle("Camera-Traps Overlayed on Elevation\n(red points where cougars detected)") +
theme(plot.title=element_text(color="black", face="bold", size=14),
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
axis.ticks=element_blank(),
axis.title=element_blank(),
axis.text=element_blank()) +
coord_fixed()
# Visualizing camera-traps and cougar detections in relation to tree binary layer
ggmap(base_map) + # baselayer
# binary tree raster
inset_raster(as.raster(tree_crs),
xmin = tree_crs@extent[1],
xmax = tree_crs@extent[2],
ymin = tree_crs@extent[3],
ymax = tree_crs@extent[4]) +
# all camera-traps
geom_point(data=cams_df,mapping=aes(x=x.coord,y=y.coord)) +
# camera-traps where cougars detected
geom_point(data=puma_df,mapping=aes(x=x.coord,y=y.coord),color="red") +
coord_fixed() +
ggtitle("Camera-Traps Overlayed on Tree Cover\n(red points where cougars detected)")
# Visualize camera-traps and cougar detections in relation to SWReGAP layer
ggmap(base_map) + # baselayer
# SWReGAP raster
inset_raster(as.raster(gap_crs),
xmin = gap_crs@extent[1],
xmax = gap_crs@extent[2],
ymin = gap_crs@extent[3],
ymax = gap_crs@extent[4]) +
geom_point(data=cams_df,mapping=aes(x=x.coord,y=y.coord)) +
geom_point(data=puma_df,mapping=aes(x=x.coord,y=y.coord),color="red") +
ggtitle("Camera-Traps Overlayed on Landcover\n(red points where cougars detected)") +
coord_fixed()
I plotted camera-traps where each species has been detected, while also color-coding by the monitoring season. This allows me to get some idea of the spatial and temporal distribution of detections for each species. I added labels to camera sites for easier interpretation of species interactions and removed the legend for color labels on camera sites, because the reason for grouping by site was mostly just to visualize which cameras were active concurrently. There’s a lot to unpack in the results, but here is what I found most interesting: * The cougar detections are clumped in the Right Hand Fork area at the center of the map, but it is also obvious that they have a wide distribution because camera-sites near the edges of the maps also have detections. * Coyote detections appear clumped in the Dry Canyon area. * Human detections are surprisingly well-distributed given that most of these locations are off-trail. * Moose detections appear to be clumped in two areas: Dry Canyon (bottom left) and the Ephraim’s grave area (bottom right). * Mule Deer detections are just about ubiquitous.
library(tmap)
total <- SpatialPointsDataFrame(data=data.frame(total), coords=list(total$UTM_Easting,total$UTM_Northing), proj4string=prj)
tmap_mode("plot")
## tmap mode set to plotting
tm_shape(total) +
tm_dots(col='Season',size=0.8,legend.show=FALSE) + #specify color by monitoring season
tm_view(basemaps="OpenTopoMap",alpha=1,basemaps.alpha=1) +
tm_facets("Species",ncol=2,free.coords=FALSE) +
tmap_options(tmap.limits=c(facets.plot=64,facets.view=23)) +
tm_compass(position=c("right","top"),type="4star") + #add compass
tm_scale_bar() +
tm_style_gray() + #specify background style
tm_text(text="Site",size=2)