-def secant_opt(func, x0, limits, x1scale=0.1, maxiter=100, k=1.0):
+def secant_opt(func, x0, limits, x1scale=0.1, maxiter=50, k=1.0):
"""
Find the function's zero on a bounded interval using the secant method.
return int64(around(x))
#return int(round(max(min(x, xmax), xmin)))
- def eval(x):
- print 'eval:'
- print x[0:N_CHANNELS]
+ def feval(x):
+ #print 'feval:'
+ #print x[0:N_CHANNELS]
r = func(x)
guesses.append(x)
results.append(r)
return r
- q0 = eval(p0)
+ q0 = feval(p0)
r = xmax - xmin
p1 = saturate(p0 - sign(q0)*x1scale*r)
- q1 = eval(p1)
+ q1 = feval(p1)
for niter in range(maxiter):
iz = find(q1==q0)
q1.flat[iz] = q1.flat[iz] + 1e-6
dp *= converging
p = saturate(p1 - dp)
- q = eval(p)
+ q = feval(p)
# Convergence criteria
# x to varies by (+1,-1) or (-1,+1)
values = []
for i in range(N_SAMPLES):
values.append(offset2signed(adc.read(), 16))
- sleep(DELAY)
+ sleep(SAMPLE_DELAY)
mv = mean(values)
print tpx(xi), tplot(mv)
return array((mv,))
values = []
for i in range(N_SAMPLES):
values.append(offset2signed(adc.read(), 16))
- sleep(DELAY)
+ sleep(SAMPLE_DELAY)
mv = mean(values)
print tpx(xi), tplot(mv)
return array((mv,))
adc.triggerMode(adc.MODE_IDLE)
adc.mux(4) #mux.otaA
adc.fifo(1)
+ adc.triggerMode(adc.MODE_MANUAL_MANUAL)
plotter = TermPlotter([-1000, 1000], width=80)
mux.selB = i
mux.write()
+ sleep(MUX_SETTLE_DELAY)
for j in range(2):
adc.mux(4+j)
- sleep(0.1)
- adc.triggerMode(adc.MODE_MANUAL_MANUAL)
+ #sleep(0.1)
+ #adc.triggerMode(adc.MODE_MANUAL_MANUAL)
#adc.triggerMode(adc.MODE_AUTO_AUTO_SINGLE)
adc.read()
values = []
#print
- for k in range(N_SAMPLES):
+ v = offset2signed(adc.read(), 16)
+ values.append(v)
+ for k in range(N_SAMPLES-1):
+ sleep(SAMPLE_DELAY)
v = offset2signed(adc.read(), 16)
#print plotter(v)
values.append(v)
- sleep(DELAY)
- mv = mean(values[-1*min(10, N_SAMPLES):-1])
+ if N_SAMPLES >= 2:
+ mv = mean(values[-1*min(10, N_SAMPLES):-1])
+ else:
+ mv = values[0]
outs[j, i] = mv
+ print '*** measured outputs: ***'
print outs[:,0:N_CHANNELS]
return outs
def chain_offsets(values, mux_offset):
+ print
+ print '*** sending values: ***'
+ print values[0:N_CHANNELS]
for i,n in enumerate(values[0]):
chain.h[i].otaA.offset = int(n)
chain.h[i].cal = 1
N_CHANNELS = 48
-N_SAMPLES = 10
-DELAY = 0.05
+MUX_SETTLE_DELAY = 0.1
+N_SAMPLES = 1
+SAMPLE_DELAY = 0.02
+
import datetime as dt
N_RUNS = 8
sample_runs = randint(48, size=(N_RUNS,))
N_PLOTS = 4
+sample_channels = sorted(randint(48, size=(N_PLOTS,)))
N_COLS = 4
nrun = 0
for infile in sorted(glob('*.npz')):
+#for infile in sorted(glob('2012-09-03_1*.npz')):
d = np.load(infile)
#print infile, d.keys()
guesses = d['guesses']
results = d['results']
+ nevals = d['nevals']
d.close() # close file descriptor
if 1:
- for i in range(N_PLOTS):
+ for i,k in enumerate(sample_channels):
if nrun not in sample_runs:
continue
- g = guesses[:, 0, i]
- r = 1e3*(2.5/2/2**13)*results[:, 0, i]
- #print g
- #print r
+ g = guesses[:, 0, k]
+ r = 1e3*(2.5/2/2**13)*results[:, 0, k]
subplot(N_PLOTS, N_COLS, N_COLS*i+1)
- plot(g, '-')
+ plot(g[:nevals[0,k]+1], '-')
ylim((0, 127))
- ylabel('Channel %02i-A' % i)
+ ylabel('Channel %02i-A' % k)
subplot(N_PLOTS, N_COLS, N_COLS*i+2)
- plot(r, '-')
+ plot(r[:nevals[0,k]+1], '-')
subplot(N_PLOTS, N_COLS, 1)
title('calibration value')