Skip to content

Commit f714bf8

Browse files
authored
r.blend: Add nprocs parameter and use it for r.mapcalc (#6564)
The main step in r.blend is running r.mapcalc which is now multithreaded. The default number of threads is now whatever is available on the machine, so to limit that, r.blend needs nprocs which is passed to r.mapcalc (before that change, r.blend was not taking the advantage of multithreading in r.mapcalc).
1 parent f4bafa4 commit f714bf8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

scripts/r.blend/r.blend.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
# % key: c
4343
# % description: Combine resulting R,G,B layers into single output map
4444
# %end
45+
# %option G_OPT_M_NPROCS
46+
# %end
4547

4648
import os
4749
import string
@@ -53,6 +55,7 @@ def main():
5355
second = options["second"]
5456
output = options["output"]
5557
percent = options["percent"]
58+
nprocs = options["nprocs"]
5659

5760
mapset = gs.gisenv()["MAPSET"]
5861

@@ -80,7 +83,15 @@ def main():
8083
cmd = [template.substitute(ch=ch) for ch in ["r", "g", "b"]]
8184
cmd = ";".join(cmd)
8285

83-
gs.mapcalc(cmd, output=output, first=first, second=second, frac1=frac1, frac2=frac2)
86+
gs.mapcalc(
87+
cmd,
88+
output=output,
89+
first=first,
90+
second=second,
91+
frac1=frac1,
92+
frac2=frac2,
93+
nprocs=nprocs,
94+
)
8495

8596
for ch in ["r", "g", "b"]:
8697
map = "%s.%s" % (output, ch)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Test of r.blend"""
2+
3+
import pytest
4+
5+
from grass.tools import Tools
6+
7+
8+
@pytest.mark.parametrize("nprocs", [None, 0, 1, 2])
9+
def test_nprocs_accepted(xy_raster_dataset_session_mapset, nprocs):
10+
"""Check that the nprocs parameter is accepted"""
11+
tools = Tools(session=xy_raster_dataset_session_mapset)
12+
tools.r_mapcalc(expression="test_1 = 1")
13+
tools.r_mapcalc(expression="test_2 = 2")
14+
tools.r_blend(first="test_1", second="test_2", output="output", nprocs=nprocs)

0 commit comments

Comments
 (0)