Пример #1
0
def main():
    layers = options['map'].split(',')

    if len(layers) < 2:
        grass.error(_("At least 2 maps are required"))

    tmpfile = grass.tempfile()

    for map in layers:
        if not grass.find_file(map, element='cell')['file']:
            grass.fatal(_("Raster map <%s> not found") % map)

    grass.write_command('d.text',
                        color='black',
                        size=4,
                        line=1,
                        stdin="CORRELATION")

    os.environ['GRASS_PNG_READ'] = 'TRUE'

    colors = "red black blue green gray violet".split()
    line = 2
    iloop = 0
    jloop = 0
    for iloop, i in enumerate(layers):
        for jloop, j in enumerate(layers):
            if i != j and iloop <= jloop:
                color = colors[0]
                colors = colors[1:]
                colors.append(color)
                grass.write_command('d.text',
                                    color=color,
                                    size=4,
                                    line=line,
                                    stdin="%s %s" % (i, j))
                line += 1

                ofile = file(tmpfile, 'w')
                grass.run_command('r.stats',
                                  flags='cnA',
                                  input=(i, j),
                                  stdout=ofile)
                ofile.close()

                ifile = file(tmpfile, 'r')
                first = True
                for l in ifile:
                    f = l.rstrip('\r\n').split(' ')
                    x = float(f[0])
                    y = float(f[1])
                    if first:
                        minx = maxx = x
                        miny = maxy = y
                        first = False
                    if minx > x: minx = x
                    if maxx < x: maxx = x
                    if miny > y: miny = y
                    if maxy < y: maxy = y
                ifile.close()

                kx = 100.0 / (maxx - minx + 1)
                ky = 100.0 / (maxy - miny + 1)

                p = grass.feed_command('d.graph', color=color)
                ofile = p.stdin

                ifile = file(tmpfile, 'r')
                for l in ifile:
                    f = l.rstrip('\r\n').split(' ')
                    x = float(f[0])
                    y = float(f[1])
                    ofile.write("icon + 0.1 %f %f\n" % ((x - minx + 1) * kx,
                                                        (y - miny + 1) * ky))
                ifile.close()

                ofile.close()
                p.wait()

    try_remove(tmpfile)
Пример #2
0
def main():
    layers = options["map"].split(",")

    if len(layers) < 2:
        gcore.error(_("At least 2 maps are required"))

    tmpfile = gcore.tempfile()

    for map in layers:
        if not gcore.find_file(map, element="cell")["file"]:
            gcore.fatal(_("Raster map <%s> not found") % map)

    try:
        gcore.write_command(
            "d.text", color="black", size=4, line=1, stdin="CORRELATION"
        )
    except CalledModuleError:
        return 1

    os.environ["GRASS_RENDER_FILE_READ"] = "TRUE"

    colors = "red black blue green gray violet".split()
    line = 2
    iloop = 0
    jloop = 0
    for iloop, i in enumerate(layers):
        for jloop, j in enumerate(layers):
            if i != j and iloop <= jloop:
                color = colors[0]
                colors = colors[1:]
                colors.append(color)
                gcore.write_command(
                    "d.text", color=color, size=4, line=line, stdin="%s %s" % (i, j)
                )
                line += 1

                ofile = open(tmpfile, "w")
                gcore.run_command("r.stats", flags="cnA", input=(i, j), stdout=ofile)
                ofile.close()

                ifile = open(tmpfile, "r")
                first = True
                for line in ifile:
                    f = line.rstrip("\r\n").split(" ")
                    x = float(f[0])
                    y = float(f[1])
                    if first:
                        minx = maxx = x
                        miny = maxy = y
                        first = False
                    if minx > x:
                        minx = x
                    if maxx < x:
                        maxx = x
                    if miny > y:
                        miny = y
                    if maxy < y:
                        maxy = y
                ifile.close()

                kx = 100.0 / (maxx - minx + 1)
                ky = 100.0 / (maxy - miny + 1)

                p = gcore.feed_command("d.graph", color=color)
                ofile = p.stdin

                ifile = open(tmpfile, "r")
                for line in ifile:
                    f = line.rstrip("\r\n").split(" ")
                    x = float(f[0])
                    y = float(f[1])
                    ofile.write(
                        b"icon + 0.1 %f %f\n"
                        % ((x - minx + 1) * kx, (y - miny + 1) * ky)
                    )
                ifile.close()

                ofile.close()
                p.wait()

    try_remove(tmpfile)

    return 0
