In [1]:
Copied!
import geopandas as gpd
import rioxarray as rxr
import matplotlib.pyplot as plt
from streamkit import (
    vectorize_streams,
    flow_accumulation_workflow,
    vector_streams_to_networkx,
    strahler_order,
    upstream_length,
    networkx_to_gdf,
    label_mainstem)
import geopandas as gpd
import rioxarray as rxr
import matplotlib.pyplot as plt
from streamkit import (
    vectorize_streams,
    flow_accumulation_workflow,
    vector_streams_to_networkx,
    strahler_order,
    upstream_length,
    networkx_to_gdf,
    label_mainstem)
OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.
In [2]:
Copied!
streams = rxr.open_rasterio("data/sample_streams.tif", masked=True).squeeze()
dem = rxr.open_rasterio("data/sample_dem.tif", masked=True).squeeze()
conditioned_dem, flow_directions, flow_accumulation = flow_accumulation_workflow(dem)
streams = rxr.open_rasterio("data/sample_streams.tif", masked=True).squeeze()
dem = rxr.open_rasterio("data/sample_dem.tif", masked=True).squeeze()
conditioned_dem, flow_directions, flow_accumulation = flow_accumulation_workflow(dem)
In [3]:
Copied!
streams_vec = vectorize_streams(streams, flow_directions, flow_accumulation)
streams_vec = vectorize_streams(streams, flow_directions, flow_accumulation)
In [4]:
Copied!
streams_vec.plot(column='stream_id')
streams_vec.plot(column='stream_id')
Out[4]:
<Axes: >
In [5]:
Copied!
graph = vector_streams_to_networkx(streams_vec)
graph = vector_streams_to_networkx(streams_vec)
In [6]:
Copied!
graph = strahler_order(graph)
graph = upstream_length(graph)
graph = label_mainstem(graph)
graph = strahler_order(graph)
graph = upstream_length(graph)
graph = label_mainstem(graph)
In [7]:
Copied!
streams_vec = networkx_to_gdf(graph)
streams_vec = networkx_to_gdf(graph)
In [8]:
Copied!
fig, axes = plt.subplots(2, 2, figsize=(12, 12))
streams_vec.plot(ax=axes[0, 0], column='strahler')
axes[0, 0].set_title('Strahler Order')
streams_vec.plot(ax=axes[0, 1], column='max_upstream_length')
axes[0, 1].set_title('Max Upstream Length')
streams_vec.plot(ax=axes[1, 0], column='mainstem')
axes[1, 0].set_title('Mainstem')
axes[1, 1].axis('off')
fig, axes = plt.subplots(2, 2, figsize=(12, 12))
streams_vec.plot(ax=axes[0, 0], column='strahler')
axes[0, 0].set_title('Strahler Order')
streams_vec.plot(ax=axes[0, 1], column='max_upstream_length')
axes[0, 1].set_title('Max Upstream Length')
streams_vec.plot(ax=axes[1, 0], column='mainstem')
axes[1, 0].set_title('Mainstem')
axes[1, 1].axis('off')
Out[8]:
(np.float64(0.0), np.float64(1.0), np.float64(0.0), np.float64(1.0))