From 50daeb5d74077b44c16c37d11d066233ec350c57 Mon Sep 17 00:00:00 2001 From: Stephen Mardson McQuay Date: Sun, 7 Feb 2010 00:01:02 -0700 Subject: [PATCH] getting stuff from qdelaunay mostly spent time trying to figure out subprocess (which i though i already understood). I am concerned for what will happen with large datasets. next steps include: 1) design data struture 2) implement slurping of stdout into this structure 3) drink coke --HG-- rename : lib/smcqhull.py => lib/smcqdelaunay.py --- bin/driver.py | 2 +- lib/grid.py | 4 ++-- lib/smcqdelaunay.py | 17 +++++++++++++++++ lib/smcqhull.py | 4 ---- test/baker.test.py | 7 +++++++ test/qhull.test.py | 4 +--- 6 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 lib/smcqdelaunay.py delete mode 100644 lib/smcqhull.py diff --git a/bin/driver.py b/bin/driver.py index d78fadd..60e61ac 100755 --- a/bin/driver.py +++ b/bin/driver.py @@ -122,4 +122,4 @@ if __name__ == '__main__': errors.append(cur_error) print rms(errors) - print "%s of %s won" % (success, options.destination_total) + print "%s of %s won" % (success, len(mesh_dest.points)) diff --git a/lib/grid.py b/lib/grid.py index 6257fd9..2dd1454 100755 --- a/lib/grid.py +++ b/lib/grid.py @@ -15,8 +15,8 @@ class grid(object): def __str__(self): r = '' assert( len(self.points) == len(self.q) ) - for i in xrange(len(self.points)): - r += "%r: %0.4f\n" % ( self.points[i], self.q[i] ) + for c, i in enumerate(zip(self.points, self.q)): + r += "%d %r: %0.4f\n" % (c,i[0], i[1]) return r class simple_rect_grid(grid): diff --git a/lib/smcqdelaunay.py b/lib/smcqdelaunay.py new file mode 100644 index 0000000..d17ec8d --- /dev/null +++ b/lib/smcqdelaunay.py @@ -0,0 +1,17 @@ +#!/usr/bin/python + +from subprocess import Popen, PIPE +from grid import simple_rect_grid + +def get_qdelaunay_dump(g): + cmd = 'qdelaunay Qt f' + p = Popen(cmd.split(), bufsize=1, stdin=PIPE, stdout=PIPE) + so, se = p.communicate(g.for_qhull()) + for i in so.splitlines(): + yield i + +if __name__ == '__main__': + g = simple_rect_grid(3,3) + print g + for i in get_qdelaunay_dump(g): + print i diff --git a/lib/smcqhull.py b/lib/smcqhull.py deleted file mode 100644 index a50160d..0000000 --- a/lib/smcqhull.py +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/python - -if __name__ == '__main__': - print "hello world" diff --git a/test/baker.test.py b/test/baker.test.py index 47aa3b9..91936aa 100755 --- a/test/baker.test.py +++ b/test/baker.test.py @@ -25,6 +25,13 @@ class TestSequenceFunctions(unittest.TestCase): self.q = [1, 0, 0, 0, 0, 0, 0, 0, 0] self.X = [1.5, 10.25] + def testImports(self): + import numpy + import scipy + import grid + import baker + import delaunay + def testGetPhis(self): X = [0,0] diff --git a/test/qhull.test.py b/test/qhull.test.py index 5a12ba0..fdb02ca 100755 --- a/test/qhull.test.py +++ b/test/qhull.test.py @@ -1,9 +1,6 @@ #!/usr/bin/python - -import random import unittest -import delaunay class TestSequenceFunctions(unittest.TestCase): def setUp(self): @@ -11,6 +8,7 @@ class TestSequenceFunctions(unittest.TestCase): def testQhull(self): + import delaunay dt = delaunay.Triangulation(self.l) answer = [ [4,1,3],