trouble with trap.builder

103 views
Skip to first unread message

ejh20

unread,
Oct 22, 2014, 2:43:04 PM10/22/14
to secr...@googlegroups.com
Good day,
We are attempting to simulate camera-trap sampling within a national park.  We'd like to simulate different trap layouts.
I created a cluster of traps as a traps object using make.grid and subset:
#
tenX500 = make.grid(nx = 21, ny = 21, spacex = 500, spacey = 500, detector = "proximity")
#
cross12 = subset(tenX500, subset = c("A11","I11","J11","K 1","K 9",'K10',"K12","K13","K21","L11","M11","U11"))
#
This gives a 10 km X 10 km box or cross shape defined by 4 traps, with a smaller 2 km X 2 km "X" or cross shape in the center. 
We have the park boundary as a SpatialPolygonsDataFrame (knpb.spdf).  I used it (with gBuffer and make.mask) to define a finite sampling frame for trap.builder:
#
knp.interior = gBuffer(knpb.spdf, width = -4000)
df = data.frame(1)
knp.int = SpatialPolygonsDataFrame(knp.interior, df, match.ID = F)

#
fr.mask = make.mask(spacing = 1000, type = c("polygon"), poly = knp.int)
#
fr = as.data.frame(fr.mask)
#
This gives me a finite sampling frame with points 1000 m apart, all of which are at least 4000 m inside the park boundary.
However, when I try to use trap.builder with edgemethod = c("allinside"), I get error messages 
#
> l1 = trap.builder(n = 4, cluster = cross12, region = knpb.spdf, frame = fr,
+ method = c("GRTS"),edgemethod = c("allinside"),detector = "proximity",
+ samplefactor = 10, plt = TRUE)
Stratum: None
Current number of levels: 3
Current number of levels: 5
Final number of levels: 5
Error in trap.builder(n = 4, cluster = cross12, region = knpb.spdf, frame = fr,  :
  not enough clusters inside polygon
> l1 = trap.builder(n = 4, cluster = cross12, region = knpb.spdf, frame = fr,
+ method = c("GRTS"),edgemethod = c("allinside"),detector = "proximity",
+ samplefactor = 100, plt = TRUE)
Stratum: None
Current number of levels: 5
Current number of levels: 7
Current number of levels: 8
Current number of levels: 9
Final number of levels: 9
Error in origins[i, ] : subscript out of bounds
In addition: There were 50 or more warnings (use warnings() to see the first 50)
#
I tried setting edgemethod = "clip" to see if that was the only problem, and got a different error message.
#
> l1 = trap.builder(n = 4, cluster = cross12, region = knpb.spdf, frame = fr,
+ method = c("GRTS"),edgemethod = c("clip"),detector = "proximity",
+ samplefactor = 10, plt = TRUE)
Stratum: None
Current number of levels: 3
Current number of levels: 5
Final number of levels: 5
Error in `row.names<-.data.frame`(`*tmp*`, value = c("1.A11", "1.I11",  :
  duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique value when setting 'row.names': ‘NA.NA’

Not sure what I'm doing wrong here, but any advice would be welcome.
Thanks,
Eric








Murray Efford

unread,
Oct 22, 2014, 5:00:18 PM10/22/14
to secr...@googlegroups.com
Eric
I tried running your code with my own SpatialPolygonsDataFrame and didn't have a problem (see attached), so I'm not sure what is going on. My SPDF was a large single polygon. If you like you could send yours offline and I could probe deeper, in a couple of days.
Murray
demo.png

Murray Efford

unread,
Oct 23, 2014, 8:59:00 PM10/23/14
to secr...@googlegroups.com
Eric

I think we are getting different results because the attributes of your SPDF (knpb.spdf) include NA values and mine don't. This shouldn't be a problem, except that the test for 'allinside' in trap.builder (mistakenly) expects the 'over' method of 'sp' to return only a vector of nonmissing values, whereas the return value includes attributes if they are present in the input. The attributes are not really relevant, and I'll re-engineer trap.builder to avoid them. Meantime, it seems that you can work around simply by calling trap.builder with region = polygons(knpb.spdf) instead of region = knpb.spdf.

Let me know if that doesn't work!

Murray

On Thursday, October 23, 2014 7:43:04 AM UTC+13, ejh20 wrote:

ejh20

unread,
Oct 24, 2014, 11:25:25 AM10/24/14
to secr...@googlegroups.com
Thanks Murray, it did work.
-Eric
Reply all
Reply to author
Forward
0 new messages