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
def set_raster_region(self): """Set the computational region (window) for all raster maps in the current process. Attention: All raster objects must be closed or the process will be terminated. The Raster library C function Rast_set_window() is called. """ libraster.Rast_set_window(self.byref())
def _set_raster_window(self, region): libraster.Rast_set_window(region.byref()) # update rows and cols attributes self._rows = libraster.Rast_window_rows() self._cols = libraster.Rast_window_cols()