Skip to content

Augustyy7/rivers_toolbox

Repository files navigation

Toolbox of river graph anaylsis

基于图网络算法的河网上下游判断工具

River graph statistics analysis, get the hierarchy of the river.

  • Main Command
python run_river_analysis.py --csv china_river_v10.csv

python run_river_sort.py
  • run_river_analysis.py

    • Command-line tool for river network degree analysis.
    • Loads river parent-child pairs from a CSV, builds a directed graph, computes in-degree and out-degree statistics, and optionally plots histograms.
    • Supports caching the graph as a pickle file.
    • Usage:
      python run_river_analysis.py china_river_v10.csv
    • Main functions:
      • parse_args(): Parses command-line arguments.
      • load_edges(): Loads and filters river edge data from CSV.
      • build_graph(): Constructs a directed graph from the data.
      • degree_stats(): Computes degree statistics.
      • print_summary(): Prints summary statistics.
      • plot_hist(): Plots and saves degree histograms.
  • run_river_sort.py

    • Script to compute the river hierarchy (distance from each river to the nearest sink).
    • Reads river data from CSV, builds a directed graph, finds sink nodes, and runs a BFS on the reversed graph to compute hierarchy levels.
    • Saves the hierarchy as a CSV file (china_river_hierarchy.csv).
    • Main steps:
      • Reads HYRIV_ID and NEXT_DOWN columns.
      • Builds a directed graph including sinks.
      • Identifies sink nodes (NEXT_DOWN == 0).
      • Runs BFS (Breadth First Search, 宽度优先搜索) from all sinks in the reversed graph.
      • Adjusts hierarchy so sinks have distance 1.
      • Saves the result as a CSV.
  • run_river_debug.ipynb

    • Jupyter notebook for interactive river path and hierarchy analysis.
    • Demonstrates how to:
      • Build the river graph and re-index river IDs.
      • Compute Euler tour timings for ancestor/descendant queries.
      • Check if two rivers are on the same route.
      • Find the downstream path from any river to the sink.
      • Justify ancestor/descendant relationships between rivers.
      • Query river depth and hierarchy interactively.

Jupyter notebook example for path finding in run_river_debug.ipynb.

Data Requirements

Inputs: china_river_v10.csv

Outputs (see more in Jupyter example): china_river_hierarchy.csv.

About

River toolbox development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors