示例#1
0
def sample1():
        
    # list of wavenumbers to plot in nm^-1
    
    lamb=linspace(400,800,num=15)
    angles=linspace(0,37,8)

    RNA = numpy.zeros((lamb.size,angles.size))
    
    for i in range(lamb.size):
        print(lamb[i])
        for j in range(angles.size):
            RNA[i,j] = inc_tmm('s',n_list, d_list, c_list, angles[j]*degree, lamb[i])['R']
            RNA[i,j] += inc_tmm('p',n_list, d_list, c_list, angles[j]*degree, lamb[i])['R']
	    #both polarisations, averaged 
    RNA = RNA/2
    
    RNAmean = numpy.mean(RNA, axis=1)    
    plt.figure(0)
    plt.plot(lamb,RNAmean,'blue', expx,expy,'purple')
    plt.xlabel('Wavelength (/nm)')
    plt.ylabel('Fraction reflected')
    plt.title('Simulated reflection of unpolarized light at 0$^\circ$ incidence (blue), '
                'Experimental data (purple)')
    plt.axis([400, 800, 0, 0.25])

# Save simulation data in a text file made out of columns delimited by a space
    
    numpy.savetxt("/users/Olimpia/Desktop/datafile1.txt", RNAmean, delimiter=" ")
示例#2
0
def sample1():

    # list of wavenumbers to plot in nm^-1

    lamb = linspace(400, 800, num=15)
    angles = linspace(0, 37, 8)

    RNA = numpy.zeros((lamb.size, angles.size))

    for i in range(lamb.size):
        print(lamb[i])
        for j in range(angles.size):
            RNA[i, j] = inc_tmm('s', n_list, d_list, c_list,
                                angles[j] * degree, lamb[i])['R']
            RNA[i, j] += inc_tmm('p', n_list, d_list, c_list,
                                 angles[j] * degree, lamb[i])['R']

#both polarisations, averaged
    RNA = RNA / 2

    RNAmean = numpy.mean(RNA, axis=1)
    plt.figure(0)
    plt.plot(lamb, RNAmean, 'blue', expx, expy, 'purple')
    plt.xlabel('Wavelength (/nm)')
    plt.ylabel('Fraction reflected')
    plt.title(
        'Simulated reflection of unpolarized light at 0$^\circ$ incidence (blue), '
        'Experimental data (purple)')
    plt.axis([400, 800, 0, 0.25])

    # Save simulation data in a text file made out of columns delimited by a space

    numpy.savetxt("/users/Olimpia/Desktop/datafile1.txt",
                  RNAmean,
                  delimiter=" ")
def reflectionsim(lamb, angles, n_list, d_list, c_list, N):

    RNA = np.zeros((lamb.size,angles.size))
    
    for i in range(lamb.size):
        for j in range(angles.size):
            RNA[i,j] = inc_tmm('s',n_list[i,:], d_list, c_list, angles[j]*degree, lamb[i])['R']
            RNA[i,j] += inc_tmm('p',n_list[i,:], d_list, c_list, angles[j]*degree, lamb[i])['R']
	    #both polarisations, averaged 
    RNA = RNA/2
    RNAmean = np.mean(RNA, axis=1)
    return RNAmean
示例#4
0
def reflectionsim(lamb, angles, n_list, d_list, c_list, N):

    RNA = np.zeros((lamb.size,angles.size))
    
    for i in range(lamb.size):
        for j in range(angles.size):
            RNA[i,j] = inc_tmm('s',n_list[i,:], d_list, c_list, angles[j]*degree, lamb[i])['R']
            RNA[i,j] += inc_tmm('p',n_list[i,:], d_list, c_list, angles[j]*degree, lamb[i])['R']
	    #both polarisations, averaged 
    RNA = RNA/2
    RNAmean = np.mean(RNA, axis=1)
    return RNAmean
示例#5
0
def sample1():

    # list of wavenumbers to plot in nm^-1

    ks = linspace(0.0025, .00125, num=800)

    # initialize lists of y-values to plot
    Rnorm = []
    R37 = []
    for k in ks:
        # For normal incidence, s and p polarizations are identical.

        # I arbitrarily decided to use 's'.
        Rnorm.append(inc_tmm('s', n_list, d_list, c_list, 0, 1 / k)['R'])
        #R37.append(unpolarized_RT(n_list, d_list, 37*degree, 1/k)['R'])
    kcm = ks * 1e7  #ks in cm^-1 rather than nm^-1
    lamb = 1 / ks
    plt.figure(0)
    plt.plot(lamb, Rnorm, 'blue', expx, expy, 'purple')
    plt.xlabel('Wavelength (/nm)')
    plt.ylabel('Fraction reflected')
    plt.title(
        'Simulated reflection of unpolarized light at 0$^\circ$ incidence (blue), '
        'Experimental data (purple)')
    plt.axis([400, 800, 0, 0.25])

    # Save simulation data in a text file made out of columns delimited by a space
    import numpy
    datafile_path = "/users/Olimpia/Desktop/datafile1.txt"
    datafile_id = open(datafile_path, 'w+')
    data = numpy.array([Rnorm])
    data = data.T
    numpy.savetxt(datafile_id, data, fmt=['%.4f'])
    datafile_id.close()
