示例#1
0
def sfine2(mom,leps,thk=254,emax=3.4,minor=0,dofit=4,inorm=[1,1,1],doplot=False):
    '''
    dofit==1: fit only thickness, renorm parameters fixed
    minor: minim. value of refer. spectrum to include point in chi2
    '''
    import profit
    inipars=[thk]+inorm
    enxz=enx[enx<emax]
    def zres(pars):
        model1=profit.plate(enxz,[leps,epssi[enx<emax]],pars[:1])
        dif=0
        for i in range(len(mom)):
            dsel=(mom[i]>0)*(enx<emax)
            if minor>0: dsel*=nor[i]>minor
            dif+=((mom[i][dsel]*pars[i+1]-model1[dsel[enx<emax]])**2*nor[i][dsel]).sum()*wnor[i]
        return dif
    from scipy import optimize as op
    if dofit==1: 
        fitpars=op.fmin(lambda p:zres(list(p)+inipars[1:]),inipars[:1],disp=0)
        qpars=inipars[1:]
    else: 
        fitpars=op.fmin(zres,inipars,disp=0)
        qpars=fitpars[1:]
    if doplot:
        from matplotlib import plot as pl
        model1=profit.plate(enxz,[leps,epssi[enx<emax]],fitpars[:1])
        pl.plot(enxz,model1)
        for i in range(len(mom)):
            m=mom[i]
            pl.plot(enx[(m>0)*(enx<emax)],m[(m>0)*(enx<emax)]*qpars[i],'rgm'[i])
    if dofit==1: 
        return fitpars,zres(list(fitpars)+inipars[1:])
    else: 
        return fitpars,zres(fitpars)
示例#2
0
 def zres(pars):
     model1=profit.plate(enxz,[leps,epssi[enx<emax]],pars[:1])
     dif=0
     for i in range(len(mom)):
         dsel=(mom[i]>0)*(enx<emax)
         if minor>0: dsel*=nor[i]>minor
         dif+=((mom[i][dsel]*pars[i+1]-model1[dsel[enx<emax]])**2*nor[i][dsel]).sum()*wnor[i]
     return dif
示例#3
0
def calc_ellips_plate(freq,epsil,wid=[],ang=60,conv=1,rep=0,corr=None):
    '''calculates ellipsometric angles for given layers'''
    from numpy import arctan,arctan2,abs
    from profit import plate,reflect
    if conv: conv=180./pi
    if len(wid)==0: #bulk material
        zz=reflect(epsil[0],ang=ang,polar='p',rep=0)
        zz/=reflect(epsil[0],ang=ang,polar='s',rep=0)
    else:
        if ang<0:
            fr=plate(freq,epsil,wid,ang=ang,rep=-1)
            zz=friter([f[:,0] for f in fr[0]],fr[1],fr[2])/friter([f[:,1] for f in fr[0]],fr[1],fr[2])
        else:
            zz=plate(freq,epsil,wid,ang=ang,rep=0,polar='p')
            zz/=plate(freq,epsil,wid,ang=ang,rep=0,polar='s')
    if rep==-2: return zz
    out=arctan(abs(zz))*conv,-arctan2(zz.imag,zz.real)*conv
    if corr=='pos':
        out[1][out[1]<-90]+=360.
    if rep==1: return out[0]+1j*out[1]
    else: return out
示例#4
0
文件: labin.py 项目: limu007/Charlay
 def measure(self,npix=None,**kwargs):
     from numpy.random import normal
     from math import sqrt
     if self.config==None:
         print("You must config first!")
         return
     if 'noise' in kwargs: noise=float(kwargs['noise'])
     else: noise=getattr(self.config,'Noise',0.05)
     noise/=sqrt(self.config.m_NrAverages)
     rep=normal(size=self.pixtable.shape,scale=noise)
     mater=None
     if 'mater' in kwargs: mater=kwargs['mater']
     elif hasattr(self.config,'Material') and self.config.Material.decode('ascii')!='simu': mater=self.config.Material.decode('ascii')
     else: mater=rc.simu_mater
     #print('using |'+str(mater)+'|')
     if mater!=None:
         if type(mater)==list:
             for m in mater:
                 if not m in self.data:
                     if m in rc.eps_ext: 
                         from profit import dielect
                         self.data[m]=dielect(self.pixtable,rc.eps_ext[m][0],rc.eps_ext[m][1])
                     elif m in rc.mod_ext: 
                         from numpy import polyval
                         self.data[m]=polyval(rc.mod_ext[m],self.pixtable)**2
                     print('calculating diel. '+m)
             if len(mater)-len(rc.simu_layer) in [0,1]:
                 from profit import plate
                 wid=rc.simu_layer
                 if hasattr(rc,'simu_layer_fluc'): wid=[wid[i]*normal(1,rc.simu_layer_fluc[i]) for i in range(len(wid))]
                 rep+=plate(self.pixtable,[self.data[m] for m in mater],wid)
         else:
             if not mater in self.data:
                 if mater in rc.mod_ext: 
                     from numpy import polyval
                     self.data[mater]=polyval(rc.mod_ext[mater],self.pixtable)**2
                 else:
                     from spectra import dbload
                     if type(mater)==bytes: dbname=mater.decode('ascii')
                     else: dbname=mater
                     if dbname in rc.eps_trans: dbname=rc.eps_trans[dbname]
                     try:
                         inp=dbload(dbname,self.pixtable)
                     except:
                         print('cannot load material '+dbname)
                         return rep
                     #for i in range(len(inp)):
                     self.data[mater]=inp[1]
             if len(self.data)>0:
                 from profit import reflect
                 rep+=reflect(self.data[mater])#,self.data[mater[1]])
     rep*=self.config.m_IntegrationTime
     return rep
