Streamkit Documentation
  • Home
  • API Reference

Examples

  • Downloading Data
  • Extracting Stream Networks
  • Stream Network Analysis
Streamkit Documentation
  • Examples
  • Stream Network Analysis
  • Edit on avkoehl/streamkit

In [1]:
Copied!
import geopandas as gpd
import rioxarray as rxr
import matplotlib.pyplot as plt

from streamkit.datasets import load_sample_data
from streamkit.terrain import flow_accumulation_workflow
from streamkit.extraction import delineate_reaches, heads_from_features, extract_channel_network
from streamkit.network import sample_cross_sections, network_cross_sections
from streamkit.network import analyze_stream_network
import geopandas as gpd import rioxarray as rxr import matplotlib.pyplot as plt from streamkit.datasets import load_sample_data from streamkit.terrain import flow_accumulation_workflow from streamkit.extraction import delineate_reaches, heads_from_features, extract_channel_network from streamkit.network import sample_cross_sections, network_cross_sections from streamkit.network import analyze_stream_network
In [2]:
Copied!
dem, flowlines = load_sample_data()
conditioned_dem, flow_dir, flow_acc = flow_accumulation_workflow(dem)
channel_heads = heads_from_features(flowlines, dem)
channel_network = extract_channel_network(channel_heads, flow_dir)
reaches = delineate_reaches(channel_network, dem, flow_dir, flow_acc, penalty=5, min_length=500, smooth_window=5, threshold_degrees=1)
dem, flowlines = load_sample_data() conditioned_dem, flow_dir, flow_acc = flow_accumulation_workflow(dem) channel_heads = heads_from_features(flowlines, dem) channel_network = extract_channel_network(channel_heads, flow_dir) reaches = delineate_reaches(channel_network, dem, flow_dir, flow_acc, penalty=5, min_length=500, smooth_window=5, threshold_degrees=1)
Loading sample data from cache at /Users/arthurkoehl/Library/Caches/streamkit...

Topology¶

In [3]:
Copied!
analysis = analyze_stream_network(reaches, dem, flow_dir, flow_acc)
analysis = analyze_stream_network(reaches, dem, flow_dir, flow_acc)
In [11]:
Copied!
fig, axes = plt.subplots(3, 2, figsize=(6, 12))
xmin, ymin, xmax, ymax = analysis.total_bounds

for ax, col in zip(
    axes.flat,
    [
        "stream_id",
        "strahler",
        "mainstem",
        "mean_slope",
        "contributing_area",
        "max_upstream_length",
    ],
):
    analysis.plot(column=col, ax=ax, aspect="auto")
    ax.set_xlim(xmin, xmax)
    ax.set_ylim(ymin, ymax)
    ax.set_title(col.replace("_", " ").title())

plt.tight_layout()
fig, axes = plt.subplots(3, 2, figsize=(6, 12)) xmin, ymin, xmax, ymax = analysis.total_bounds for ax, col in zip( axes.flat, [ "stream_id", "strahler", "mainstem", "mean_slope", "contributing_area", "max_upstream_length", ], ): analysis.plot(column=col, ax=ax, aspect="auto") ax.set_xlim(xmin, xmax) ax.set_ylim(ymin, ymax) ax.set_title(col.replace("_", " ").title()) plt.tight_layout()
No description has been provided for this image

Cross Sections¶

In [18]:
Copied!
xsections = network_cross_sections(streams_vec.geometry, 100, 1000, smoothed=True)
fig, ax = plt.subplots(figsize=(10,10))
dem.plot(ax=ax)
xsections.plot(ax=ax, color='red')
xsections = network_cross_sections(streams_vec.geometry, 100, 1000, smoothed=True) fig, ax = plt.subplots(figsize=(10,10)) dem.plot(ax=ax) xsections.plot(ax=ax, color='red')
Out[18]:
<Axes: title={'center': 'band = 1, spatial_ref = 0'}, xlabel='x', ylabel='y'>
No description has been provided for this image
In [19]:
Copied!
elevation_profiles = sample_cross_sections(xsections, 10)
elevation_profiles
elevation_profiles = sample_cross_sections(xsections, 10) elevation_profiles
Out[19]:
side geometry distance xs_id linestring_id
0 center POINT (-220062.321 52866.706) 0.0 1 0
1 positive POINT (-220052.874 52863.428) 10.0 1 0
2 positive POINT (-220043.426 52860.15) 20.0 1 0
3 positive POINT (-220033.979 52856.872) 30.0 1 0
4 positive POINT (-220024.531 52853.594) 40.0 1 0
... ... ... ... ... ...
171352 negative POINT (-215882.218 28741.635) -460.0 1713 126
171353 negative POINT (-215876.568 28733.384) -470.0 1713 126
171354 negative POINT (-215870.917 28725.134) -480.0 1713 126
171355 negative POINT (-215865.266 28716.883) -490.0 1713 126
171356 negative POINT (-215859.616 28708.633) -500.0 1713 126

171357 rows × 5 columns

Previous

Built with MkDocs using a theme provided by Read the Docs.
avkoehl/streamkit « Previous