Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
Merge branch 'main' into plainsmap_optional
Browse files Browse the repository at this point in the history
  • Loading branch information
metzm authored Dec 11, 2024
2 parents 4686c08 + cdefc4e commit 04ad93f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
27 changes: 26 additions & 1 deletion r.slopeunits.create/r.slopeunits.create.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,33 @@
# % answer: 20
# %end

# %option
# % key: convergence
# % type: integer
# % label: Convergence factor for MFD in r.watershed (1-10)
# % description: 1 = most diverging flow, 10 = most converging flow. Recommended: 5
# % answer: 5
# %end

# %flag
# % key: g
# % description: Generalize Slope Units vector layer
# % guisection: flags
# %end

# %flag
# % key: s
# % label: SFD (D8) flow in r.watershed (default is MFD)
# % description: SFD: single flow direction, MFD: multiple flow direction
# % guisection: flags
# %end

# %rules
# % requires: -g,slumapvect
# %end

# pylint: disable=C0302 (too-many-lines)

import atexit
import os

Expand Down Expand Up @@ -157,6 +174,7 @@ def slope_units(
cvarmin=-1.0,
red=-1,
maxiter=0,
convergence=5,
):
"""core slope unit calculation"""

Expand Down Expand Up @@ -250,12 +268,17 @@ def slope_units(
grass.run_command(
"g.remove", type="raster", name="slu_r_tmp", flags="f", quiet=True
)
if flags["s"]:
rwflags = "abs"
else:
rwflags = "ab"
grass.run_command(
"r.watershed",
elevation=dem,
hbasin="slu_r_tmp",
thresh=thc,
flags="ab",
convergence=convergence,
flags=rwflags,
quiet=True,
)
rm_rasters.append("slu_r_tmp")
Expand Down Expand Up @@ -757,6 +780,7 @@ def main():
cvarmin = float(options["cvmin"])
red = int(options["rf"])
maxiter = int(options["maxiteration"])
convergence = int(options["convergence"])

slope_units(
dem,
Expand All @@ -769,6 +793,7 @@ def main():
cvarmin,
red,
maxiter,
convergence,
)
if options["slumapvect"]:
export_as_vect(slumap, options["slumapvect"])
Expand Down
28 changes: 28 additions & 0 deletions r.slopeunits.optimize/r.slopeunits.optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@
# % answer: outdir
# %end

# %option
# % key: convergence
# % type: integer
# % label: Convergence factor for MFD in r.watershed (1-10)
# % description: 1 = most diverging flow, 10 = most converging flow. Recommended: 5
# % answer: 5
# %end

# %flag
# % key: s
# % label: SFD (D8) flow in r.watershed (default is MFD)
# % description: SFD: single flow direction, MFD: multiple flow direction
# %end

# pylint: disable=C0302 (too-many-lines)

import atexit
Expand Down Expand Up @@ -173,6 +187,7 @@ def run_batch(
thresh,
cleansize,
plainsmap,
convergence,
):
"""Calls r.slopeunits.create, r.slopeunits.clean and r.slopeunits.metrics"""
global COUNT_GLOBAL
Expand Down Expand Up @@ -201,6 +216,10 @@ def run_batch(
kwargs = {}
if plainsmap:
kwargs["plainsmap"] = plainsmap
if flags["s"]:
rwflags = "s"
else:
rwflags = ""
grass.run_command(
"r.slopeunits.create",
demmap=dem,
Expand All @@ -210,6 +229,8 @@ def run_batch(
cvmin=cvmin,
rf=redf,
maxiteration=maxiteration,
convergence=convergence,
flags=rwflags,
overwrite=True,
**kwargs,
)
Expand Down Expand Up @@ -278,6 +299,7 @@ def calcola_loop(
thresh,
cleansize,
plainsmap,
convergence,
ico,
calcd_file,
current_file,
Expand Down Expand Up @@ -313,6 +335,7 @@ def calcola_loop(
thresh,
cleansize,
plainsmap,
convergence,
)
out1 = f"{float(metrics['v_fin']):16.14f}"
out2 = f"{float(metrics['i_fin']):16.9f}".strip()
Expand Down Expand Up @@ -361,6 +384,7 @@ def calcola_current(
thresh,
cleansize,
plainsmap,
convergence,
calcd_file,
current_file,
):
Expand All @@ -387,6 +411,7 @@ def calcola_current(
thresh,
cleansize,
plainsmap,
convergence,
ico,
calcd_file,
current_file,
Expand Down Expand Up @@ -423,6 +448,7 @@ def calcola_current(
thresh,
cleansize,
plainsmap,
convergence,
ico,
calcd_file,
current_file,
Expand Down Expand Up @@ -615,6 +641,7 @@ def main():
]
epsilonx = float(options["epsilonx"])
epsilony = float(options["epsilony"])
convergence = int(options["convergence"])
outdir = os.path.abspath(options["outdir"])

calcd_file = os.path.join(outdir, "calcd.dat")
Expand Down Expand Up @@ -668,6 +695,7 @@ def main():
thresh,
cleansize,
plainsmap,
convergence,
calcd_file,
current_file,
)
Expand Down

0 comments on commit 04ad93f

Please sign in to comment.