Пример #3
0
def plot_dgraph():
    # use d.info and d.frame to create a square frame in the center of the window.
    s = grass.read_command('d.info', flags = 'd')
    f = s.split()
    frame_width = float(f[1])
    frame_height = float(f[2])

    # take shorter side as length of frame side
    min_side = min(frame_width, frame_height)
    dx = (frame_width  - min_side) / 2
    dy = (frame_height - min_side) / 2

    fl = dx
    fr = frame_width - dx
    ft = dy
    fb = frame_height - dy

    tenv = os.environ.copy()
    tenv['GRASS_FRAME'] = '%f,%f,%f,%f' % (ft, fb, fl, fr)

    # polyline calculations
    ring = 0.95
    scaleval = ring * totalvalidnumber / totalnumber

    sine_cosine_replic_normalized = [
	((scaleval * p[0]/maxradius + 1)*50,
	 (scaleval * p[1]/maxradius + 1)*50)
	for p in sine_cosine_replic
	if isinstance(p, types.TupleType)]

    # create circle
    circle = [(50*(1 + ring * math.sin(math.radians(i))),
	       50*(1 + ring * math.cos(math.radians(i))))
	      for i in range(0, 361)]

    # trend vector
    vect = [((scaleval * p[0]/maxradius + 1)*50,
	     (scaleval * p[1]/maxradius + 1)*50)
	    for p in vector[1:]]

    # Possible TODOs:
    # To fill data area with color, use BOTH d.graph's polyline and polygon commands.
    #  Using polygon alone gives a jagged boundary due to sampling technique (not a bug).

    # plot it!
    lines = [
	# draw circle
	#   mandatory when drawing proportional to non-square frame
	"color 180:255:180",
	"polyline"] + circle + [
	# draw axes
        "color 180:180:180",
        "width 0",
        "move 0 50",
        "draw 100 50",
        "move 50 0",
        "draw 50 100",

	# draw the goods
        "color red",
        "width 0",
        "polyline"] + sine_cosine_replic_normalized + [
	# draw vector
        "color blue",
        "width 3",
        "polyline"] + vect + [

	# draw compass text
        "color black",
        "width 2",
        "size 10 10",
        "move 51 97",
        "text N",
        "move 51 1",
        "text S",
        "move 1 51",
        "text W",
        "move 97 51",
        "text E",

	# draw legend text
        "width 0",
        "size 10",
        "color 0:180:0",
        "move 0.5 96.5",
        "text All data (incl. NULLs)",
        "color red",
        "move 0.5 93.5",
        "text Real data angles",
        "color blue",
        "move 0.5 90.5",
        "text Avg. direction"
	]

    p = grass.feed_command('d.graph', env = tenv)
    for point in lines:
	if isinstance(point, types.TupleType):
	    p.stdin.write("%f %f\n" % point)
	else:
	    p.stdin.write(point + '\n')
    p.stdin.close()
    p.wait()
Пример #4
0
def plot_dgraph():
    # use d.info and d.frame to create a square frame in the center of the
    # window.
    s = gcore.read_command('d.info', flags='d')
    f = s.split()
    frame_width = float(f[2])
    frame_height = float(f[3])

    # take shorter side as length of frame side
    min_side = min(frame_width, frame_height)
    dx = (frame_width - min_side) / 2
    dy = (frame_height - min_side) / 2

    fl = dx
    fr = frame_width - dx
    ft = dy
    fb = frame_height - dy

    tenv = os.environ.copy()
    tenv['GRASS_RENDER_FRAME'] = '%f,%f,%f,%f' % (ft, fb, fl, fr)

    # polyline calculations
    ring = 0.95
    scaleval = ring * totalvalidnumber / totalnumber

    sine_cosine_replic_normalized = [((scaleval * p[0] / maxradius + 1) * 50,
                                      (scaleval * p[1] / maxradius + 1) * 50)
                                     for p in sine_cosine_replic
                                     if isinstance(p, tuple)]

    # create circle
    circle = [(50 * (1 + ring * math.sin(math.radians(i))),
               50 * (1 + ring * math.cos(math.radians(i))))
              for i in range(0, 361)]

    # trend vector
    vect = [((scaleval * p[0] / maxradius + 1) * 50,
             (scaleval * p[1] / maxradius + 1) * 50) for p in vector[1:]]

    # Possible TODOs:
    # To fill data area with color, use BOTH d.graph's polyline and polygon commands.
    # Using polygon alone gives a jagged boundary due to sampling technique
    # (not a bug).

    # plot it!
    lines = [
        # draw circle
        #   mandatory when drawing proportional to non-square frame
        "color 180:255:180",
        "polyline"
    ] + circle + [
        # draw axes
        "color 180:180:180",
        "width 0",
        "move 0 50",
        "draw 100 50",
        "move 50 0",
        "draw 50 100",

        # draw the goods
        "color red",
        "width 0",
        "polyline"
    ] + sine_cosine_replic_normalized + [
        # draw vector
        "color blue",
        "width 3",
        "polyline"
    ] + vect + [

        # draw compass text
        "color black",
        "width 2",
        "size 10 10",
        "move 51 97",
        "text N",
        "move 51 1",
        "text S",
        "move 1 51",
        "text W",
        "move 97 51",
        "text E",

        # draw legend text
        "width 0",
        "size 10",
        "color 0:180:0",
        "move 0.5 96.5",
        "text All data (incl. NULLs)",
        "color red",
        "move 0.5 93.5",
        "text Real data angles",
        "color blue",
        "move 0.5 90.5",
        "text Avg. direction"
    ]

    p = gcore.feed_command('d.graph', env=tenv)
    for point in lines:
        if isinstance(point, tuple):
            p.stdin.write("%f %f\n" % point)
        else:
            p.stdin.write(point + '\n')
    p.stdin.close()
    p.wait()
