Example #1
0
def run_benchmark(resolution_list, runs, testdict, profile):
    regions = []
    for resolution in resolution_list:
        core.use_temp_region()
        core.run_command("g.region",
                         e=50,
                         w=-50,
                         n=50,
                         s=-50,
                         res=resolution,
                         flags="p")

        # Adjust the computational region for this process
        region = libgis.Cell_head()
        libraster.Rast_get_window(ctypes.byref(region))
        region.e = 50
        region.w = -50
        region.n = 50
        region.s = -50
        region.ew_res = resolution
        region.ns_res = resolution

        libgis.G_adjust_Cell_head(ctypes.byref(region), 0, 0)

        libraster.Rast_set_window(ctypes.byref(region))
        libgis.G_set_window(ctypes.byref(region))

        # Create two raster maps with random numbers
        core.mapcalc("test_a = rand(0, 100)", quite=True, overwrite=True)
        core.mapcalc("test_b = rand(0.0, 1.0)", quite=True, overwrite=True)
        result = collections.OrderedDict()
        result["res"] = resolution
        result["cols"] = region.cols
        result["rows"] = region.rows
        result["cells"] = region.rows * region.cols
        result["results"] = copy.deepcopy(testdict)
        for execmode, operation in result["results"].items():
            print(execmode)
            for oper, operdict in operation.items():
                operdict["time"], operdict["times"] = mytimer(
                    operdict["func"], runs)
                if profile:
                    filename = "{0}_{1}_{2}".format(execmode, oper, profile)
                    cProfile.runctx(
                        operdict["func"].__name__ + "()",
                        globals(),
                        locals(),
                        filename=filename,
                    )
                print(("    {0}: {1: 40.6f}s".format(oper, operdict["time"])))
                del operdict["func"]

        regions.append(result)
        core.del_temp_region()

    return regions
Example #2
0
 def adjust(self, rows=False, cols=False):
     """Adjust rows and cols number according with the nsres and ewres
     resolutions. If rows or cols parameters are True, the adjust method
     update nsres and ewres according with the rows and cols numbers.
     """
     libgis.G_adjust_Cell_head(self.c_region, bool(rows), bool(cols))