Test habicon function using NIC 2019 outputs

Load libraries and package functions

devtools::load_all()

# regular checking
#devtools::check()

library(tmap)

Read in test data (using RWBL maps)

rw_suit <- terra::rast("scratch/test_data/rwbl_hab_use")

# note these are resistance values
rw_conn_raw <- terra::rast("scratch/test_data/rwbl_connect")

# rescale values
rw_conn <- rescale_map(rw_conn_raw)


terra::plot(rw_suit)
terra::plot(rw_conn)

Calculate bin maps

# using top 20% of suitability/connectivity values
suit_bin <-  bin_map(rw_suit, threshold = quantile(terra::values(rw_suit, na.rm = TRUE), 0.8))
#suit_bin <- bin_map(rw_suit, threshold = 0.75)

# Being a little more liberal on what is included for corridor calculations
corr_bin <- bin_map(1/(rw_conn+1), threshold = quantile(terra::values(1/(rw_conn+1), na.rm = TRUE), 0.4))

Compare suitability bin map to NIC cores map

nic_cores <- sf::read_sf("scratch/test_data/rwbl_core_habitat_patches.shp") |>
  sf::st_make_valid()


tmap_mode("view")

qtm(suit_bin) +
  qtm(nic_cores)

Overlap when threshold is conservative, most cores included when using the top 20% threshold.

Patch Priority

Took 4.8 hours on Mac (30m res)

start <- Sys.time()

patch <- patch_priority(
  suit = rw_suit,
  suit_bin = suit_bin,
  corr_bin = corr_bin,
  resist = rw_conn,
  d = 422,
  progress = TRUE
)

end <- Sys.time()

end - start

Save output

terra::writeRaster(terra::rast(patch[1:3]), file = "scratch/test_data/nic_patch_priority_rasters_UPDATE.tif")

write.csv(patch[4], file = "scratch/test_data/nic_patch_priority_table_UPDATE.csv")

Corridor Priority

start <- Sys.time()

corridor <- corr_priority(
  suit = rw_suit,
  suit_bin = suit_bin,
  corr_bin = corr_bin,
  resist = rw_conn,
  d = 422,
  progress = TRUE
)

end <- Sys.time()

end - start
# 2.16 hours

Save output

terra::writeRaster(corridor, file = "scratch/test_data/nic_corridor_priority_UPDATE.tif")

Visualize results

patches <- terra::rast("scratch/test_data/nic_patch_priority_rasters_UPDATE.tif")

corridors <- terra::rast("scratch/test_data/nic_corridor_priority_UPDATE.tif")

tmap_mode("view")

tm_shape(patches$qwa) +
  tm_raster(title = "Quality Weighted Area") +
  tm_shape(patches$btwn) +
  tm_raster(title = "Betweenness Centrality") +
  tm_shape(patches$dECA) +
  tm_raster(title = "Equivalent Connected Area") +
  tm_shape(corridors) +
  tm_raster(title = "Corridor Priority", style = "cont")


ccmothes/habicon documentation built on Sept. 16, 2024, 1:34 a.m.