Skip to content

Commit

Permalink
r.drain: fix for fully-qualified map names (#3092)
Browse files Browse the repository at this point in the history
 make tmp names safe for parallelization on cluster
  • Loading branch information
petrasovaa committed Jul 25, 2023
1 parent 21c02f4 commit 74f7859
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions scripts/r.drain/r.drain.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,16 @@
# % required: start_coordinates, start_points
# %end

import os
import sys
import atexit

import grass.script as grass
import grass.script as gs


def cleanup():
"""Delete temporary direction map."""
if tmp_maps:
grass.run_command(
gs.run_command(
"g.remove",
flags="f",
quiet=True,
Expand All @@ -141,12 +140,13 @@ def main():
atexit.register(cleanup)

if not dirmap:
valmap_name = valmap.split("@", maxsplit=1)[0]
# get directions with r.fill.dir, without sink filling
dirmap = "%s_tmp_%d" % (valmap, os.getpid())
fill_map = "%s_fill_%d" % (valmap, os.getpid())
area_map = "%s_area_%d" % (valmap, os.getpid())
dirmap = gs.append_node_pid(f"{valmap_name}_dir")
fill_map = gs.append_node_pid(f"{valmap_name}_fill")
area_map = gs.append_node_pid(f"{valmap_name}_area")
tmp_maps = dirmap + "," + fill_map + "," + area_map
grass.run_command(
gs.run_command(
"r.fill.dir",
input=valmap,
output=fill_map,
Expand Down Expand Up @@ -179,11 +179,11 @@ def main():
if flags["n"]:
pathflags += "n"

grass.run_command("r.path", flags=pathflags, **kwargs)
gs.run_command("r.path", flags=pathflags, **kwargs)

return 0


if __name__ == "__main__":
options, flags = grass.parser()
options, flags = gs.parser()
sys.exit(main())

0 comments on commit 74f7859

Please sign in to comment.