示例#6
0
文件: tests.py 项目: JoannaKG/tmm
def inc_overflow_test():
    """
    Test whether very very opaque layers will break the incoherent program
    """
    n_list = [1., 2., 1 + 3j, 4., 5.]
    d_list = [inf, 50, 1e5, 50, inf]
    c_list = ['i', 'i', 'i', 'i', 'i']
    lam = 200
    alpha_d = imag(n_list[2]) * 4 * pi * d_list[2] / lam
    print('Very opaque layer: Calculation should involve e^(-', alpha_d, ')!')
    data = inc_tmm('s', n_list, d_list, c_list, 0, lam)
    n_list2 = n_list[0:3]
    d_list2 = d_list[0:3]
    d_list2[-1] = inf
    c_list2 = c_list[0:3]
    data2 = inc_tmm('s', n_list2, d_list2, c_list2, 0, lam)
    print('First entries of the following two lists should agree:')
    print(data['power_entering_list'])
    print(data2['power_entering_list'])
示例#7
0
def angle(angle):
        
    # list of wavenumbers to plot in nm^-1
    
    ks=linspace(0.0025,.00125,num=800)
    
    # initialize lists of y-values to plot
    #NA of microscope is 0.60 => angle = 37deg
    for angle in range(0,38):
        globals()['R%s' % angle] = []

    for k in ks:
		# For normal incidence, s and p polarizations are identical.
		# I arbitrarily decided to use 's'.
	
        R0.append(inc_tmm('s',n_list, d_list, c_list, angle, 1/k)['R%s' %angle])
        
            
    kcm = ks * 1e7 #ks in cm^-1 rather than nm^-1
    lamb = 1/ks
    Rlist = []    
    Rlist = [R0,R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,R30,R31,R32,R33,R34,R35,R36,R37]
    RNA = []
    RNA = numpy.mean(Rlist, axis=0, dtype=numpy.float32)    
    plt.figure(0)
    plt.plot(lamb,RNA,'blue', expx,expy,'purple')
    plt.xlabel('Wavelength (/nm)')
    plt.ylabel('Fraction reflected')
    plt.title('Simulated reflection of unpolarized light at 0$^\circ$ incidence (blue), '
                'Experimental data (purple)')
    plt.axis([400, 800, 0, 0.25])

# Save simulation data in a text file made out of columns delimited by a space
    
    datafile_path = "/users/Olimpia/Desktop/datafile1.txt"
    datafile_id = open(datafile_path, 'w+')
    data = numpy.array([R0])
    data = data.T
    numpy.savetxt(datafile_id, data, fmt = ['%.4f'])
    datafile_id.close()
