コード例 #1
0
ファイル: benchmark.py プロジェクト: mlennert/grass
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
コード例 #2
0
ファイル: abstract.py プロジェクト: landam/grass-stable-ppa
    def get_value(self, point, region=None):
        """This method returns the pixel value of a given pair of coordinates:

        :param point: pair of coordinates in tuple object or class object with coords() method
        :param region: The region that should be used for sampling,
                       default is the current computational region that can be set with set_region()
                       or set_region_from_rast()
        """
        # Check for tuple
        if type(point) != type([]) and type(point) != type(()):
            point = point.coords()
        # If no region was set, use the current computational region
        if not region:
            region = Region()
            libraster.Rast_get_window(region.byref())
        row, col = utils.coor2pixel(point, region)
        if col < 0 or col > region.cols or row < 0 or row > region.rows:
            return None
        line = self.get_row(int(row))
        return line[int(col)]