akde hard boundaries

213 views
Skip to first unread message

Chris2

unread,
Sep 28, 2022, 5:34:28 PM9/28/22
to ctmm R user group
Hello Chris and others,

I have been trying to force hard boundaries with akde, but I have not been successful. Perhaps I am not setting up the SpatialPolygonsDataFrame object correctly? It is in the same projection as the data, as a first check. I include a reproducible example here if anyone who has been successful with this wants to have a look where I go wrong. Any pointers would be much appreciated. 

The code is for 2 marine predators. The hard boundary is 'coastlines', and I am trying to prevent the UD from going onto land. 
I created these SpatialPolygonsDataFrame from bathymetry data, setting 0 m above sea level as the polygon line, but I was not sure whether the inside of the polygons should have values, be NA, etc. When I didn't get this to work, I created a third SpatialPolygonsDataFrame in the code, which is a simpler test 'boundary'.  But, as the plots show, the UD still crosses the hard boundary I am trying to enforce.

Thanks,
Chris
exampledat2.rds
coastlineSpatialPolygonsDataFrameUTM.rds
coastlineNA.rds
akde hard boundary.R

Christen Fleming

unread,
Sep 29, 2022, 4:08:18 PM9/29/22
to ctmm R user group
Hi Chris,

You don't need them in the same projection.
The first thing I did was plot the data with the imported shapefiles as a visual check:

plot(DATA,col=c('red','blue'),SP=coast,col.SP='grey') # everything seems to be inside a polygon?
plot(DATA,col=c('red','blue'),SP=coastNA,col.SP='grey') # looks good, as far as I can tell

I don't know what anything is, but the second one looks like something, so I went with that.
I then calculated AKDEs and a PKDE just with SP= coastNA and they both looked okay to me.

But, in your code, you do a bunch of extra steps with raster, sf, stars, and I don't see anything in the sp::plot of the output tstUTM object before akde and pkde are called.

Best,
Chris
Message has been deleted

Chris2

unread,
Oct 9, 2022, 10:11:59 AM10/9/22
to ctmm R user group
My post above has at least two issues that Chris helped me to correct. The code is working now and I am just posting a reply here should it be useful to someone in future.

My first mistake was that I did not supply the SP argument in pkde(). The shapefile is not carried over in the individual UDs and hence my population level UD was not adjusted for hard boundaries. I should have looked at ?pkde.

The code below shows how you can make a land mask (hard barrier) from bathymetry data. 

library(raster)
# read in bathymetery raster
r = raster('./ibcso.tif')
# set cells above sea level to NA and others to 1. (i.e., the NA cells are areas where animals can't go).
r[r >= 0] <- NA
r[r < 0] <- 1
library(stars)
library(sf)
spdf = as_Spatial(st_as_sf(stars::st_as_stars(r),
                        as_points = F, merge = T))
raster::plot(spdf, col="red",border="green")

Reply all
Reply to author
Forward
0 new messages