https://github.com/mdsumner/noswimming
Prevent Animals from Swimming on Land
https://github.com/mdsumner/noswimming
Last synced: about 1 year ago
JSON representation
Prevent Animals from Swimming on Land
- Host: GitHub
- URL: https://github.com/mdsumner/noswimming
- Owner: mdsumner
- License: other
- Created: 2024-08-14T05:00:37.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-14T05:01:26.000Z (almost 2 years ago)
- Last Synced: 2025-03-19T11:19:31.985Z (about 1 year ago)
- Language: R
- Size: 332 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# noswimming
The goal of noswimming is to prevent animals from leaving the ocean. (i.e. swimming on land is not allowed)
## WIP
The name isn't very serious, or accurate, or what we want. TBD (donotcross ?)
## Installation
You can install the development version of noswimming like so:
``` r
## install.packages("remotes")
remotes::install_github("mdsumner/noswimming")
```
## Example
This is a basic example which finds the least cost path around land (we get a topographic dataset under the hood to figure this out).
```{r example}
library(noswimming)
#pt <- cbind(c(-90, 90), c(-70, -60))
pt <- cbind(c(138, 153), c(-36, -23))
path <- lcp(pt)
library(terra)
## we get the data in the projection use
plot(path)
## so reproject for longlat use
plot(terra::project(path, "EPSG:4326"), lty = 2, col = "firebrick")
maps::map(add = TRUE)
```
To turn `path` into longlat, do this:
```{r path}
ll <- terra::geom(terra::project(path, "EPSG:4326"))[,c("x", "y")]
str(ll)
```
We can also obtain the intermediate datasets used in the above process.
```{r intermediate}
pt1 <- cbind(c(-90, 90), c(-70, -60))
topo <- make_global_topo(pt1)
## here we might customize the min and max value of the topography (from [-Inf,0])
surf <- make_na_surface(topo)
path <- lcp(pt1, surf = surf)
plot(topo)
plot(path, add = TRUE, col = "hotpink")
```
It's not really going to be valid in this crs for such long pathways, but we might improve that (you would need a custom projection like Oblique Mercator).
```{r longer}
pt2 <- cbind(c(-76, -118), c(-52, 70))
topo <- make_global_topo(pt2)
## here we might customize the min and max value of the topography (from [-Inf,0])
surf <- make_na_surface(topo)
path <- lcp(pt2, surf = surf)
topo[topo > 0] <- NA
plot(topo)
plot(path, add = TRUE, col = "hotpink", lwd = 2)
```
## Code of Conduct
Please note that the noswimming project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.