From 9d4a620bf10ccb0a0166c73288e4dd001b3c12f9 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 8 Apr 2010 13:56:36 -0400 Subject: [PATCH] Add improved extract_fit_valley.py to fit-space Makefile flow --- tex/src/figures/fit-space/Makefile | 7 +++- .../figures/fit-space/extract_fit_valley.py | 41 ++++++++++++++----- tex/src/figures/fit-space/fit_valley.data | 29 ------------- 3 files changed, 35 insertions(+), 42 deletions(-) delete mode 100644 tex/src/figures/fit-space/fit_valley.data diff --git a/tex/src/figures/fit-space/Makefile b/tex/src/figures/fit-space/Makefile index fcfaa89..f304605 100644 --- a/tex/src/figures/fit-space/Makefile +++ b/tex/src/figures/fit-space/Makefile @@ -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 $< > $@ diff --git a/tex/src/figures/fit-space/extract_fit_valley.py b/tex/src/figures/fit-space/extract_fit_valley.py index 92a8667..3b2c37a 100644 --- a/tex/src/figures/fit-space/extract_fit_valley.py +++ b/tex/src/figures/fit-space/extract_fit_valley.py @@ -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 index 9216c79..0000000 --- a/tex/src/figures/fit-space/fit_valley.data +++ /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 -- 2.26.2