From: Dan White Date: Wed, 29 Aug 2012 17:58:08 +0000 (-0500) Subject: cleanup X-Git-Tag: calibrations~14 X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=38a5c2d0108971396a97dc4c6941529fd4e1932e;p=430.git cleanup --- diff --git a/python-lib/calibrate.py b/python-lib/calibrate.py index 9888798..530d4ff 100644 --- a/python-lib/calibrate.py +++ b/python-lib/calibrate.py @@ -54,7 +54,6 @@ def bisect(fset, limits=[0.0, 1.0], dgmin=None, up='uk', down='dj'): -from scipy.optimize import brentq def secant_opt(func, x0, limits, x1scale=0.5, tol=1e-3, maxiter=50): """ Find the function's zero on a bounded interval using the secant method. @@ -110,10 +109,8 @@ def secant_opt(func, x0, limits, x1scale=0.5, tol=1e-3, maxiter=50): a0 = abs(q0) a1 = abs(q1) a = abs(q) + #ensure we pick the correct value if (a0 <= a1) and (a <= a1): - #print "*** turnaround convergence ***" - #print ''.join(['%5i ' % i for i in guesses]) - #print ''.join(['%9.2e' % i for i in results]) return p0 #else: #print "false alarm, almost there..." @@ -143,8 +140,6 @@ def mux_a_offset(x): values.append(offset2signed(adc.read(), 16)) sleep(DELAY) mv = mean(values) - #print xi, mv - #print '%4i'%xi, tplot(mv) print tpx(xi), tplot(mv) return mv @@ -158,9 +153,6 @@ def mux_b_offset(x): values.append(offset2signed(adc.read(), 16)) sleep(DELAY) mv = mean(values) - #print xi, mv - #print tplot(mv) - #print '%4i'%xi, tplot(mv) print tpx(xi), tplot(mv) return mv @@ -179,9 +171,6 @@ def chain_a_offset(x, n, mux_offset): values.append(offset2signed(adc.read(), 16)) sleep(DELAY) mv = mean(values) - #print xi, mv - #print tplot(mv) - #print '%4i'%xi, tplot(mv) print tpx(xi), tplot(mv) return mv - mux_offset @@ -204,8 +193,6 @@ mux.write() adc.triggerMode(adc.MODE_MANUAL_MANUAL) -#from scipy.optimize import brentq as fopt -from scipy.optimize import bisect as fopt N_SAMPLES = 10 DELAY = 0.05 @@ -213,8 +200,6 @@ DELAY = 0.05 print print 'Calibrating mux otaA' adc.mux(4) -#resA = fopt(mux_a_offset, -128, 127, xtol=0.01, disp=True) -#def secant_opt(func, x0, limits, x1scale=0.5, tol=1e-3, maxiter=50): resA = secant_opt(mux_a_offset, 0, [-128, 127]) muxA_offset = mean([offset2signed(adc.read(), 16) for i in range(1000)]) print '*** mux.otaA.offset =', muxA_offset, ' @', resA @@ -225,7 +210,6 @@ if 1: print print 'Calibrating mux otaB' adc.mux(5) - #resB = fopt(mux_b_offset, -128, 127, xtol=0.01, disp=True) resB = secant_opt(mux_b_offset, 0, [-128, 127]) muxB_offset = mean([offset2signed(adc.read(), 16) for i in range(1000)]) print '*** mux.otaB.offset =', muxB_offset, ' @', resB @@ -242,10 +226,6 @@ if 1: mux.otaA.mode = mux.otaA.MUX_BUF mux.otaB.mode = mux.otaB.MUX_BUF mux.write() - #nos = fopt(lambda x: chain_a_offset(x, n, muxA_offset), - #-128, 127, - #xtol=0.01, - #disp=True) nos = secant_opt(lambda x: chain_a_offset(x, n, muxA_offset), 0, (-128, 127)) mean_os = mean([offset2signed(adc.read(), 16) for i in range(1000)]) print '*** chain.h[%02i].otaA.offset =' % n, mean_os, ' @', nos