GithubHelp home page GithubHelp logo

jsta / streamnet Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 3.0 2.39 MB

Morphology analysis of stream networks ๐Ÿƒ

Home Page: https://jsta.github.io/streamnet/

R 94.45% C++ 5.55%
limnology geomorphology

streamnet's Introduction

streamnet

CRAN status Lifecycle: experimental Travis-CI Build Status DOI

Morphology analysis of stream networks

Installation

You can install streamnet from github with:

# install.packages("devtools")
devtools::install_github("jsta/streamnet")

In addition, many functions require a system installation of GRASS 7 along with the v.stream.order extension.

There is a helper function to install v.stream.order at streamnet:::install_grass_extensions.

Usage

Calculate morphology metrics

library(sf)
library(nhdR)
library(streamnet)
library(ggplot2)
library(raster)
data(nhd_sub_lines)
data(nhd_sub_lakes)

outlet_reach   <- terminal_reaches(network = nhd_sub_lines, 
                                   approve_all_dl = TRUE, quiet = TRUE)
outlet_point   <- st_cast(st_line_sample(outlet_reach, sample = 1), "POINT")

ggplot() +
  geom_sf(data = nhd_sub_lines) +
  geom_sf(data = outlet_point, aes(color = "red")) +
  scale_color_manual(labels = "outlet", values = "red") +
  labs(colour = "") + theme_minimal()

calc_metrics(nhd_sub_lines, nhd_sub_lakes)

Simplify stream networks

data(nhd_sub_lines)

# Combine(dissolve) adjacent reaches with no junctions
nhd_sub_simple <- simplify_network(nhd_sub_lines)
avg_link_length(nhd_sub_simple)
#> 2444.693 [m]
avg_link_length(nhd_sub_lines)
#> 1312.988 [m]

Round-trip igraph and sf lines

tree <- create_reversed_tree(15)
class(tree)
#> [1] "igraph"
plot(tree)

tree_sf <- igraph2sf(tree)
plot(tree_sf)

Create synthetic stream networks

# Diffusion limited aggregation
dt <- sim_dla()
viz_dla(dt, which.max(dt))

# Generate from a binary raster
foo <- matrix(0, ncol = 9, nrow = 9)
foo[1:4,3] <- 1
foo[5,4]   <- 1
foo[6:9,5] <- 1
foo <- raster(foo, xmn = 1, xmx = 9, ymn = 1, ymx = 9)
origin <- which.min(apply(
              which(as.matrix(flip(foo, "y")) == 1, arr.ind = TRUE), 1, sum))
res <- raster2network(foo, origin)

par(mfrow = c(1, 2))
plot(foo)
plot(foo); plot(res, add = TRUE)

streamnet's People

Contributors

jsta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

streamnet's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.