示例#8
0
文件: tests.py 项目: JoannaKG/tmm
def incoherent_test():
    """
    test inc_tmm(). To do: Add more tests.
    """
    print('The following should all be zero (within rounding errors):')

    #3-incoherent-layer test, real refractive indices (so that R and T are the
    #same in both directions)
    n0 = 1
    n1 = 2
    n2 = 3
    n_list = [n0, n1, n2]
    d_list = [inf, 567, inf]
    c_list = ['i', 'i', 'i']
    th0 = pi / 3
    th1 = snell(n0, n1, th0)
    th2 = snell(n0, n2, th0)
    lam_vac = 400

    for pol in ['s', 'p']:
        inc_data = inc_tmm(pol, n_list, d_list, c_list, th0, lam_vac)
        R0 = abs(interface_r(pol, n0, n1, th0, th1)**2)
        R1 = abs(interface_r(pol, n1, n2, th1, th2)**2)
        T0 = 1 - R0
        RR = R0 + R1 * T0**2 / (1 - R0 * R1)
        print(df(inc_data['R'], RR))
        print(df(inc_data['R'] + inc_data['T'], 1))

    #One finite layer with incoherent layers on both sides. Should agree with
    #coherent program
    n0 = 1 + 0.1j
    n1 = 2 + 0.2j
    n2 = 3 + 0.4j
    n_list = [n0, n1, n2]
    d_list = [inf, 100, inf]
    c_list = ['i', 'c', 'i']
    n00 = 1
    th00 = pi / 3
    th0 = snell(n00, n0, th00)
    lam_vac = 400
    for pol in ['s', 'p']:
        inc_data = inc_tmm(pol, n_list, d_list, c_list, th0, lam_vac)
        coh_data = coh_tmm(pol, n_list, d_list, th0, lam_vac)
        print(df(inc_data['R'], coh_data['R']))
        print(df(inc_data['T'], coh_data['T']))
        print(df(1, sum(inc_absorp_in_each_layer(inc_data))))

    #One finite layer with three incoherent layers. Should agree with
    #manual calculation + coherent program
    n0 = 1 + 0.1j
    n1 = 2 + 0.2j
    n2 = 3 + 0.004j
    n3 = 4 + 0.2j
    d1 = 100
    d2 = 10000
    n_list = [n0, n1, n2, n3]
    d_list = [inf, d1, d2, inf]
    c_list = ['i', 'c', 'i', 'i']
    n00 = 1
    th00 = pi / 3
    th0 = snell(n00, n0, th00)
    lam_vac = 400
    for pol in ['s', 'p']:
        inc_data = inc_tmm(pol, n_list, d_list, c_list, th0, lam_vac)
        coh_data = coh_tmm(pol, [n0, n1, n2], [inf, d1, inf], th0, lam_vac)
        th2 = snell(n0, n2, th0)
        th3 = snell(n0, n3, th0)
        coh_bdata = coh_tmm(pol, [n2, n1, n0], [inf, d1, inf], th2, lam_vac)
        R02 = coh_data['R']
        R20 = coh_bdata['R']
        T02 = coh_data['T']
        T20 = coh_bdata['T']
        P2 = exp(-4 * pi * d2 * (n2 * cos(th2)).imag /
                 lam_vac)  #fraction passing through
        R23 = interface_R(pol, n2, n3, th2, th3)
        T23 = interface_T(pol, n2, n3, th2, th3)
        #T = T02 * P2 * T23 + T02 * P2 * R23 * P2 * R20 * P2 * T23 + ...
        T = T02 * P2 * T23 / (1 - R23 * P2 * R20 * P2)
        #R = R02
        #    + T02 * P2 * R23 * P2 * T20
        #    + T02 * P2 * R23 * P2 * R20 * P2 * R23 * P2 * T20 + ...
        R = R02 + T02 * P2 * R23 * P2 * T20 / (1 - R20 * P2 * R23 * P2)
        print(df(inc_data['T'], T))
        print(df(inc_data['R'], R))

    #The coherent program with a thick but randomly-varying-thickness substrate
    #should agree with the incoherent program.
    nair = 1 + 0.1j
    nfilm = 2 + 0.2j
    nsub = 3
    nf = 3 + 0.4j
    n_list = [nair, nfilm, nsub, nf]
    n00 = 1
    th00 = pi / 3
    th0 = snell(n00, n0, th00)
    lam_vac = 400
    for pol in ['s', 'p']:
        d_list_inc = [inf, 100, 1, inf]  #sub thickness doesn't matter here
        c_list = ['i', 'c', 'i', 'i']
        inc_data = inc_tmm(pol, n_list, d_list_inc, c_list, th0, lam_vac)
        coh_Rs = []
        coh_Ts = []
        for dsub in np.linspace(10000, 30000, 357):
            d_list = [inf, 100, dsub, inf]
            coh_data = coh_tmm(pol, n_list, d_list, th0, lam_vac)
            coh_Rs.append(coh_data['R'])
            coh_Ts.append(coh_data['T'])
        print('Coherent with random thickness should agree with incoherent. ' +
              'Discrepency is: ' + str(df(average(coh_Rs), inc_data['R'])))
        print('Coherent with random thickness should agree with incoherent. ' +
              'Discrepency is: ' + str(df(average(coh_Ts), inc_data['T'])))
    #The coherent program with a thick substrate and randomly-varying wavelength
    #should agree with the incoherent program.
    n0 = 1 + 0.0j
    n_list = [n0, 2 + 0.0002j, 3 + 0.0001j, 3 + 0.4j]
    n00 = 1
    th00 = pi / 3
    th0 = snell(n00, n0, th00)
    d_list = [inf, 10000, 10200, inf]
    c_list = ['i', 'i', 'i', 'i']
    for pol in ['s', 'p']:
        inc_absorp = array([0., 0., 0., 0.])
        coh_absorp = array([0., 0., 0., 0.])
        num_pts = 234
        for lam_vac in np.linspace(40, 50, num_pts):
            inc_data = inc_tmm(pol, n_list, d_list, c_list, th0, lam_vac)
            inc_absorp += array(inc_absorp_in_each_layer(inc_data))
            coh_data = coh_tmm(pol, n_list, d_list, th0, lam_vac)
            coh_absorp += array(absorp_in_each_layer(coh_data))
        inc_absorp /= num_pts
        coh_absorp /= num_pts
        print(
            'Coherent with random wavelength should agree with incoherent. ' +
            'The two rows of this array should be the same:')
        print(vstack((inc_absorp, coh_absorp)))