make.mask to exclude non-habitat

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

make.mask to exclude non-habitat

Postby demarsea » Tue Jun 08, 2021 10:44 am

Hello Murray,

I've been troubleshooting the make.mask function but not having any luck through forums or with the secr guide. Hopefully you can help me figure out what I've done wrong here.

I have created a polygon shapefile in ArcMap that includes all of the potentially useable habitat at my study site, which excludes non-habitat. I'm unclear in what exact format the program needs this shape file to be in, because no matter how I input it I keep getting errors back.

Here's what I've done:
Code: Select all
library(secr)
library(sp)
library(rgdal)

captfile <- read.delim("CaptAld19.txt")
trapfile <- read.delim("trapsAld19.txt")
Ald2019CH <- read.capthist("CaptAld19.txt", "trapsAld19.txt", detector="count")
Ald2019aCH <- read.capthist("CaptAld19.txt", "trapsAld19.txt",
              fmt=NULL, detector="count"),
              noccasions=40,
              markocc=c(1,1,0,1,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
                        1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0))
Ald2019aCH <- addSightings(Ald2019aCH, nonID="TmAld19.txt",
              unmarked="TuAld19.txt", uncertain="TnAld19.txt")


#Basic mask: no errors
Code: Select all
mask <- make.mask(traps(Ald2019aCH))


#Approach 1: Input as shapefile
Code: Select all
library(sf)
st_read("Useable.shp")
Useable <- st_read("Useable.shp")
make.mask(traps(Ald2019aCH), type='trapbuffer', buffer=400, poly='Useable')
#Error in insidecpp(xy1, 0, np - 1, as.matrix(poly)) :
#Not compatible with requested type: [type=character; target=double].
#Troubleshooting, input differently
UsedHabitat <- rgdal::readOGR(dsn=".", layer="Export_usepts")
UsedHabitat2 <- rgdal::readOGR(dsn=".", layer="Useable")
class(UsedHabitat) #This one is "SpatialPointsDataFrame"
class(UsedHabitat2) #This one is "SpatialPolygonsDataFrame"
make.mask(traps, spacing=10, type="trapbuffer", poly="UsedHabitat2", poly.habitat=TRUE)
#Error in nearestcpp(as.matrix(X), as.matrix(trps)) :
 #Not compatible with requested type: [type=character; target=double].
make.mask(traps, spacing=10, type="polybuffer", poly="UsedHabitat2", poly.habitat=TRUE)
#Error in xl + buffx : non-numeric argument to binary operator


#Approach 2: Input as .csv
Code: Select all
Useablept <- read.csv('Useable_Pts.csv', header=TRUE, sep=",", dec=".")
make.mask(traps(Ald2019aCH), type='trapbuffer', poly='Useablept')
#Error in insidecpp(xy1, 0, np - 1, as.matrix(poly)) :
#Not compatible with requested type: [type=character; target=double]

#Troubleshoot
make.mask(traps, type=c("trapbuffer"), buffer=400, poly=c("Useable"))
#error "Object of type 'closure' is not subsettable.

#Troubleshoot
make.mask(traps(Ald2019aCH), type=c("trapbuffer"), buffer=400, poly=c("Useable"))
# error "In inside cpp(cy1, 0, np - 1, as.matrix(poly)):
#Not compatible with requested type: [type=character; target=double].



If you could help me sort out what has gone wrong I'd really appreciate it!
Best wishes,
Angela
demarsea
 
Posts: 4
Joined: Wed Mar 17, 2021 12:23 pm

Re: make.mask to exclude non-habitat

Postby murray.efford » Thu Jun 10, 2021 11:16 pm

A SpatialPolgonsDataFrame should be OK (poly = UsedHabitat2). "UsedHabitat2" in quotes is a character string, not a SpatialPolgonsDataFrame. That simple?
murray.efford
 
Posts: 686
Joined: Mon Sep 29, 2008 7:11 pm
Location: Dunedin, New Zealand

Re: make.mask to exclude non-habitat

Postby demarsea » Mon Jun 21, 2021 12:41 pm

It was that simple! Still new to R. Thank you for taking the time to respond. :oops:
demarsea
 
Posts: 4
Joined: Wed Mar 17, 2021 12:23 pm


Return to analysis help

Who is online

Users browsing this forum: No registered users and 13 guests