Skip to content

Commit

Permalink
Allow r.random.surf to fail for benchmarking
Browse files Browse the repository at this point in the history
Fix flake8: bare exceptions
  • Loading branch information
aaronsms committed Aug 18, 2021
1 parent 67f761a commit e0f335a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions raster/r.univar/benchmark/benchmark_r_univar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@author Aaron Saw Min Sern
"""

from grass.exceptions import CalledModuleError
from grass.pygrass.modules import Module
from subprocess import DEVNULL

Expand All @@ -12,6 +13,7 @@
def main():
results = []

# Users can add more or modify existing reference maps
benchmark(7071, "r.univar_50M", results)
benchmark(10000, "r.univar_100M", results)
benchmark(14142, "r.univar_200M", results)
Expand All @@ -20,26 +22,32 @@ def main():
bm.nprocs_plot(results)


def benchmark(length, label, results):
fractal = "benchmark_fractal"
def benchmark(size, label, results):
reference = "r_univar_reference_map"
output = "benchmark_r_univar_nprocs"

generate_fractal(rows=length, cols=length, fname=fractal)
generate_map(rows=size, cols=size, fname=reference)
module = Module(
"r.univar",
map=[fractal] * 5,
map=reference,
run_=False,
stdout_=DEVNULL,
overwrite=True,
)
results.append(bm.benchmark_nprocs(module, label=label, max_nprocs=16, repeat=3))
Module("g.remove", quiet=True, flags="f", type="raster", name=fractal)
Module("g.remove", quiet=True, flags="f", type="raster", name=reference)
Module("g.remove", quiet=True, flags="f", type="raster", name=output)


def generate_fractal(rows, cols, fname):
def generate_map(rows, cols, fname):
Module("g.region", flags="p", s=0, n=rows, w=0, e=cols, res=1)
Module("r.surf.fractal", output=fname)
# Generate using r.random.surface if r.surf.fractal fails
try:
print("Generating reference map using r.surf.fractal...")
Module("r.surf.fractal", output=fname)
except CalledModuleError:
print("r.surf.fractal fails, using r.random.surface instead...")
Module("r.random.surface", output=fname)


if __name__ == "__main__":
Expand Down

0 comments on commit e0f335a

Please sign in to comment.