# \donttest{
extensions <- c("shp", "shx", "dbf", "sbn", "sbx")
tmp <- tempdir()
for (ext in extensions) {
download.file(paste0(
"https://raw.githubusercontent.com/SMBC-NZP/MigConnectivity",
"/master/data-raw/Spatial_Layers/OVENdist.",
ext),
destfile = paste0(tmp, "/OVENdist.", ext), mode = "wb")
}
OVENdist <- sf::st_read(paste0(tmp, "/OVENdist.shp"))
OVENdist <- OVENdist[OVENdist$ORIGIN==2,] # only breeding
sf::st_crs(OVENdist) <- sf::st_crs(4326)
download.file(paste0("https://raw.githubusercontent.com/SMBC-NZP/MigConnectivity",
"/master/data-raw/deltaDvalues.csv"),
destfile = paste0(tmp, "/deltaDvalues.csv"))
OVENvals <- read.csv(paste0(tmp, "/deltaDvalues.csv"))
HBEFbirds <- OVENvals[grep("NH",OVENvals[,1]),]
# Create a spatial object of known capture sites
knownLocs <- sf::st_as_sf(data.frame(Long = rep(-73,nrow(HBEFbirds)),
Lat = rep(43,nrow(HBEFbirds))),
coords = c("Long","Lat"),
crs = 4326)
#Get OVEN abundance from BBS estimates and read into R #
utils::download.file("https://www.mbr-pwrc.usgs.gov/bbs/ra15/ra06740.zip",
destfile = paste0(tmp, "/oven.zip"))
utils::unzip(paste0(tmp, "/oven.zip"), exdir = tmp)
oven_dist <- sf::st_read(paste0(tmp, "/ra06740.shp"))
# Empty raster with the same dimensions as isoscape and Ovenbird distribution
# We do this manually here but the weightedAssign function has been updated
# to ensure the isoscape and abundance rasts have the same extent using
# resampling to match relAbund to the isoscape.
r <- terra::rast(nrow = 331, ncol = 870,
res = c(0.0833333, 0.0833333),
xmin = -125.1667, xmax = -52.66672,
ymin = 33.49995, ymax = 61.08327,
crs = sf::st_crs(4326)$wkt)
# rasterize the polygons from BBS - this is not needed if working with a
# rasterized surface
relativeAbun<-terra::rasterize(terra::vect(sf::st_transform(oven_dist,4326)),
r,
field = "RASTAT")
relativeAbund <- relativeAbun/terra::global(relativeAbun, sum,
na.rm = TRUE)$sum
BE <- weightAssign(knownLocs = knownLocs,
isovalues = HBEFbirds[,2],
isoSTD = 12,
intercept = -10,
slope = 0.8,
odds = 0.67,
relAbund = relativeAbund,
weightRange = c(-1, 1),
sppShapefile = OVENdist,
assignExtent = c(-179,-60,15,89),
element = "Hydrogen",
period = "Annual")
# }
Run the code above in your browser using DataLab