Skip to content

Commit

Permalink
tweak comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Jonsen committed Feb 6, 2024
1 parent 7d0f804 commit a87ae79
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions data-raw/potential_fn_gradients.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ proj <- "+proj=merc +units=km +datum=WGS84"
## create world land raster
wm <- rnaturalearth::ne_countries(scale = 10, returnclass = "sf")

## set resolution to ensure a sufficiently small file size for the R pkg
## finer resolutions may be more useful for custom applications
y <- terra::rast(crs = sf::st_crs(wm)$wkt,
vals = 1,
resolution = c(0.25, 0.25),
resolution = c(0.25, 0.25),
xmin = -180,
xmax = 180,
ymin = -86,
Expand All @@ -27,13 +29,15 @@ x[is.na(x)] <- -1
x[x == 1] <- NA
x[x == -1] <- 1

## calculate gradient rasters - these are needed to keep fish off land
## calculate gradient rasters - these are needed to keep animals off land
dist <- terra::distance(x)
x1 <- terra::terrain(dist, v = "slope", unit = "radians")
y1 <- terra::terrain(dist, v = "aspect", unit = "radians")
grad.x <- -1 * x1 * cos(0.5 * pi - y1)
grad.y <- -1 * x1 * sin(0.5 * pi - y1)
grad <- c(grad.x, grad.y)

## need to use terra::wrap() to export the rasters & terra::unwrap() to import
## from an exported (wrapped) file
grad <- terra::wrap(grad)
save(grad, file = "inst/extdata/grad.rda", compress = "xz")

0 comments on commit a87ae79

Please sign in to comment.