Пример #5
0
def main():
    layers = options['map'].split(',')

    if len(layers) < 2:
	grass.error(_("At least 2 maps are required"))

    tmpfile = grass.tempfile()

    for map in layers:
	if not grass.find_file(map, element = 'cell')['file']:
	    grass.fatal(_("Raster map <%s> not found") % map)

    grass.write_command('d.text', color = 'black', size = 4, line = 1, stdin = "CORRELATION")

    os.environ['GRASS_PNG_READ'] = 'TRUE'

    colors = "red black blue green gray violet".split()
    line = 2
    iloop = 0
    jloop = 0
    for iloop, i in enumerate(layers):
	for jloop, j in enumerate(layers):
	    if i != j and iloop <= jloop:
		color = colors[0]
		colors = colors[1:]
		colors.append(color)
		grass.write_command('d.text', color = color, size = 4, line = line, stdin = "%s %s" % (i, j))
		line += 1

		ofile = file(tmpfile, 'w')
		grass.run_command('r.stats', flags = 'cnA', input = (i, j), stdout = ofile)
		ofile.close()

		ifile = file(tmpfile, 'r')
		first = True
		for l in ifile:
		    f = l.rstrip('\r\n').split(' ')
		    x = float(f[0])
		    y = float(f[1])
		    if first:
			minx = maxx = x
			miny = maxy = y
			first = False
		    if minx > x: minx = x
		    if maxx < x: maxx = x
		    if miny > y: miny = y
		    if maxy < y: maxy = y
		ifile.close()

		kx = 100.0/(maxx-minx+1)
		ky = 100.0/(maxy-miny+1)

		p = grass.feed_command('d.graph', color = color)
		ofile = p.stdin

		ifile = file(tmpfile, 'r')
		for l in ifile:
		    f = l.rstrip('\r\n').split(' ')
		    x = float(f[0])
		    y = float(f[1])
		    ofile.write("icon + 0.1 %f %f\n" % ((x-minx+1) * kx, (y-miny+1) * ky))
		ifile.close()

		ofile.close()
		p.wait()

    grass.try_remove(tmpfile)
Пример #6
0
def main():
    layers = options["map"].split(",")

    if len(layers) < 2:
        gcore.error(_("At least 2 maps are required"))

    tmpfile = gcore.tempfile()

    for map in layers:
        if not gcore.find_file(map, element="cell")["file"]:
            gcore.fatal(_("Raster map <%s> not found") % map)

    gcore.write_command("d.text", color="black", size=4, line=1, stdin="CORRELATION")

    os.environ["GRASS_RENDER_FILE_READ"] = "TRUE"

    colors = "red black blue green gray violet".split()
    line = 2
    iloop = 0
    jloop = 0
    for iloop, i in enumerate(layers):
        for jloop, j in enumerate(layers):
            if i != j and iloop <= jloop:
                color = colors[0]
                colors = colors[1:]
                colors.append(color)
                gcore.write_command("d.text", color=color, size=4, line=line, stdin="%s %s" % (i, j))
                line += 1

                ofile = file(tmpfile, "w")
                gcore.run_command("r.stats", flags="cnA", input=(i, j), stdout=ofile)
                ofile.close()

                ifile = file(tmpfile, "r")
                first = True
                for l in ifile:
                    f = l.rstrip("\r\n").split(" ")
                    x = float(f[0])
                    y = float(f[1])
                    if first:
                        minx = maxx = x
                        miny = maxy = y
                        first = False
                    if minx > x:
                        minx = x
                    if maxx < x:
                        maxx = x
                    if miny > y:
                        miny = y
                    if maxy < y:
                        maxy = y
                ifile.close()

                kx = 100.0 / (maxx - minx + 1)
                ky = 100.0 / (maxy - miny + 1)

                p = gcore.feed_command("d.graph", color=color)
                ofile = p.stdin

                ifile = file(tmpfile, "r")
                for l in ifile:
                    f = l.rstrip("\r\n").split(" ")
                    x = float(f[0])
                    y = float(f[1])
                    ofile.write("icon + 0.1 %f %f\n" % ((x - minx + 1) * kx, (y - miny + 1) * ky))
                ifile.close()

                ofile.close()
                p.wait()

    try_remove(tmpfile)