From 3a5ddc263f89f2937eb36a08b577f59e3a2a0b91 Mon Sep 17 00:00:00 2001 From: Sami Domisch Date: Tue, 10 Dec 2024 16:22:03 +0100 Subject: [PATCH] Update get_pfafstetter_basins.R Added a pre-selection of the 100 longest streams from which the most contributing (main) stream will be identified based on the area --- R/get_pfafstetter_basins.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/R/get_pfafstetter_basins.R b/R/get_pfafstetter_basins.R index 53c1a8b8..8d79e617 100644 --- a/R/get_pfafstetter_basins.R +++ b/R/get_pfafstetter_basins.R @@ -165,7 +165,15 @@ g_dt_tmp <- setDT(igraph::as_data_frame(g)) g <- graph.data.frame(g_dt_tmp[,c("from", "to")], directed = T) # Get all possible paths from the outlet outlet = which(degree(g, v = V(g), mode = "out")==0, useNames = T) -headwater = which(degree(g, v = V(g), mode = "in")==0, useNames = T) +#headwater = which(degree(g, v = V(g), mode = "in")==0, useNames = T) # all, slow + + +### Get a pre-selection of those 100 main stream candidates that have the +### longest distance to the outlet (the most contributing stream is likely to +### to be one of these) +headwater <- g_dt_tmp[order(-out_dist)]$from[1:100] +headwater <- headwater[!is.na(headwater)] # remove NAs if less than 100 subc_id + # Stop if too many outlets if (length(outlet)!=1) {