示例#5
0
def reconstruct(x,y8,points=None,di=10,re_ord=2,n_subs=3.46,thick=2000.,im_ini=0,im_ind=-1):
    if points==None: points=range(5*di,len(x)-5*di,5*di)
    res=spectra.extrema(y8,x,poly=-1,msplit='sort',extsel=half_anal_width,loud=0)
    mis=[((array(o[1:])+array(o[:-1]))/2.,(array(o[1:])-array(o[:-1]))) for o in res]
    from extra import polyfit as rob_fit
    n_pr=array([rob_fit(m[0],1/(spectra.ev2um*m[1]*2.*thick/1000.),re_ord,clip=1,lim=1.1) for m in mis])
    n_re=polyval(n_pr.mean()/r_[re_ord+1:0.:-1.],x) #real part from oscillations
    moo=[im_ini]
    from scipy import optimize
    for i in points:
        muf=lambda z:sum((y8[i-di:i+di]-profit.plate(x[i-di:i+di],[(n_re[i-di:i+di]+1j*z)**2,n_subs**2],[thick]))**2)
        moo.append(optimize.fmin(muf,moo[im_ind])[0])
    return n_pr,moo
示例#6
0
def test_prepare(wrange,w2=1000,norm=620,j=0):
    global sig_limit,dt
    import profit
    tsig=sig_limit
    sig_limit=0
    epsil=profit.dielect(px,spectra.lor_si_low[0],spectra.lor_si_low[1])
    oxide=polyval(spectra.cau_sio2,px)
    if (dt==None) or (len(wrange)!=len(dt)): dt=[profit.plate(px,[epsil,oxide,epsil],[w1,w2]) for w1 in wrange]
    out=[]
    for a in range(len(wrange)): 
        if anal(a,j,rep=2)[2]>2: out.append([mids,(norm/pers)])
    sig_limit=tsig
    return out
示例#7
0
def extra_test(wid1=1300,wid2=300,step=0.002,isel=1,levabs=0.1,prec=False):
    global bins,refe,mall,dall,zzall,nomal,epsil
    if bins==None:
        bins=r_[1:3:step]
    if epsil==None:
        epsil=dielect(bins,spectra.lor_si_low2[0],spectra.lor_si_low2[1])
        mall=sqrt(epsil.real+1j*levabs).real*bins
        dall=(mall[2:]-mall[:-2])/(bins[2:]-bins[:-2])
    oxide=polyval(spectra.cau_sio2,bins)
    dd=plate(bins,[epsil.real+1j*levabs,oxide,epsil],[wid1,wid2])
    if prec: 
        aall=spectra.extrema(dd,bins,poly=-1,msplit='fine',extsel=5)
        a2=array([sum(bins<a) for a in aall[isel]])
        dp=array(aall[isel])[1:]-array(aall[isel])[:-1]
    else: 
        aall=spectra.extrema(dd)
        a2=array(aall[isel])
        dp=bins[a2][1:]-bins[a2][:-1]
    b2=(a2[1:]+a2[:-1])/2
    return bins[b2],dp,dall[b2-1]
示例#8
0
def bump(w2=310,w1=1500,vl=None,slim=[2.2,2.6],rep=1,min_dis=0.015,loud=0,fit_wid=2):
    global counter
    if vl==None: 
        oxide=polyval(spectra.cau_sio2,px)
        epsil=profit.dielect(px,spectra.lor_si_low[0],spectra.lor_si_low[1])
        vl=profit.plate(px,[epsil,oxide,epsil],[w1,w2])
    a,b=spectra.extrema(vl)
    if len(a)<len(b):a,b=b,a
    if a[0]>b[0]:
        sh=sum(b<a[0])
        b=b[sh:]
    elif a[1]<b[0]:
        sh=sum(a<b[0])
        a=a[sh-1:]
    if a[-1]<b[-1]:
        sh=sum(b>a[-1])
        b=b[:-sh]
    elif a[-2]>b[-1]:
        sh=sum(a>b[-1])
        a=a[:-sh+1]
    assert len(b)==len(a)-1
    m2=concatenate([(px[b]+px[a][:-1])/2.,(px[b]+px[a][1:])/2.])
    n2=concatenate([(vl[b]-vl[a][:-1])/2.,(vl[b]-vl[a][1:])/2.])
    s2=argsort(m2)
    n2=n2[s2]
    m2=m2[s2]
    sel=n2>min_dis
    m2=m2[sel]
    n2=n2[sel]
    if rep==0: return m2,n2
    sel=(m2>slim[0])*(m2<slim[1])
    if sum(sel)<2*fit_wid:
        return 0,0
    i1=argmin(n2[sel])
    s=(m2[sel][i1]+m2[sel][i1+1])/2.
    j1=i1>fit_wid and i1-fit_wid  or None
    j2=i1+fit_wid+1
    counter+=1
    k,l=polyfit(m2[sel][j1:j2],(n2[sel]*sign(m2[sel]-s))[j1:j2],1)
    chi2=sum((polyval([k,l],m2[sel][j1:j2])-(n2[sel]*sign(m2[sel]-s))[j1:j2])**2)
    return -l/k,chi2