Add improved extract_fit_valley.py to fit-space Makefile flow
authorW. Trevor King <wking@drexel.edu>
Thu, 8 Apr 2010 17:56:36 +0000 (13:56 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 8 Apr 2010 17:56:36 +0000 (13:56 -0400)
tex/src/figures/fit-space/Makefile
tex/src/figures/fit-space/extract_fit_valley.py
tex/src/figures/fit-space/fit_valley.data [deleted file]

index fcfaa89b7af530e9d63d5a603a9ccc816d3829d5..f3046053cabdca820f2b087d3ab3a995c5ffd54b 100644 (file)
@@ -1,7 +1,10 @@
 all : fig.pdf
 
 clean :
-       rm -f fig.pdf
+       rm -f fig.pdf fit_valley.data
 
-fig.pdf :
+fig.pdf : fit_valley.data
        gnuplot plot.gp
+
+fit_valley.data : extract_fit_valley.py data
+       cat data | python $< > $@
index 92a866748de5d6fc337c00975d09d5187a7315c3..3b2c37ad6a7afff9763ad19107eb82909d94bb80 100644 (file)
@@ -2,20 +2,39 @@
 
 import sys
 
-print "#x_u (m)       k_u0 (1/s)"
 current_k = None
 best_x = None
 best_residual = None
+
+data = {}
+header = None
 for line in sys.stdin.readlines():
-    if line.startswith('#') or len(line.strip()) == 0:
+    if len(line.strip()) == 0:
         continue
+    if line.startswith('#'):
+        if header == None:
+            header = line.strip()
+            continue
     k,x,residual = [float(z) for z in line.split()]
-    if k != current_k: # starting a new k
-        if best_x != None: # print summary of last k
-            print '%g\t%g' % (best_x, current_k)
-        current_k = k
-        best_x = None
-        best_residual = 2 # all residuals <= 1
-    if residual < best_residual:
-        best_residual = residual
-        best_x = x
+    data[(k,x)] = residual
+
+ks = sorted(set([k for k,x in data.keys()]))
+max_k = max(ks)
+min_k = min(ks)
+xs = sorted(set([x for k,x in data.keys()]))
+max_x = max(xs)
+min_x = min(xs)
+border_xs = xs[:3] + xs[-3:]
+
+print header
+for k in ks:
+    best_x = xs[0]
+    best_residual = data[(k,x)]
+    for x in xs[1:]:
+        residual = data[(k,x)]
+        if residual < best_residual:
+            best_x = x
+            best_residual = residual
+    if best_x in border_xs:
+        continue # don't print minimums up against the data boundaries
+    print '\t'.join([str(z) for z in [k,best_x,best_residual]])
diff --git a/tex/src/figures/fit-space/fit_valley.data b/tex/src/figures/fit-space/fit_valley.data
deleted file mode 100644 (file)
index 9216c79..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#x_u (m)       k_u0 (1/s)
-1.98077e-10    0.00334363
-1.95385e-10    0.00380203
-1.98077e-10    0.00432328
-1.92692e-10    0.00491598
-1.9e-10        0.00558995
-1.84615e-10    0.00635631
-1.81923e-10    0.00722773
-1.81923e-10    0.00821863
-1.79231e-10    0.00934537
-1.73846e-10    0.0106266
-1.71154e-10    0.0120835
-1.68462e-10    0.01374
-1.65769e-10    0.0156238
-1.63077e-10    0.0177657
-1.57692e-10    0.0202013
-1.60385e-10    0.0229708
-1.52308e-10    0.0261201
-1.49615e-10    0.029701
-1.49615e-10    0.0337729
-1.44231e-10    0.0384031
-1.38846e-10    0.043668
-1.38846e-10    0.0496547
-1.41538e-10    0.0564622
-1.36154e-10    0.0642029
-1.30769e-10    0.0730049
-1.28077e-10    0.0830136
-1.25385e-10    0.0943944
-1.22692e-10    0.107336