aggregate_network: Aggregate Network

View source: R/aggregate_network.R

aggregate_networkR Documentation

Aggregate Network

Description

Aggregates a catchment network according to a set of outlet.

Usage

aggregate_network(
  flowpath,
  outlets,
  da_thresh = NA,
  only_larger = FALSE,
  post_mortem_file = NA
)

Arguments

flowpath

sf data.frame Flowpaths with ID, toID, LevelPathID, and Hydroseq attributes.

outlets

data.frame with "ID" and "type" columns. "ID" must be identifiers from fowpath and divide data.frames. "type" should be "outlet", or "terminal". "outlet" will include the specified ID. "terminal" will be treated as a terminal node with nothing downstream.

da_thresh

numeric Defaults to NA. A threshold total drainage area in the units of the TotDASqKM field of the flowpath data.frame. When automatically adding confluences to make the network valid, tributary catchments under this threshold will be lumped with the larger tributaries rather than being added to the set of output catchments.

only_larger

boolean Defaults to TRUE. If TRUE when adding confluences to make the network valid, only tributaries larger than the one with an upstream outlet will be added. e.g. if a tributary is required in the model this will add main stems that the tributary contributes to. Note that the NHDPlus treats divergences as part of the main stem, so the da_thresh may still be needed to eliminate small tributary catchments introduced by divergences near confluences.

post_mortem_file

rda file to dump environment to in case of error

Details

This function operates on the catchment network as a node-edge graph. The outlet types are required to ensure that graph searches start from the appropriate nodes and includes the appropriate catchments. Outlets such as gages should be treated as "outlet" outlets. While it may be possible for the algorithm to determine terminal outlets, at this time, it is required that they be specified explicitely as "terminal" outlet types.

The function checks supplied outlets to make sure they connect downstream. Checks verify that the outlet of the levelpath (main stem of a total catchment) of each supplied outlet is in the supplied outlet set. If the outlet of a levelpath is not in the supplied set, it is added along with other catchments that contribute to the same receiving catchment. These checks ensure that all output catchments have one and only one input and output nexus and that all catchments are well-connected.

Examples

source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))

fline <- dplyr::right_join(dplyr::select(walker_flowline, COMID),
                           nhdplusTools::prepare_nhdplus(walker_flowline, 0, 0, 0, FALSE))

fline <- dplyr::select(fline, ID = COMID, toID = toCOMID,
                       LevelPathID = LevelPathI, Hydroseq)

outlets <- data.frame(ID = c(5329357, 5329317, 5329365, 5329303, 5329435, 5329817),
                      type = c("outlet", "outlet", "outlet", "terminal", "outlet", "outlet"),
                      stringsAsFactors = FALSE)

aggregated <- aggregate_network(fline, outlets)

aggregated <- aggregate_network(fline, outlets)

outlets <- dplyr::filter(fline, ID %in% outlets$ID)

outlets <- nhdplusTools::get_node(outlets)

plot(aggregated$fline_sets$geom, lwd = 3, col = "red")
plot(walker_flowline$geom, lwd = .7, col = "blue", add = TRUE)
plot(outlets$geometry, add = TRUE)



dblodgett-usgs/hyRefactor documentation built on Oct. 14, 2024, 12:59 p.m.