An open API service indexing awesome lists of open source software.

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

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.