MRRpy 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mrrpy-0.2.0/LICENSE +21 -0
- mrrpy-0.2.0/MANIFEST.in +16 -0
- mrrpy-0.2.0/MRRpy/__init__.py +65 -0
- mrrpy-0.2.0/MRRpy/cli/__init__.py +6 -0
- mrrpy-0.2.0/MRRpy/cli/main.py +135 -0
- mrrpy-0.2.0/MRRpy/config.py +763 -0
- mrrpy-0.2.0/MRRpy/core/__init__.py +19 -0
- mrrpy-0.2.0/MRRpy/core/dem_processing.py +924 -0
- mrrpy-0.2.0/MRRpy/core/io_utils.py +116 -0
- mrrpy-0.2.0/MRRpy/core/opm.py +339 -0
- mrrpy-0.2.0/MRRpy/core/precip/__init__.py +15 -0
- mrrpy-0.2.0/MRRpy/core/precip/engine.py +343 -0
- mrrpy-0.2.0/MRRpy/core/precip/gpu.py +99 -0
- mrrpy-0.2.0/MRRpy/core/routing/__init__.py +59 -0
- mrrpy-0.2.0/MRRpy/core/routing/boundary.py +189 -0
- mrrpy-0.2.0/MRRpy/core/routing/fields.py +175 -0
- mrrpy-0.2.0/MRRpy/core/routing/gauges.py +117 -0
- mrrpy-0.2.0/MRRpy/core/routing/gpu.py +190 -0
- mrrpy-0.2.0/MRRpy/core/routing/hydraulics.py +372 -0
- mrrpy-0.2.0/MRRpy/core/routing/reporting.py +107 -0
- mrrpy-0.2.0/MRRpy/core/routing/router.py +874 -0
- mrrpy-0.2.0/MRRpy/core/routing/schemes.py +85 -0
- mrrpy-0.2.0/MRRpy/core/routing/surface.py +478 -0
- mrrpy-0.2.0/MRRpy/core/routing/terrain.py +292 -0
- mrrpy-0.2.0/MRRpy/core/runoff/__init__.py +43 -0
- mrrpy-0.2.0/MRRpy/core/runoff/engine.py +406 -0
- mrrpy-0.2.0/MRRpy/core/runoff/gpu.py +20 -0
- mrrpy-0.2.0/MRRpy/core/runoff/mechanisms.py +544 -0
- mrrpy-0.2.0/MRRpy/core/runoff/physical.py +116 -0
- mrrpy-0.2.0/MRRpy/core/runoff/soil.py +370 -0
- mrrpy-0.2.0/MRRpy/data/lcz_lookup.csv +18 -0
- mrrpy-0.2.0/MRRpy/data/lulc_lookup.csv +12 -0
- mrrpy-0.2.0/MRRpy/gee/__init__.py +12 -0
- mrrpy-0.2.0/MRRpy/gee/auth.py +77 -0
- mrrpy-0.2.0/MRRpy/gee/cn_gee.py +97 -0
- mrrpy-0.2.0/MRRpy/gee/dem_catalog.py +175 -0
- mrrpy-0.2.0/MRRpy/gee/dem_gee.py +193 -0
- mrrpy-0.2.0/MRRpy/gee/imerg_gee.py +368 -0
- mrrpy-0.2.0/MRRpy/gee/serves_gee.py +744 -0
- mrrpy-0.2.0/MRRpy/pipeline.py +208 -0
- mrrpy-0.2.0/MRRpy/plotting.py +239 -0
- mrrpy-0.2.0/MRRpy/utils/__init__.py +6 -0
- mrrpy-0.2.0/MRRpy/utils/gpu_utils.py +104 -0
- mrrpy-0.2.0/MRRpy/utils/notebook_map.py +118 -0
- mrrpy-0.2.0/MRRpy/utils/terrain_rules.py +152 -0
- mrrpy-0.2.0/MRRpy.egg-info/PKG-INFO +114 -0
- mrrpy-0.2.0/MRRpy.egg-info/SOURCES.txt +55 -0
- mrrpy-0.2.0/MRRpy.egg-info/dependency_links.txt +1 -0
- mrrpy-0.2.0/MRRpy.egg-info/entry_points.txt +2 -0
- mrrpy-0.2.0/MRRpy.egg-info/requires.txt +23 -0
- mrrpy-0.2.0/MRRpy.egg-info/top_level.txt +1 -0
- mrrpy-0.2.0/PKG-INFO +114 -0
- mrrpy-0.2.0/README.md +68 -0
- mrrpy-0.2.0/configs/example_config.yaml +105 -0
- mrrpy-0.2.0/pyproject.toml +77 -0
- mrrpy-0.2.0/requirements.txt +29 -0
- mrrpy-0.2.0/setup.cfg +4 -0
mrrpy-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Saurav Bhattarai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
mrrpy-0.2.0/MANIFEST.in
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include requirements.txt
|
|
4
|
+
recursive-include MRRpy/data *.csv
|
|
5
|
+
recursive-include configs *.yaml *.yml *.json
|
|
6
|
+
|
|
7
|
+
# Keep build noise out of the sdist.
|
|
8
|
+
global-exclude *.pyc
|
|
9
|
+
global-exclude __pycache__/*
|
|
10
|
+
prune tests
|
|
11
|
+
prune docs
|
|
12
|
+
prune study
|
|
13
|
+
prune qgis_plugin
|
|
14
|
+
prune _plugin_build
|
|
15
|
+
prune tools
|
|
16
|
+
prune runs
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
MRRpy (Multi-Mechanism Runoff and Routing) — a distributed, physics-based
|
|
4
|
+
hydrological + hydrodynamic model.
|
|
5
|
+
|
|
6
|
+
Implements Variable Source Area (VSA) saturation-excess runoff, Green-Ampt
|
|
7
|
+
infiltration-excess and impervious urban shedding (the Pradhan & Ogden 2010
|
|
8
|
+
"One-Parameter Model"), feeding explicit grid-based kinematic / diffusive-wave /
|
|
9
|
+
Muskingum–Cunge channel routing. Optional Google Earth Engine forcing (IMERG
|
|
10
|
+
rainfall, SERVES deficit, SoilGrids, LULC/LCZ).
|
|
11
|
+
|
|
12
|
+
Subpackages
|
|
13
|
+
-----------
|
|
14
|
+
core : the science — DEM preprocessing, precipitation, runoff generation
|
|
15
|
+
(VSA / Green-Ampt / impervious), kinematic/diffusive-wave routing.
|
|
16
|
+
Pure NumPy/SciPy/rasterio; no QGIS, no Qt.
|
|
17
|
+
gee : Google Earth Engine integrations (IMERG rainfall, SERVES deficit,
|
|
18
|
+
SoilGrids, LULC/LCZ). Optional; requires earthengine-api.
|
|
19
|
+
utils : shared helpers (CPU/GPU backend selection).
|
|
20
|
+
cli : the ``MRRpy`` command-line interface (config-file driven runs).
|
|
21
|
+
|
|
22
|
+
Quick start
|
|
23
|
+
-----------
|
|
24
|
+
from MRRpy import Config, run_pipeline
|
|
25
|
+
|
|
26
|
+
cfg = Config(DEM_PATH="dem.tif", OUTPUT_DIR="results/")
|
|
27
|
+
cfg.update_output_paths()
|
|
28
|
+
results = run_pipeline(cfg, stages=("process_dem", "routing"))
|
|
29
|
+
|
|
30
|
+
``Config`` is the canonical configuration object; ``OpmConfig`` is an alias.
|
|
31
|
+
|
|
32
|
+
No local DEM yet? ``print(MRRpy.describe_available_dems())`` lists the
|
|
33
|
+
DEM datasets MRRpy can auto-download from Google Earth Engine (no
|
|
34
|
+
``[gee]`` install needed just to browse); set ``Config(DEM_BOUNDS_WGS84=...,
|
|
35
|
+
DEM_SOURCE=...)`` with an empty ``DEM_PATH`` to have the ``process_dem``
|
|
36
|
+
stage fetch one automatically (requires ``pip install MRRpy[gee]`` +
|
|
37
|
+
authentication).
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
__version__ = "0.1.2"
|
|
41
|
+
|
|
42
|
+
from .config import Config, OpmConfig
|
|
43
|
+
from .pipeline import run_pipeline, DEFAULT_STAGES
|
|
44
|
+
from .gee.dem_catalog import (
|
|
45
|
+
list_dems as list_available_dems,
|
|
46
|
+
describe_dems as describe_available_dems,
|
|
47
|
+
)
|
|
48
|
+
from .plotting import plot_hydrograph, plot_watershed, plot_raster, plot_mass_balance
|
|
49
|
+
from .utils.terrain_rules import mannings_n_from_dem, apply_elevation_rule
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
"Config",
|
|
53
|
+
"OpmConfig",
|
|
54
|
+
"run_pipeline",
|
|
55
|
+
"DEFAULT_STAGES",
|
|
56
|
+
"list_available_dems",
|
|
57
|
+
"describe_available_dems",
|
|
58
|
+
"plot_hydrograph",
|
|
59
|
+
"plot_watershed",
|
|
60
|
+
"plot_raster",
|
|
61
|
+
"plot_mass_balance",
|
|
62
|
+
"mannings_n_from_dem",
|
|
63
|
+
"apply_elevation_rule",
|
|
64
|
+
"__version__",
|
|
65
|
+
]
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
main.py
|
|
4
|
+
=======
|
|
5
|
+
The ``MRRpy`` command-line interface.
|
|
6
|
+
|
|
7
|
+
Commands
|
|
8
|
+
--------
|
|
9
|
+
MRRpy run -c config.yaml [--stages process_dem routing]
|
|
10
|
+
Run the pipeline with the given config file (YAML, JSON or a legacy
|
|
11
|
+
flat python settings module).
|
|
12
|
+
|
|
13
|
+
MRRpy init-config [-o config.yaml]
|
|
14
|
+
Write a template config file with every parameter at its default,
|
|
15
|
+
ready to edit.
|
|
16
|
+
|
|
17
|
+
MRRpy validate -c config.yaml
|
|
18
|
+
Load the config file and run the pre-flight sanity checks without
|
|
19
|
+
starting a simulation.
|
|
20
|
+
|
|
21
|
+
MRRpy list-options
|
|
22
|
+
Print every fixed-choice option with its integer codes (each option
|
|
23
|
+
accepts the string or the code, e.g. PRECIP_METHOD: uniform ≡ 0).
|
|
24
|
+
|
|
25
|
+
MRRpy list-dems
|
|
26
|
+
Print every DEM dataset MRRpy can auto-download from Google Earth
|
|
27
|
+
Engine (dataset id, resolution, coverage) — set DEM_SOURCE to one of
|
|
28
|
+
these keys.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
import argparse
|
|
32
|
+
import sys
|
|
33
|
+
|
|
34
|
+
from ..config import Config
|
|
35
|
+
from ..pipeline import run_pipeline, DEFAULT_STAGES, _STAGE_PROGRESS
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _cmd_run(args):
|
|
39
|
+
cfg = Config.from_file(args.config)
|
|
40
|
+
if args.output_dir:
|
|
41
|
+
cfg.OUTPUT_DIR = args.output_dir
|
|
42
|
+
cfg.update_output_paths()
|
|
43
|
+
if args.backend:
|
|
44
|
+
cfg.BACKEND = args.backend
|
|
45
|
+
cfg.validate()
|
|
46
|
+
run_pipeline(cfg, stages=args.stages)
|
|
47
|
+
return 0
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _cmd_init_config(args):
|
|
51
|
+
cfg = Config()
|
|
52
|
+
path = cfg.save(args.output)
|
|
53
|
+
print(f"Template config written to: {path}")
|
|
54
|
+
print("Edit at least DEM_PATH, OUTPUT_POINT, TARGET_CRS_EPSG and OUTPUT_DIR, then:")
|
|
55
|
+
print(f" MRRpy run -c {path}")
|
|
56
|
+
print("Tip: fixed-choice options accept a string or an integer code "
|
|
57
|
+
"(see 'MRRpy list-options').")
|
|
58
|
+
return 0
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _cmd_validate(args):
|
|
62
|
+
cfg = Config.from_file(args.config)
|
|
63
|
+
try:
|
|
64
|
+
cfg.validate()
|
|
65
|
+
except ValueError as exc:
|
|
66
|
+
print(exc)
|
|
67
|
+
return 1
|
|
68
|
+
print("Config OK.")
|
|
69
|
+
return 0
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _cmd_list_options(args):
|
|
73
|
+
print(Config.describe_options())
|
|
74
|
+
return 0
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _cmd_list_dems(args):
|
|
78
|
+
from ..gee.dem_catalog import describe_dems
|
|
79
|
+
print(describe_dems())
|
|
80
|
+
return 0
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def build_parser():
|
|
84
|
+
parser = argparse.ArgumentParser(
|
|
85
|
+
prog="MRRpy",
|
|
86
|
+
description="MRRpy — distributed hydrological + hydrodynamic model "
|
|
87
|
+
"(VSA-OPM; Pradhan & Ogden 2010).",
|
|
88
|
+
)
|
|
89
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
90
|
+
|
|
91
|
+
p_run = sub.add_parser("run", help="run the pipeline from a config file")
|
|
92
|
+
p_run.add_argument("-c", "--config", required=True,
|
|
93
|
+
help="config file (.yaml, .json or legacy .py)")
|
|
94
|
+
p_run.add_argument("--stages", nargs="+", default=list(DEFAULT_STAGES),
|
|
95
|
+
choices=sorted(_STAGE_PROGRESS),
|
|
96
|
+
help=f"pipeline stages to run (default: {' '.join(DEFAULT_STAGES)})")
|
|
97
|
+
p_run.add_argument("--output-dir", default=None,
|
|
98
|
+
help="override OUTPUT_DIR from the config file")
|
|
99
|
+
p_run.add_argument("--backend", default=None, choices=("cpu", "gpu"),
|
|
100
|
+
help="override the compute backend")
|
|
101
|
+
p_run.set_defaults(func=_cmd_run)
|
|
102
|
+
|
|
103
|
+
p_init = sub.add_parser("init-config", help="write a template config file")
|
|
104
|
+
p_init.add_argument("-o", "--output", default="config.yaml",
|
|
105
|
+
help="destination file (.yaml or .json; default: config.yaml)")
|
|
106
|
+
p_init.set_defaults(func=_cmd_init_config)
|
|
107
|
+
|
|
108
|
+
p_val = sub.add_parser("validate", help="check a config file without running")
|
|
109
|
+
p_val.add_argument("-c", "--config", required=True,
|
|
110
|
+
help="config file (.yaml, .json or legacy .py)")
|
|
111
|
+
p_val.set_defaults(func=_cmd_validate)
|
|
112
|
+
|
|
113
|
+
p_opts = sub.add_parser("list-options",
|
|
114
|
+
help="list fixed-choice options and their integer codes")
|
|
115
|
+
p_opts.set_defaults(func=_cmd_list_options)
|
|
116
|
+
|
|
117
|
+
p_dems = sub.add_parser("list-dems",
|
|
118
|
+
help="list DEM datasets available via Google Earth Engine")
|
|
119
|
+
p_dems.set_defaults(func=_cmd_list_dems)
|
|
120
|
+
|
|
121
|
+
return parser
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def main(argv=None):
|
|
125
|
+
parser = build_parser()
|
|
126
|
+
args = parser.parse_args(argv)
|
|
127
|
+
try:
|
|
128
|
+
return args.func(args)
|
|
129
|
+
except (FileNotFoundError, ValueError, AttributeError, ImportError) as exc:
|
|
130
|
+
print(f"[ERROR] {exc}", file=sys.stderr)
|
|
131
|
+
return 1
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
if __name__ == "__main__":
|
|
135
|
+
sys.exit(main())
|