better peak extraction
[imago.git] / gridf_analyzer.py
index feb1e25..9ae783f 100644 (file)
@@ -1,50 +1,45 @@
 import matplotlib.pyplot as plt
 from matplotlib import cm
-import time
 import sys
 import pickle
 import multiprocessing
 
 import gridf
 
-def job1(args):
-    X, Y, im_l, a, b, c, d, s, v1, k, hough, size = args
-    return [gridf.distance(im_l, 
-                     gridf.get_grid(a + X[y] * s * v1, 
-                              b + Y[y] * s * v1, 
-                              c, d, hough, size),
-                     size) for y in range(2 * k)]
-def job2(args):
-    X, Y, im_l, a, b, c, d, s, v1, v2, k, hough, size = args
-    return [gridf.distance(im_l, 
-                     gridf.get_grid(a, b, c+ X[y] * s * v2, 
-                              d + Y[y] * s * v2, 
-                              hough, size),
-                     size) for y in range(2 * k)]
-
-def error_surface(im_l, a, b, c, d, hough, size, v1, v2):
+def dist1(task):
+    d, _, _ = gridf.job_br1(task)
+    return d
+
+def dist2(task):
+    d, _, _ = gridf.job_br2(task)
+    return d
+
+def error_surface(k, im_l, v1, v2, h1, h2, dv, dh, x_v, y_v, x_h, y_h, size):
     X = []
     Y = []
-    Z = []
-    s = 0.001
-    k = 250
-    for i in range(-k, k):
-        X.append(range(-k, k))
-        Y.append(2*k*[i])
-
-    tasks = [(X[x], Y[x], im_l, a, b, c, d, s, v1, v2, k, hough, size) for x in xrange(0, 2 * k)]
+    Z1 = []
+    Z2 = []
 
     pool = multiprocessing.Pool(None)
     
-    start = time.time()
-    Z = pool.map(job2, tasks, 1)
-    print time.time() - start
-
-    s_file = open('surface' + str(k), 'w')
-    pickle.dump((X, Y, Z), s_file)
-    s_file.close()
-    plt.imshow(Z, cmap=cm.jet, interpolation='bicubic', 
-               origin='upper', extent=(-k, k, -k, k), aspect='equal')
-    plt.colorbar()
+    for y in xrange(-k, k):
+        tasks = [(im_l, v1, v2, h1, h2, x, y, dv, dh, size) for x in xrange(-k, k)]
+        Z1.append(pool.map(dist1, tasks, 8))
+        Z2.append(pool.map(dist2, tasks, 8))
+
+    fig = plt.figure()
+    s1 = fig.add_subplot(121)
+    s2 = fig.add_subplot(122)
+
+    s1.imshow(Z1, cmap=cm.jet, interpolation='bicubic', 
+                extent=(-k, k, -k, k), aspect='equal')
+    s1.plot([x_v], [-y_v], 'o')
+    s1.set_ylim(-k, k)
+    s1.set_xlim(-k, k)
+    s2.imshow(Z2, cmap=cm.jet, interpolation='bicubic', 
+                extent=(-k, k, -k, k), aspect='equal')
+    s2.plot([x_h], [-y_h], 'o')
+    s2.set_ylim(-k, k)
+    s2.set_xlim(-k, k)
 
     plt.show()