knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(sf,warn.conflicts=FALSE) library(assimReservoirs,warn.conflicts=FALSE) library(dplyr,warn.conflicts=FALSE) library(igraph,warn.conflicts=FALSE) library(knitr,warn.conflicts=FALSE) library(ggplot2,warn.conflicts=FALSE)
knitr::include_graphics('/home/delgado/proj/assimReservoirs/screenshot.png')
We use HydroSHEDS as a consistent global river dataset. The resolution is about 90 m around the equator (3 arc-seconds).
Lehner, B., Verdin, K., Jarvis, A. (2008): New global hydrography derived from spaceborne elevation data. Eos, Transactions, AGU, 89(10): 93-94.
plot(riv["UP_CELLS"]) # ggplot(riv) + geom_sf(aes(color=UP_CELLS))
Since the river network dataset of HydroSHEDS has valid topology, we can operate on it with package igraph, using graph theory. We can for example obtain all disjoint components of the graph:
riv_split = split_river_network(riv) plot(riv_split["membership"]) split_river_network
Selecting a river system by a reach id, eg in the Jaguaribe river basin:
reach_id=140877 riv_jagua = select_disjoint_river(reach_id,riv_split) plot(riv_jagua["UP_CELLS"])
We use the JRC global surface water dataset.
Jean-Francois Pekel, Andrew Cottam, Noel Gorelick, Alan S. Belward, High-resolution mapping of global surface water and its long-term changes. Nature 540, 418-422 (2016). (doi:10.1038/nature20584)
Resolution is 30 m. We run
allocate_reservoir_to_river(riv),Routing_strat() andRouting_non_strat()in advance in order to create a graph. Then we can obtain any subgraph of choice.
head(reservoir_graph)
Identify adjacent reservoirs upstream of 34560:
id='34560' neighbors(reservoir_graph,id,'in')
Identify all reservoirs upstream of 34560:
sub=all_simple_paths(reservoir_graph,from=id,mode='in') %>% unlist %>% unique Vsubgraph = induced_subgraph(reservoir_graph, sub ,impl='auto')
...and plot:
plot(Vsubgraph) vertices = V(Vsubgraph) res_subgraph = filter(res_max,res_max$id_jrc %in% vertices$name) reach_id = filter(res_subgraph,`id_jrc`==id) %>% pull(`nearest river`) riv_upstr=river_upstream(reach_id,riv,river_graph) res_subgraph %>% mutate(`nearest river`=as.factor(`nearest river`)) %>% ggplot(.) + geom_sf(aes(color=`nearest river`)) + geom_sf(data=riv_upstr)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.