Beispiel #1
0
def multipoint(dang,wids,weig=None,repeaf=None,xpts=None,ypts=None,poly_deg=2,alog=None,aform='UV_%i',rep=0,check=False,dowid=True):
    global ualc
    from numpy import array,abs,polyfit,polyval,dot,ones,arange,iterable
    if alog!=None: #evaluate function fitted to measured values
        if iterable(alog):
            ualc=alog
        else:
            valc=[polyfit(alog.base,alog[aform%i],poly_deg) for i in dang]
            if type(xpts)==list: xpts=alog.base[xpts]
            ualc=array([polyval(a,xpts) for a in valc])
            if rep==1: return xpts,ualc
            print('fitted for polynom deg %i'%poly_deg)
            if check:
                for j in range(len(dang)):
                    print('ang %i:chi2 %.4f'%(dang[j],sum((polyval(valc[j],alog.base)-alog[aform%dang[j]])**2)))
    if weig==None: weig=ones(len(dang))
    if ypts!=None: #p0=list(ypts.real.flat)+list(ypts.imag.flat)+list(wids)
        p0=list(array([ypts.real,ypts.imag]).swapaxes(0,2).swapaxes(0,1).flat)+wids
        neps=len(ypts)
    else: 
        p0=None
        neps=len(wids)+1
    if repeaf==None: repeaf=arange(neps)
    #print 'shape:',neps,len(xpts),2
    feps=lambda p:dot(array(p[:neps*len(xpts)*2]).reshape(neps,len(xpts),2),array([1,1j]))
    if dowid:
        from ellipse import calc_ellips_plate
        wfit=lambda p:sum([sum(abs(calc_ellips_plate(xpts,feps(p)[repeaf],p[-len(wids):],ang=dang[i],rep=0,corr='pos')-ualc[i]))*weig[i] for i in range(len(dang))])
        return wfit,p0
    else:
        wfit=lambda p:sum([sum(abs(calc_ellips_plate(xpts,feps(p)[repeaf],wids,ang=dang[i],rep=0,corr='pos')-ualc[i]))*weig[i] for i in range(len(dang))])
        return wfit,p0[:-len(wids)]
Beispiel #2
0
def selpoint(x,
             meas,
             epsil=[10 + 4j, 2.5, 10 + 2j],
             vari=[1, 0, 2],
             wid=[230, 60.],
             angs=[60, 70, 80],
             rep=0):
    global plout
    from numpy import zeros, dot, array
    vepsil = zeros((len(epsil), max(vari)))
    for i in range(len(vari)):
        if vari[i] > 0: vepsil[i, vari[i] - 1] = 1
    fuc = lambda p, k: array([
        calc_ellips_plate(x[k], epsil + dot(vepsil, p), wid, rep=0, ang=a)
        for a in angs
    ])
    if rep == 1: return fuc
    from scipy import optimize
    plout = [zeros(max(vari))]
    out = []
    for k in range(len(meas)):
        plout.append(
            optimize.fmin(lambda p: sum(abs(fuc(p, k) - meas[k])), plout[-1]))
        out.append(sum(abs(fuc(plout[-1], k) - meas[k])))
    return out
Beispiel #3
0
def ptbypt(meas,dang,freq,nlay=1):
    '''gets epsilon and layer thickness from ellips. measurements at different angles
    point-by-point
    '''
    dfit=lambda p,w:sum([abs(calc_ellips_plate(freq,p,w,ang=dang[i],rep=0)-meas[i])**2 for i in range(len(dang))])
    wfit=lambda q:dfit([q[i]+1j*q[i+1] for i in range(nlay+1)],q[-nlay:])
    return wfit
Beispiel #4
0
def ptbypt(meas, dang, freq, nlay=1):
    '''gets epsilon and layer thickness from ellips. measurements at different angles
    point-by-point
    '''
    dfit = lambda p, w: sum([
        abs(calc_ellips_plate(freq, p, w, ang=dang[i], rep=0) - meas[i])**2
        for i in range(len(dang))
    ])
    wfit = lambda q: dfit([q[i] + 1j * q[i + 1]
                           for i in range(nlay + 1)], q[-nlay:])
    return wfit
Beispiel #5
0
def selpoint(x,meas,epsil=[10+4j,2.5,10+2j],vari=[1,0,2],wid=[230,60.],angs=[60,70,80],rep=0):
	global plout
	from numpy import zeros,dot,array
	vepsil=zeros((len(epsil),max(vari)))
	for i in range(len(vari)): 
		if vari[i]>0:vepsil[i,vari[i]-1]=1
	fuc=lambda p,k:array([calc_ellips_plate(x[k],epsil+dot(vepsil,p),wid,rep=0,ang=a) for a in angs])
	if rep==1: return fuc
	from scipy import optimize
	plout=[zeros(max(vari))]
	out=[]
	for k in range(len(meas)):	
	    plout.append(optimize.fmin(lambda p:sum(abs(fuc(p,k)-meas[k])),plout[-1]))
	    out.append(sum(abs(fuc(plout[-1],k)-meas[k])))
	return out
Beispiel #6
0
def multipoint(dang,
               wids,
               weig=None,
               repeaf=None,
               xpts=None,
               ypts=None,
               poly_deg=2,
               alog=None,
               aform='UV_%i',
               rep=0,
               check=False,
               dowid=True):
    global ualc
    from numpy import array, abs, polyfit, polyval, dot, ones, arange, iterable
    if alog != None:  #evaluate function fitted to measured values
        if iterable(alog):
            ualc = alog
        else:
            valc = [
                polyfit(alog.base, alog[aform % i], poly_deg) for i in dang
            ]
            if type(xpts) == list: xpts = alog.base[xpts]
            ualc = array([polyval(a, xpts) for a in valc])
            if rep == 1: return xpts, ualc
            print('fitted for polynom deg %i' % poly_deg)
            if check:
                for j in range(len(dang)):
                    print('ang %i:chi2 %.4f' %
                          (dang[j],
                           sum((polyval(valc[j], alog.base) -
                                alog[aform % dang[j]])**2)))
    if weig == None: weig = ones(len(dang))
    if ypts != None:  #p0=list(ypts.real.flat)+list(ypts.imag.flat)+list(wids)
        p0 = list(
            array([ypts.real, ypts.imag]).swapaxes(0, 2).swapaxes(
                0, 1).flat) + wids
        neps = len(ypts)
    else:
        p0 = None
        neps = len(wids) + 1
    if repeaf == None: repeaf = arange(neps)
    #print 'shape:',neps,len(xpts),2
    feps = lambda p: dot(
        array(p[:neps * len(xpts) * 2]).reshape(neps, len(xpts), 2),
        array([1, 1j]))
    if dowid:
        from ellipse import calc_ellips_plate
        wfit = lambda p: sum([
            sum(
                abs(
                    calc_ellips_plate(xpts,
                                      feps(p)[repeaf],
                                      p[-len(wids):],
                                      ang=dang[i],
                                      rep=0,
                                      corr='pos') - ualc[i])) * weig[i]
            for i in range(len(dang))
        ])
        return wfit, p0
    else:
        wfit = lambda p: sum([
            sum(
                abs(
                    calc_ellips_plate(xpts,
                                      feps(p)[repeaf],
                                      wids,
                                      ang=dang[i],
                                      rep=0,
                                      corr='pos') - ualc[i])) * weig[i]
            for i in range(len(dang))
        ])
        return wfit, p0[:-len(wids)]