#!/usr/bin/python import sys from optparse import OptionParser import numpy as np import scipy.spatial from grid import simple_random_grid, exact_func import baker def rms(errors): r = 0.0 for i in errors: r += np.power(i, 2) r = np.sqrt(r / len(errors)) return r if __name__ == '__main__': parser = OptionParser() parser.add_option("-o", "--output-file", dest="output", type='str', default = '/tmp/for_qhull.txt', help = "qhull output file") parser.add_option("-e", "--extra-points", dest="extra", type='int', default = 3, help = "how many extra points") parser.add_option("-s", "--source-total", dest="source_total", type='int', default = 100, help = "total number of source points") parser.add_option("-d", "--destination-total",dest="destination_total",type='int', default = 100, help = "total number of destination points") parser.add_option("-v", "--verbose", action = 'store_true', default = False, help = "verbosity") (options, args) = parser.parse_args() print >> sys.stderr, options mesh_source = simple_random_grid(options.source_total) tree = scipy.spatial.KDTree(mesh_source.points) mesh_dest = simple_random_grid(options.destination_total) open(options.output, 'w').write(mesh_source.for_qhull()) print >> sys.stderr, "wrote output to %s" % options.output errors = [] for x in mesh_dest.points: (final, exact) = baker.run_baker(x, mesh_source, tree, options.extra, options.verbose) cur_error = np.abs(final - exact) errors.append(cur_error) print rms(errors)