P.show() height_diff = list() if save_work: sys.stdout = open(filename + '.txt', 'w') print name print "\nAnalysis Array:" for n in N.arange(y.size): print "\t%d" % (n + 1), print for (num, row) in enumerate(field.T): print "%d\t" % (num + 1), for col in row: print "%7.2f" % col, print print "\nk\tSTID\tZ_o\t\tZ_a\t\tZ_o - Z_a" for i in range(len(data.x)): try: interp_height = oban.bilinear(x, y, field, data.x[i], data.y[i]) hd = data.heights[i] - interp_height height_diff.append(hd) print "%d\t%.0f\t%.4f\t%.4f\t%.4f" % (i, data.stids[i], data.heights[i],\ interp_height, hd) except ValueError: print "%d\t%.0f\t%.4f\tOff Grid\tOff Grid" % (i, data.stids[i],\ data.heights[i]) height_diff = N.array(height_diff) rms = N.sqrt(N.average(height_diff * height_diff)) print "RMS: %.4f m" % rms if save_work: sys.stdout.close()
from scipy.interpolate import interpolate from numpy.random import randn from numpy import meshgrid, arange, array, dot import oban data = randn(16).reshape(4, 4) x = y = arange(4) X, Y = meshgrid(x, y) x_loc = 1.4 y_loc = 2.7 full_bilin = interpolate.interp2d(X, Y, data, kind="linear") partial_bilin = interpolate.interp2d(X[1:, 1:], Y[1:, 1:], data[1:, 1:], kind="linear") single_bilin = interpolate.interp2d(X[2:4, 1:3], Y[2:4, 1:3], data[2:4, 1:3], kind="linear") print full_bilin(x_loc, y_loc) print partial_bilin(x_loc, y_loc) print single_bilin(x_loc, y_loc) top = data[2, 1] + (data[2, 2] - data[2, 1]) * 0.4 bottom = data[3, 1] + (data[3, 2] - data[3, 1]) * 0.4 print top + (bottom - top) * 0.7 xw = 0.4 yw = 0.7 xws = array([1 - xw, xw]) yws = array([1 - yw, yw]) print dot(yws, dot(data[2:4, 1:3], xws)) print oban.bilinear(x, y, data, x_loc, y_loc) print data[2:4, 1:3]