Point Shapefiles and Habitat Masks

questions concerning anlysis/theory using program DENSITY and R package secr. Focus on spatially-explicit analysis.

Point Shapefiles and Habitat Masks

Postby Kubecka » Thu Feb 28, 2019 3:37 pm

Is there a way to extract covariates from point shapefiles to habitat masks? Since density can not be modeled by trap covariates, I was trying to circumvent this by making the detector a shapefile with all my covariates included therein and then add covariates of this shapefile to the mask.

For each trap site, the respective covariates are 1) distance to feeders and 2) three metrics of woody cover. I have a feeder shapefile (point vector) and TIF rasters for woody cover metrics. I have extracted all relevant metrics at each trap site. Alternatively, I've tried the "distance.to.shore" example in vignettes. Any ideas?

#####################################
#Mask
library(rgdal)
bobmask<- readOGR(".", "bobmask")
trapcov<- readOGR(".", "arc_trap")

bobMASK <- make.mask(alltraps, spacing = 165.2601,
buffer = 777, type = "trapbuffer", poly = bobmask, nx=32)

par(mar = c(1,6,6,6), xpd = TRUE)
plot (bobMASK, ppoly = TRUE)
plot(alltraps, add = T)
par(mar = c(5,4,4,2) + 0.1, xpd = FALSE)

tcov_frame<-data.frame(trapcov)

addCovariates(bobMASK, tcov_frame)
Kubecka
 
Posts: 9
Joined: Wed Feb 06, 2019 12:35 pm

Re: Point Shapefiles and Habitat Masks

Postby murray.efford » Thu Feb 28, 2019 5:19 pm

Hi
I'm not sure I fully understand, but...

As you understand, to model density as a function of covariates the covariates must be provided for each mask cell as mask covariates.

Your woody cover metrics already exist as a 2-D data source (TIF) that can presumably be imported as covariates using addCovariates (perhaps via a 'raster' object). I'm not expert at rasters, but surely this can be done.

Your other covariate is 'distance to feeder'. I would simply make sure I had the feeder point locations in a 2-column matrix or traps object 'feeders', then (assuming covariates(bobMASK) already exists)
Code: Select all
covariates(bobMASK)$distance.to.feeder <- distancetotrap(bobMASK, feeders)

Except that it may be convenient to store feeder locations in a traps object, I don't think you should mess with detectors and their covariates.

Murray
murray.efford
 
Posts: 565
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Point Shapefiles and Habitat Masks

Postby Kubecka » Thu Feb 28, 2019 11:40 pm

Thanks for the reply, Murray.

I made raster objects and tried to use it in addCovariates but to no avail. I can get them as raster objects, but can't get it to jibe in secr.

I also tried making a traps object from the feeder points, but also got errors. I pasted the errors below.


###################################
#Mask

library(rgdal)
library(sp)
library(raster)

pland<-raster::raster("pland_1.tif") #Makes woody cover raster
lpi<-raster::raster("lpi_1.tif") #Makes woody cover raster
mpa<-raster::raster("area_mn_1.tif") #Makes woody cover raster
bobmask<- readOGR(".", "bobmask") #Reads in study boundary
feeders<- read.traps(file= c("feeder_object.txt", "feeder_object.txt", "feeder_object.txt"))
# Creates trap objects for feeders, for each session

bobMASK <- make.mask(alltraps, spacing = 165.2601,
buffer = 777, type = "trapbuffer", poly = bobmask, nx=32) #Make the mask

covariates(bobMASK)$distance.to.feeder <- distancetotrap(bobMASK, feeders)

Error in `covariates<-`(`*tmp*`, value = list(traps_session1.txt = NULL, :
mismatch between multisession object and covariates


pland<-addCovariates(bobMASK, pland)
lpi<-addCovariates(bobMASK, lpi)
mpa<-addCovariates(bobMASK, mpa)

Error in addCovariates(out[[session]], spatialdata) :
spatialdata type unrecognised or unsupported


# PLOT
par(mar = c(1,6,6,6), xpd = TRUE)
plot (bobMASK, ppoly = TRUE)
plot(alltraps, add = T)
par(mar = c(5,4,4,2) + 0.1, xpd = FALSE)
Kubecka
 
Posts: 9
Joined: Wed Feb 06, 2019 12:35 pm

Re: Point Shapefiles and Habitat Masks

Postby murray.efford » Fri Mar 01, 2019 12:14 am

I forgot raster objects were not directly supported, but see
https://groups.google.com/forum/#!searchin/secrroup/raster|sort:date/secrgroup/RJux3h9Jfiw/MIk8-F1YAwAJ

I didn't anticipate that your mask object is a list of masks. You'll need to work around that by constructing covariates for each mask in turn. Start by doing it for one and convincing yourself that it works by plotting with cov = 'distance.to.feeder'.
murray.efford
 
Posts: 565
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Point Shapefiles and Habitat Masks

Postby Kubecka » Fri Mar 01, 2019 12:33 am

Raster suggestion worked! Thanks!

How might the code look for doing a single mask at a time? I tried:

covariates(bobMASK[1])$distance.to.feeder <- distancetotrap(bobMASK[1], feeders[1])

Get the same error of mismatch.
Kubecka
 
Posts: 9
Joined: Wed Feb 06, 2019 12:35 pm

Re: Point Shapefiles and Habitat Masks

Postby murray.efford » Fri Mar 01, 2019 3:52 pm

Use double [[ to select component of a list. Is feeders a list?
murray.efford
 
Posts: 565
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: Point Shapefiles and Habitat Masks

Postby Kubecka » Fri Mar 01, 2019 4:27 pm

Ahh, rookie mistake. I got all the covariates added to the mask. I ran a model in secr.fit with distance to feeder. It ran and produced reasonable estimates!

For the raster covariates I added however, I get this error when trying to run.

Error in aperm.default(temp, order(olddim)) :
invalid first argument, must be an array


Sorry for all the confusion and questions. I appreciate your patience and help!

Brad
Kubecka
 
Posts: 9
Joined: Wed Feb 06, 2019 12:35 pm

Re: Point Shapefiles and Habitat Masks

Postby murray.efford » Fri Mar 01, 2019 7:56 pm

I can't explain that. The error comes from insertdim{} that is an internal function used to create the design data. I would suspect an issue with the levels of your covariate(s). If you can't fix it then send me the data offline and I'll have a look.
Murray
murray.efford
 
Posts: 565
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand


Return to analysis help

Who is online

Users browsing this forum: No registered users and 1 guest

cron