ResORR
  • Home

How to run ResORR

  • Network generation
  • Run ResORR model
ResORR
  • How to run ResORR
  • Network generation
  • Edit on GitHub

Network generation¶

The reservoir network represents the connectivity of the reservoirs in a basin. It is represented by a directed graph, where each node represents a reservoir and the edges represent the direction of flow of water between them.

Let us first visualize the flow direction file and the reservoir locations.

In [5]:
Copied!
import rioxarray as rxr
import xarray as xr
import numpy as np
import geopandas as gpd
import cartopy.crs as ccrs
import cartopy
import matplotlib.pyplot as plt
from pathlib import Path
import holoviews as hv
import geoviews as gv
import hvplot.xarray
import hvplot.pandas
import networkx as nx
import hvplot.networkx as hvnx

gv.extension('bokeh')
import rioxarray as rxr import xarray as xr import numpy as np import geopandas as gpd import cartopy.crs as ccrs import cartopy import matplotlib.pyplot as plt from pathlib import Path import holoviews as hv import geoviews as gv import hvplot.xarray import hvplot.pandas import networkx as nx import hvplot.networkx as hvnx gv.extension('bokeh')
No description has been provided for this image No description has been provided for this image

Let's visualize the reservoirs and the flow direction file.

In [6]:
Copied!
# read in the flow direction file
flow_dir_fn = "../../data/cumberland/flow-directions.tif"
res_location_fn = "../../data/cumberland/cumberland-stations.csv"
save_dir = "../../data/cumberland/regulation_data"

fdr = rxr.open_rasterio(flow_dir_fn, band_as_variable=True, masked=True)

reservoirs = gpd.read_file(res_location_fn)
reservoirs['geometry'] = gpd.points_from_xy(reservoirs['lon'], reservoirs['lat'])
reservoirs.set_crs('epsg:4326', inplace=True)

gv.tile_sources.OSM() \
* fdr.hvplot(x='x', y='y', geo=True, cmap='colorwheel') \
* reservoirs.hvplot(geo=True, hover_cols=['lat', 'lon', 'name']).opts(marker='triangle', fill_color='white', line_color='black', size=15, line_width=3)
# read in the flow direction file flow_dir_fn = "../../data/cumberland/flow-directions.tif" res_location_fn = "../../data/cumberland/cumberland-stations.csv" save_dir = "../../data/cumberland/regulation_data" fdr = rxr.open_rasterio(flow_dir_fn, band_as_variable=True, masked=True) reservoirs = gpd.read_file(res_location_fn) reservoirs['geometry'] = gpd.points_from_xy(reservoirs['lon'], reservoirs['lat']) reservoirs.set_crs('epsg:4326', inplace=True) gv.tile_sources.OSM() \ * fdr.hvplot(x='x', y='y', geo=True, cmap='colorwheel') \ * reservoirs.hvplot(geo=True, hover_cols=['lat', 'lon', 'name']).opts(marker='triangle', fill_color='white', line_color='black', size=15, line_width=3)
Out[6]:

Here, the triangles denote the location of the reservoirs and the colored raster denotes the flow direction of each cell in the flow direction file. The values correspond to the direction of flow of water as follows - 1: N, 2: NE, 3: E, 4: SE, 5: S, 6: SW, 7: W and 8: NW.

We will be using the generate_network function in the resorr.data_prep module to generate the reservoir network. The function returns the reservoir network as a geonetworkx.GeoDiGraph object, but can also save the network as shp files if the save_dir arguemnt is passed.

In [7]:
Copied!
from resorr.data_prep import generate_network

G = generate_network(
    flow_dir_fn, res_location_fn, save_dir
)
G
from resorr.data_prep import generate_network G = generate_network( flow_dir_fn, res_location_fn, save_dir ) G
Out[7]:
<geonetworkx.geodigraph.GeoDiGraph at 0x15e4cefd0>
In [8]:
Copied!
nx.draw(G)
nx.draw(G)
No description has been provided for this image
Previous Next

Built with MkDocs using a theme provided by Read the Docs.