Licencia Creative Commons
<span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">Python en ciencias e ingeniería: tutoriales basados en ejemplos</span> por <span xmlns:cc="http://creativecommons.org/ns#" property="cc:attributionName">Sergio Gutiérrez Rodrigo y Adrián Navas Montilla</span> se distribuye bajo una Licencia Creative Commons Atribución-NoComercial-CompartirIgual 4.0 Internacional.


Programa de Recursos en Abierto en la UZ (2022)

Python en ciencias e ingeniería: tutoriales basados en ejemplos

Universidad de Zaragoza

PRAUZ-739

Propiedades de scattering de una lámina dieléctrica (tratamiento error estadístico)


Funciones auxiliares (para pintar gráficos, etc.)

In [ ]:
def plot_figure(x,y,xlabel,ylabel,path,pngname,**kwargs):
    import matplotlib.pyplot as plt    
    #plt.style.use('ggplot') #('seaborn-whitegrid') 
    '''
    Función para dibujar funciones f=f(x)
    '''
    
    '''
    'seaborn-ticks', 'ggplot', 'dark_background', 'bmh', 'seaborn-poster', 
    'seaborn-notebook', 'fast', 'seaborn', 'classic', 'Solarize_Light2', 
    'seaborn-dark', 'seaborn-pastel', 'seaborn-muted', '_classic_test', 
    'seaborn-paper', 'seaborn-colorblind', 'seaborn-bright', 'seaborn-talk',
    'seaborn-dark-palette', 'tableau-colorblind10', 'seaborn-darkgrid', 
    'seaborn-whitegrid', 'fivethirtyeight', 'grayscale', 'seaborn-white', 'seaborn-deep']
    '''
    xmin=kwargs.get('xmin')
    xmax=kwargs.get('xmax')
    ymin=kwargs.get('ymin')
    ymax=kwargs.get('ymax')
    symbol_size=kwargs.get('symbol_size',0)
    line_width=kwargs.get('line_width',2)
    
    labels,colors,line = [],[],[]    
    colors = ["blue","green","red"]
    line = ["-","--","-"]
    labels = ["R","T","2"]    
    dpi=220; figy=2;figx=1.5*figy
    fig, ax = plt.subplots(num=None, dpi=dpi,figsize=(figx,figy), facecolor='w', edgecolor='k')    
    for i in range(0,len(y)):
        ax.plot(x[i],y[i], color=colors[i],ls=line[i], label=labels[i],
                marker='.',markersize=symbol_size,linewidth=line_width)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
    ax.set_xlim(xmin,xmax)
    ax.set_ylim(ymin,ymax)
    #ax.set_ylabel("Scattering coefficients")
    ax.legend(bbox_to_anchor=(0,1.02,1,0.2), loc="lower left",
                mode="expand", borderaxespad=0, ncol=2)
    ax.grid(b=None)
    fig.savefig(path+pngname+".png", dpi=dpi, facecolor="#f1f1f1")    
pass


def wavelength_to_rgb(wavelength, gamma=0.8):
    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.colors
    ''' taken from http://www.noah.org/wiki/Wavelength_to_RGB_in_Python
    This converts a given wavelength of light to an 
    approximate RGB color value. The wavelength must be given
    in nanometers in the range from 380 nm through 750 nm
    (789 THz through 400 THz).

    Based on code by Dan Bruton
    http://www.physics.sfasu.edu/astro/color/spectra.html
    Additionally alpha value set to 0.5 outside range
    '''
    wavelength = float(wavelength)
    if wavelength >= 380 and wavelength <= 750:
        A = 1.
    else:
        A=0.5
    if wavelength < 380:
        wavelength = 380.
    if wavelength >750:
        wavelength = 750.
    if wavelength >= 380 and wavelength <= 440:
        attenuation = 0.3 + 0.7 * (wavelength - 380) / (440 - 380)
        R = ((-(wavelength - 440) / (440 - 380)) * attenuation) ** gamma
        G = 0.0
        B = (1.0 * attenuation) ** gamma
    elif wavelength >= 440 and wavelength <= 490:
        R = 0.0
        G = ((wavelength - 440) / (490 - 440)) ** gamma
        B = 1.0
    elif wavelength >= 490 and wavelength <= 510:
        R = 0.0
        G = 1.0
        B = (-(wavelength - 510) / (510 - 490)) ** gamma
    elif wavelength >= 510 and wavelength <= 580:
        R = ((wavelength - 510) / (580 - 510)) ** gamma
        G = 1.0
        B = 0.0
    elif wavelength >= 580 and wavelength <= 645:
        R = 1.0
        G = (-(wavelength - 645) / (645 - 580)) ** gamma
        B = 0.0
    elif wavelength >= 645 and wavelength <= 750:
        attenuation = 0.3 + 0.7 * (750 - wavelength) / (750 - 645)
        R = (1.0 * attenuation) ** gamma
        G = 0.0
        B = 0.0
    else:
        R = 0.0
        G = 0.0
        B = 0.0
    return (R,G,B,A)

def plot_figure_rgb(wavelengths,R,T,xlabel,ylabel,path,pngname,**kwargs):    
    import matplotlib
    import matplotlib.pyplot as plt 

    fig, ax = plt.subplots(2, 1, figsize=(4,8), tight_layout=True) 

    ax[0].plot(wavelengths, R, color='darkred',label="Reflexión")
    ax[1].plot(wavelengths, T, color='darkblue',label="Transmisión")
    
    ax[0].fill_between(wavelengths, 1, R, color='w')
    ax[1].fill_between(wavelengths, T, 1, color='w')

    clim=(350,780)
    norm = plt.Normalize(*clim)
    wl = np.arange(clim[0],clim[1]+1,2)
    colorlist = list(zip(norm(wl),[wavelength_to_rgb(w) for w in wl]))
    spectralmap = matplotlib.colors.LinearSegmentedColormap.from_list("spectrum", colorlist)  

    y = np.linspace(0, 1, 100)
    X,Y = np.meshgrid(wavelengths, y)

    extent=(np.min(wavelengths), np.max(wavelengths), np.min(y), np.max(y))
    for i in range(0,2):
      ax[i].imshow(X, clim=clim,  extent=extent, cmap=spectralmap, aspect='auto')
      ax[i].set_xlabel(xlabel)
      ax[i].set_ylabel(ylabel)
      ax[i].legend(bbox_to_anchor=(0,1.02,1,0.2), loc="lower left",
                      mode="expand", borderaxespad=0, ncol=2)

    fig.savefig(path+pngname+".png", dpi=220, facecolor="#f1f1f1")  
    plt.show()
    pass

Reflexión y transmisión en INCIDENCIA NORMAL a través de una lámina delgada de espesor $h$ dieléctrico con índice de refracción $n$, sobre un sustrato con índice de refracción $n_{sustrato}$

In [ ]:
def Ref(lon_onda,n_capa,h_capa,n_sustrato):    
    import numpy as np
    from math import pi
    '''
    Calcula la reflexión en una lámina dieléctrica con índice de refracción
    n_capa situada sobre un sustrato (n_sustrato) y cuyo espesor es h_capa
    '''
    ci=1j
    A = 2.0*pi*n_capa*h_capa/lon_onda    
    contraste=n_sustrato/n_capa
    reflc=(np.cos(A)+ci*contraste*np.sin(A) - n_sustrato*np.cos(A)-ci*n_capa*np.sin(A))/ \
          (np.cos(A)+ci*contraste*np.sin(A) + n_sustrato*np.cos(A)+ci*n_capa*np.sin(A)) 			    
    reflc=np.real(np.conjugate(reflc)*reflc)    
    return np.abs(reflc)

print(Ref(1500.0,2.25,50.0,1.0))

import sys
print(sys.executable)
print(sys.version)
print(sys.version_info)
0.1438202961181632
/usr/bin/python3
3.7.13 (default, Apr 24 2022, 01:04:09) 
[GCC 7.5.0]
sys.version_info(major=3, minor=7, micro=13, releaselevel='final', serial=0)

Parámetros geométricos, materiales e inicialización de variables

In [ ]:
'''
Parámetros comunes del problema.
Las magnitudes con unidades de longitud son siempre 
en nanómetros, sino se dice otra cosa.
'''
resolucion=500 # Resulución espectral, número de longitudes de onda
lon_onda_ini=380.0 
lon_onda_fin=780.0
n_capa=1.16
n_sustrato=3.97+0.030209j
h_capa=1000.0 #nm

Pintamos la reflexión y la transmisión (I)

In [ ]:
'''
Ejemplo de cálculo de reflexión y transmisión
'''
import numpy as np
from math import pi
lon_onda=np.linspace(lon_onda_ini,lon_onda_fin,resolucion)
R=Ref(lon_onda,n_capa,h_capa,n_sustrato)

'''
Pintamos la reflexión
'''
xplot,yplot = [],[]
xplot.append(lon_onda)
xplot.append(lon_onda)
yplot.append(R)
yplot.append(1.0-R)

plot_figure(xplot,yplot,xlabel='$\lambda$(nm)',ylabel='Reflexión/Transmisión',path='./',
            pngname='lamina_dielectrica_delgada',xmin=lon_onda_ini,xmax=lon_onda_fin,ymin=0.0,ymax=1.0)

Pintamos la reflexión y la transmisión (II)

In [ ]:
'''
Para el mismo ejemplo anterior, este código permite graficar la T y la R
incluyendo información visual sobre el color en función de la longitud de onda
'''
wavelengths = np.linspace(lon_onda_ini, lon_onda_fin, 1000)
R = Ref(wavelengths,n_capa,h_capa,n_sustrato) 
T = 1.0 -R

plot_figure_rgb(wavelengths,R,T,xlabel='$\lambda$(nm)',ylabel='Reflexión/Transmisión',path='./',
            pngname='lamina_dielectrica_delgada',R_plot=True,T_plot=True)
/usr/local/lib/python3.7/dist-packages/IPython/core/pylabtools.py:125: UserWarning: Tight layout not applied. The left and right margins cannot be made large enough to accommodate all axes decorations. 
  fig.canvas.print_figure(bytes_io, **kw)

Calculamos la reflexión para una longitud de onda en el vacío dada y una determinada anchura con ruido estadístico (gaussiano)

In [ ]:
lambda_0 = 475.0 #nm
print(Ref(lambda_0,n_capa,h_capa,n_sustrato))

mu, sigma = h_capa, 5.0 # media y desviación estándar de nuestras medidas
no_medidas=100
h = np.random.normal(mu, sigma, no_medidas)
y=np.linspace(min(h),max(h),len(h))
R_anchura=Ref(lambda_0,n_capa,h,n_sustrato)

'''
Se pinta el resultado
'''
xplot,yplot = [],[]
xplot.append(y)
yplot.append(R_anchura)

plot_figure(xplot,yplot,xlabel='anchura lámina (nm)',ylabel='Reflexión, $\lambda$='+str(lambda_0),path='./',
            pngname='lamina_dielectrica_delgada',ymin=-0.01,ymax=max((R_anchura)*1.2),line_width=0,symbol_size=3)
1.132023669304248e-31

Distribución estadística de una muestra

In [ ]:
print(mu,sigma)

print("Comprobación distribución normal")
print(abs(mu - np.mean(h)))
print(abs(sigma - np.std(h,ddof=1))) # ddof=1 para Varianza (dividir por n-1) Ver https://numpy.org/doc/stable/reference/generated/numpy.std.html

# Histograma y distribución normal asociada
import matplotlib.pyplot as plt
count, bins, ignored = plt.hist(h,30,density=False)
density = count / (sum(count) * np.diff(bins))
plt.plot(bins, (max(count)/max(density))/(sigma * np.sqrt(2 * np.pi)) *
               np.exp( - (bins - mu)**2 / (2 * sigma**2) ),
         linewidth=4, color='k')
plt.vlines(h_capa,0,max(count),colors='r')
plt.xlabel('Muestra - anchura lámina (nm)')
plt.show()
500.0 5.0
Comprobación distribución normal
0.2805846982287221
0.4671705434587201

Distribución muestral de la media aritmética (media de las medias y error cuadrático medio asociado)

In [ ]:
import matplotlib.pyplot as plt
from math import sqrt

no_medidas=10
N_muestras=1000 # Para llegar al Teorema del límite central N_muestras grande
s,mean_of_means=[],[]
for _ in range(0,N_muestras):
  h = np.random.normal(mu, sigma, no_medidas)
  mean_of_means.append(np.mean(h))  

# Verificaciones
print("Comprobación distribución normal")
mu_mu=abs(np.mean(mean_of_means))
print("Media de la población=",mu,"Media de las medias=",mu_mu)
print("Media de todas las muestras=",mean_of_means)
sigma_x=abs(np.std(mean_of_means,ddof=1))
print(" Sigma de la población=",sigma,"Sigma_x=",sigma_x,"; Sigma de la población/sqrt(no_medidas)=",sigma/sqrt(no_medidas))


# Histograma y distribución normal asociada
s=mean_of_means
count, bins, ignored = plt.hist(s,30,density=False)
density = count / (sum(count) * np.diff(bins))
plt.plot(bins, (max(count)/max(density))/(sigma_x * np.sqrt(2 * np.pi)) *
               np.exp( - (bins - mu_mu)**2 / (2 * sigma_x**2) ),
         linewidth=2, color='g')
plt.vlines(h_capa,0,max(count),colors='r')
plt.xlabel('Media de las medias - anchura lámina (nm)')
plt.show()
Comprobación distribución normal
Media de la población= 500.0 Media de las medias= 500.0527228841089
Media de todas las muestras= [500.22080736844293, 499.45885356039344, 498.12215994421206, 502.0309782384118, 501.98541489588087, 500.50444307676355, 499.7446726973311, 500.3482863130531, 500.9235800647475, 500.84917558816505, 501.737991096479, 500.4046077732943, 499.7286134715374, 500.48676329709133, 500.8925917098788, 500.25459011897465, 499.14114900125094, 500.233417802709, 500.5520416108284, 500.4786642108763, 501.5990588806825, 497.2667183539055, 498.1571450801474, 499.2942564684181, 500.9368648247907, 499.8003841016322, 500.3372730018876, 498.198965127354, 500.2248844824858, 502.25210570722845, 498.95038662613814, 499.2888435305798, 501.0768029861365, 499.8987516468895, 500.85815014822026, 501.0293101394679, 498.28323318686154, 503.32211425723307, 502.93922332629955, 498.21559183359125, 497.38536889292965, 503.0371670681799, 500.5812504131251, 500.17975305488955, 501.31959594423927, 499.0005359667057, 497.8403836849784, 501.84188159299055, 498.30673416941727, 498.5254167915882, 500.9932521147799, 500.03028000138255, 499.12909167835835, 502.0015655764185, 498.5004234887795, 501.3491416462942, 502.4761139394201, 499.0973246169574, 499.8123855328963, 501.27118348668535, 499.66418620312413, 499.3631436263232, 500.8262633144876, 501.7564697144505, 503.3585732529885, 497.3484429518879, 501.98930107864106, 499.81920837164006, 499.9666240948533, 499.8146577009039, 499.83986533095396, 500.07721666523383, 501.37698179795916, 502.71067429880225, 500.19567034954946, 499.3933430370538, 497.46905460339815, 500.8103876062999, 502.19328833252194, 500.9964771630296, 501.1215180552008, 497.86750635451943, 500.48473927638497, 502.0251537467637, 498.78688894873204, 501.27716265179413, 500.578877704391, 502.9772081465573, 503.70585974725, 500.40723311937506, 499.30848530167907, 501.35515004556225, 501.9247779112923, 498.6933044140063, 498.3537498334537, 501.5692732697947, 498.2400582662584, 499.39190876315024, 499.2931065691587, 498.5130818303104, 502.7821160986273, 501.25321660774614, 500.2507712564561, 498.78170091846204, 503.7170621670637, 502.6697623353333, 501.0878661838009, 501.82641566342136, 499.60440635718396, 500.9822176435984, 500.3100637153002, 499.7876800226906, 500.752333145774, 497.9578895880919, 500.7085249233792, 500.01804511556827, 502.1215179075515, 497.07229511064725, 499.4569854048251, 499.569281289772, 500.086090880916, 501.69017080081164, 499.62447881667094, 503.2761623627487, 499.29217316379174, 498.4783691337474, 502.38312910267996, 499.96235653469137, 499.655578849137, 499.42487082597546, 498.87756135796747, 502.4164077928996, 502.48660830860297, 500.2800651585011, 500.2729743976917, 500.13286344700253, 499.3992730387478, 495.57168684444304, 498.9911180941277, 499.50913847271715, 500.02944399173623, 499.46410826525073, 501.76473558349437, 499.5706779384226, 500.4791782943363, 502.06269348278454, 498.8494085900371, 501.89495140346787, 498.8033721944189, 500.18730798705684, 498.5411482312552, 498.8868888752697, 500.803864109655, 500.1522287026661, 500.8725814672065, 497.94363116108815, 501.5396854769366, 500.14279780764844, 501.2699439070701, 497.9257911865545, 501.881391042279, 501.80633069130755, 498.6400562500985, 501.6408516959838, 502.3303487510203, 499.42686837919484, 500.8609692425765, 502.4497580178251, 500.638309451573, 501.896561124681, 502.32050230318436, 499.7434295403614, 498.4312071401702, 500.0271666014689, 502.34796215183314, 499.83455168289646, 499.9520833084622, 500.57659631869336, 500.90398963335804, 500.536197065319, 499.92067576441616, 501.20319435041284, 498.70230851052213, 500.226434371323, 499.02792966043353, 501.39935779703364, 501.3782698611004, 500.76312677227133, 497.40363619837245, 497.7194788829086, 499.95969745602554, 499.7902373288349, 499.8008429942015, 500.4356310846389, 499.5087695322113, 500.290328609986, 501.2048530310187, 502.25962202448227, 501.56568705188863, 497.16720600924634, 499.09809777570973, 500.5249357966528, 501.5505462917632, 502.26329353913934, 498.1598959126606, 499.8389512726666, 499.0461537349168, 498.775819467891, 497.5672974552619, 498.39234660585515, 501.1165542497417, 501.02112885744884, 499.4780579442389, 500.6499183158306, 499.7018325353841, 501.5775491664746, 499.4101194093303, 499.2231366872423, 500.7746155199078, 499.87516942757236, 497.30242756072255, 499.54932246368696, 500.3071285202817, 500.2519005931346, 498.6652920250701, 497.47555066091934, 501.35925146232694, 498.75404789200076, 498.4167432423727, 501.6757861292296, 499.04326915716894, 500.1230637697815, 502.5817688234133, 499.45235282968116, 501.9138358885101, 502.00320164606376, 498.3740026860067, 500.1955090223499, 500.0909747005685, 500.15550675204975, 499.4511857410075, 497.4592414159467, 499.32753665725215, 499.5576363277094, 500.0046067742734, 500.1097644977411, 499.60453419547264, 499.6036667496105, 501.1180773641425, 500.41079755378877, 499.7312645126258, 500.0332478634867, 501.357670370693, 499.1348662211661, 499.303783441153, 499.986048983455, 499.48925048253375, 500.9364740689055, 500.5910361547458, 503.19042886948273, 497.8431673703338, 497.69653479665686, 500.03922409947256, 500.20008638036296, 501.1274628436319, 501.62696700570376, 500.81460911602517, 502.46555659970034, 501.14130059854153, 501.18399468349025, 498.80964817413553, 501.68863937060934, 499.07305628320125, 498.70790983387826, 500.47287308650795, 501.3390589731668, 503.18365853187277, 498.7694668440148, 497.2319137977828, 500.2975641559695, 499.12600379474605, 499.81176119858327, 502.6617137589692, 499.39887049834533, 500.8255235265616, 501.2505830940422, 497.747050493275, 501.71956808025715, 501.47530866823826, 499.79062126213086, 500.7183729879316, 500.21612683585624, 498.03005255276105, 498.98607945784306, 499.81045871833913, 497.71563922127996, 497.38757923947276, 500.8699783935505, 498.87080990335863, 502.3456241640159, 498.74224123783927, 499.36143285613554, 502.10367026181484, 498.91515012715246, 499.12034319292036, 498.3367500055093, 502.6371296355366, 499.90094091466256, 497.91805464226064, 501.8618978481601, 497.24663167970823, 499.40608193348896, 497.76853658339314, 499.4792502874492, 498.0561354512118, 501.30621067316326, 498.17559347360884, 502.53768091569026, 499.25520006764816, 499.30800530067444, 500.21587846600715, 501.060634578749, 498.55425419265094, 501.1453185528144, 500.47758188700027, 501.56813434906553, 498.64066813104057, 502.3581995543433, 500.22837312470864, 500.5022163856244, 496.017867485681, 499.5651590930671, 500.9317789936029, 502.94388565425106, 500.7500135024992, 499.3271820650624, 498.424872674815, 499.00738654431063, 500.2267414985172, 499.015262084739, 500.0710384450417, 496.9317951547047, 498.9503324369828, 498.0748384548083, 500.87776994870217, 500.3870321312485, 502.0367540018834, 498.47838423770844, 501.4736163783858, 497.1631781855801, 502.8241465958993, 499.9782369842093, 500.4516265816575, 500.3152678907396, 498.7419733037571, 502.2323094116779, 500.3471405641687, 499.6430115724764, 499.00902165494654, 503.98826875411135, 501.4043048416962, 500.33405657803615, 498.20439919773355, 502.66593724345176, 500.121404901496, 502.0683120330189, 501.243502175654, 500.7956266598353, 499.577557344944, 498.2609073665717, 498.60736773145754, 500.0173818285192, 498.69887614481956, 498.6556955069662, 499.56125892737253, 500.8653478054347, 500.388298366219, 500.0854804068398, 499.79534598067676, 497.7002378860201, 498.0683862961723, 499.41126610964375, 500.3449967083123, 502.1283322977426, 500.3262789208592, 504.2461278866339, 498.3251953364097, 497.53922352655735, 499.43137917601246, 499.2237847772682, 502.5178961452307, 498.9123702451475, 499.88131176650734, 504.1480247990673, 496.88704976922617, 499.30533723675336, 501.93000272708434, 498.44009123464286, 499.07009518606503, 501.1264888319347, 500.28234548792614, 498.3980863147811, 498.49366242169236, 499.3023372191527, 500.2803075478798, 500.36976566338944, 500.4930986547053, 498.3730139059671, 503.32913491603887, 501.55654116152647, 499.01410318354465, 498.04608362383505, 498.66371489555456, 497.67147538505003, 499.6959205457306, 502.9760774574067, 499.9514699262033, 498.6027037630385, 502.98562921208713, 497.0943300461489, 500.2007975200825, 502.257251396163, 497.1125049311624, 500.2150261897601, 498.866360607155, 499.5716553222927, 497.7001659706617, 501.0288284733335, 497.9488428713254, 503.32613981454034, 498.8433527596858, 499.8969895766648, 501.24396955478744, 501.1205645362872, 498.4954944691055, 497.2653308793814, 501.9704537308642, 500.6747103236281, 499.6987343018019, 501.5840061003787, 496.73388735156766, 500.98059493898126, 501.18142204603964, 498.17977737923036, 502.57389664172297, 502.08205629045153, 499.5604374352649, 499.24635112194994, 501.65465493675447, 499.2224874708928, 498.0921974333105, 497.12341460159587, 502.4104652406364, 498.310144238854, 498.59995741323394, 501.02370463451297, 500.3433246923108, 498.2550314964681, 500.94201119513417, 500.3233768672553, 501.969279308158, 500.12958263403755, 501.279584696954, 497.36411963914964, 500.3683082043829, 501.50018943928416, 499.8367896730189, 500.1807487026434, 499.0564722103246, 498.3290462007503, 500.99580945626866, 498.9193693512907, 499.11453100077716, 497.7767139497296, 498.43084545841094, 497.8466941826312, 500.1665776930593, 503.2850837121426, 498.23016097859306, 498.84275534140363, 501.82510623952777, 498.8238483617417, 500.24201526073045, 501.2035552371156, 499.5422636452803, 500.40598015851646, 501.1572709447863, 499.36849847467175, 499.22776511976343, 497.2709682247829, 498.70489136912965, 500.4113923774888, 503.01537604887335, 498.91459926924483, 499.2775701122643, 500.1973640854009, 499.4217242432522, 500.15163763334715, 501.3555899844021, 501.69363972168924, 501.02989124829963, 499.4649508412176, 498.5571173100178, 500.65340929554793, 501.7419224406246, 499.3441188480371, 498.9660223409295, 501.12753821166746, 498.93722617981393, 498.5976218204984, 500.0624031705728, 498.80083353956627, 499.5898896296975, 498.6113850721652, 499.81229441148287, 501.07207212587065, 499.248429073711, 499.70496302357924, 499.9156457766441, 500.01087670239815, 500.5446941906222, 498.555414518201, 498.6330821492813, 500.4629517112774, 502.7924333972602, 501.5383615656383, 496.7630609948475, 500.3999834894461, 498.8489854522768, 499.6880269527227, 498.3813569926527, 501.2912239996279, 498.84446821065404, 497.7449273983672, 498.102911907222, 500.3024822764851, 500.4775928572317, 501.34006207332715, 500.6722427690652, 500.0571654072679, 499.1175294377493, 500.3095766764004, 503.48580454225265, 498.40633531783067, 500.76280706980594, 503.1156554840274, 498.9493015128288, 500.0488222243566, 498.223783679412, 498.77309563463933, 500.1788752141094, 500.6512168333511, 501.2519645847934, 498.3092108216505, 500.89454876096096, 503.0011818299173, 501.433254060228, 500.85849639228337, 497.1830252170677, 495.99565380170316, 499.20970513039117, 499.6132967724176, 499.68637108512223, 500.02972469390517, 499.2149308613216, 503.29803021316155, 501.3040205772879, 502.2520610433752, 502.3610557166179, 499.6456272900431, 501.3841673593166, 497.0949559842791, 499.1811415264939, 501.0341012698236, 499.49827756698795, 499.0575387503419, 499.0362242147113, 503.1689112113281, 502.9413019728183, 499.51789835099305, 499.9306081429962, 500.57064314096306, 499.44939366758007, 498.6720975725351, 500.6190376923895, 501.7582026859278, 502.95325266410146, 500.3130292987495, 499.9897789843999, 500.38810404771465, 500.0879302022896, 501.22138662800364, 501.1477099595689, 498.43394207104757, 497.20034302383874, 500.0473296095787, 498.23899267844183, 499.09544472243726, 499.1033660722211, 499.652380944315, 502.0783433277953, 502.47918311871535, 503.2932152028981, 500.89470786116306, 498.82121205414535, 500.21119819121003, 500.63341982080493, 499.7747197196289, 500.97208740683243, 501.85197845604614, 500.3071601421455, 498.5708328093974, 500.0756585091523, 501.7057920518447, 500.9786535736106, 500.31429002611975, 497.91413713974316, 497.7006026259006, 498.29885640076066, 499.72879120578483, 501.136182912279, 498.9797246549384, 498.19853695884797, 500.6411075488697, 502.46860815545585, 498.62854246338236, 499.64027614770146, 499.24444848124296, 501.4955066691017, 500.5487797804367, 498.55656317334876, 502.4584169209561, 500.8081976964751, 500.1495212028009, 498.79068906596405, 498.5014773012487, 501.9349969621714, 500.51170579255466, 496.47180553636963, 500.1618455503112, 499.52198504321785, 501.15787475886236, 499.17011445179253, 498.64967196714076, 499.5911799757402, 501.57399047035705, 503.59631464528127, 499.4666380233531, 501.06431386074576, 500.2987317525698, 500.03519328864394, 501.5042729643301, 501.34995055139154, 501.63154840926137, 500.6325159160988, 500.8701877969928, 499.95115571994546, 501.2291436631808, 499.0752793308478, 500.00109385956796, 499.3920720371524, 502.7789490807371, 503.88679484195364, 500.4159669474378, 499.44617592076327, 505.8475960867412, 501.1202161558981, 501.3489099183248, 499.9566804880562, 500.20191255290837, 502.07570295894027, 501.2163283937456, 504.5071451669088, 497.8326330253203, 500.74452634794636, 500.266234056769, 499.9425574082905, 498.64282270066644, 498.4756462850517, 496.3069309935483, 499.39737994060135, 499.79336618434775, 500.20460438758465, 500.2848548225261, 499.26367444915394, 500.0751622177314, 498.8186579616233, 501.4199727922681, 497.3302736458646, 499.8245107495294, 501.3920143937897, 501.58050701479044, 499.2715682509132, 497.96717117005346, 499.3289536416699, 499.50791625472175, 501.79871685143564, 499.6874278865228, 499.7438388427011, 499.69229630540883, 499.7278704222798, 500.6617408725224, 500.05261608348036, 497.2434834584975, 502.44371031881985, 499.6198901628378, 499.9457238397149, 498.97888930904526, 494.97429176498963, 499.11540016316246, 501.74723396760544, 499.02902004348033, 496.96121988206886, 501.2817112407032, 499.7565894840915, 500.411848103172, 501.7738529915364, 499.2917893031451, 500.0848129202007, 499.3200086736222, 503.10558445408395, 503.48858336130087, 498.70255112944477, 503.0009162558167, 501.854347142542, 502.23805116137953, 499.3491025507457, 499.8242218805839, 498.52408119339714, 497.61189435351696, 499.9160136229655, 498.3918214849732, 500.72888366261725, 499.4474581389053, 501.7105962024183, 500.9176773742577, 502.5377664622573, 497.5535801671391, 499.2195472358293, 498.9515317989773, 500.15112968713566, 499.8658184967524, 498.8674303117756, 501.1807148540221, 499.6061037124109, 501.0046791304064, 500.54868484158317, 499.39420328144615, 499.0381902584544, 499.2711249452535, 501.5653695869469, 502.70889526575513, 502.6619957522724, 499.300265323071, 501.54224518747185, 501.0942565042211, 497.61375159846057, 501.77894816182726, 497.4135098476201, 501.0613155068971, 498.7826418617774, 503.37942420682674, 501.5425047363933, 499.30883815597656, 500.63252766159997, 501.7988782203206, 499.8768622771763, 497.48469553045527, 499.3861654156446, 501.97061136400015, 502.1752107332669, 498.0123247571466, 498.366202100102, 498.4916411823093, 500.9631180911565, 500.2070546115289, 497.68749028039895, 501.7130931527739, 499.8615958983335, 496.6000716760726, 498.2882368655581, 499.4624100083336, 501.6456792877434, 501.4672044220109, 501.4039272224304, 498.32906119567997, 496.2961592721125, 500.0610472291681, 500.9604369338407, 501.4487925488205, 499.84657994111785, 500.1741940942972, 501.8060376068687, 499.22846182156974, 500.0002498920223, 499.36141121117714, 498.14527709306674, 501.2623339477392, 500.57557101508235, 499.774680394875, 500.24621950417503, 500.91598633457045, 499.28690117285515, 498.7782301846779, 501.7152961455072, 499.85762241356025, 498.7613718543704, 498.91455910422627, 498.6045114130914, 501.9891458742697, 499.6214442157822, 500.893983166981, 498.23642054624406, 499.3639170408036, 499.7271697715388, 499.4221521885127, 499.04898046905225, 501.420313400528, 499.67141694665526, 500.0553874877619, 497.65967836266964, 499.2218755088935, 501.80610637953794, 498.7007550995039, 497.4737710314027, 497.4619994619952, 502.2055345067203, 501.06285903357565, 502.07545095340976, 502.03012443080235, 499.0435226285621, 499.89983273531, 499.73831262260757, 501.1030445952806, 497.29516219322613, 499.3908239816025, 496.85475342976014, 497.90804375300274, 501.46407008419357, 499.10151273872015, 498.6773649107789, 497.8270145872986, 501.9925882441018, 501.08860573647314, 501.2131228438532, 502.3007235761538, 503.82399952166713, 498.6554322753608, 499.4116588465037, 501.08435825564703, 497.747297163017, 500.3746350114878, 501.71299588465183, 498.611789358836, 500.5249193393555, 499.38560230809145, 499.32062826475504, 498.7249836336426, 501.24812710314734, 498.9857661046234, 498.34712465399525, 501.75082064718947, 500.5718330285987, 499.1678338620062, 499.5365417447829, 501.79726483746117, 499.8214170834891, 495.68860648807265, 501.2625982349471, 497.42945349755234, 499.8029643199534, 500.6837005627567, 499.3992664842731, 499.6942373414466, 499.3047357280851, 501.1414547835695, 499.7398368082337, 501.03207220407904, 499.2767365146834, 499.46506693271147, 498.03179528408475, 499.74684339120967, 499.24407424051435, 501.3753256912217, 498.7418580760729, 497.4761929237907, 500.9119605994003, 500.79714982858934, 501.200541076823, 500.3704078019188, 497.26572203182275, 498.52350057550166, 500.36685758357896, 496.86992574381213, 499.18168246747183, 502.22788566294787, 501.7918163969527, 500.12938162181547, 498.8596545080139, 497.7349203481391, 500.1822992227438, 499.45637632824673, 503.5243682230838, 500.4514471088145, 499.1599010846021, 500.97983693411135, 499.95632911338816, 500.4822378364603, 500.10939351848265, 501.3979938914625, 499.9392989276682, 499.1592559127674, 499.8603633770896, 502.60142711840416, 501.51860652262667, 501.7053215447933, 499.8716831680754, 498.9627443192313, 498.51873928862176, 501.68862827537333, 499.0325506791384, 498.70090387799627, 499.7993049057307, 500.905885554781, 499.1201573701634, 502.37192855870296, 500.7679832203154, 501.01063036736497, 498.7708724985785, 503.0345318717283, 502.43944013022235, 501.89777505578456, 499.057400401837, 499.6695780317782, 499.93913285225733, 498.1333513962355, 500.27661001852204, 497.34356007470103, 501.321376634414, 501.0855883942566, 500.9144421357083, 501.44990845403316, 498.5521270559545, 497.2101325748723, 499.78184842619777, 499.8470236933901, 500.5321119805418, 501.113130175045, 499.8806194338749, 499.8108476674496, 497.48525902337735, 500.1844355598215, 498.023640515016, 500.7554703275629, 500.1535155678813, 501.4507540272668, 499.41346857255905, 499.9725360856055, 499.4906704246956, 497.32397483108355, 501.07872708423685, 497.0433579740478, 501.07170383610264, 500.2715027683964, 500.292243825864, 499.4220537779091, 500.792977213934, 503.092981461716, 501.0328831379373, 500.5900272965952, 501.0254195360206, 499.34991206055736, 499.3430969276834, 500.11913125373957, 495.7872087645504, 500.5510937805877, 497.41175889664936, 501.48575688135145, 499.25862595432454, 499.9928369100304, 501.3408718481454, 499.7317897599419, 501.7360947844892, 498.61750588890425, 500.2806022158744, 500.8507557751333, 500.5813804701979, 497.93497303016477, 496.8807035761748, 500.79195823636366, 503.1022616646027, 500.3404684809565, 496.78782500177186, 501.0610744617742, 501.427543087646, 499.77619560972016, 501.21035178588227, 498.53782249598333, 500.7633933275106, 501.02551969620924]
 Sigma de la población= 5.0 Sigma_x= 1.5518141923439985 ; Sigma de la población/sqrt(no_medidas)= 1.5811388300841895

Ajuste mínimos cuadrados

In [ ]:
import random

lambda_0 = 600.0 #nm
print(Ref(lambda_0,n_capa,h_capa,n_sustrato))
'''
mu, sigma = h_capa, 5.0 # media y desviación estándar de nuestras medidas
no_medidas=100
h = np.random.normal(mu, sigma, no_medidas)
y=np.linspace(min(h),max(h),len(h))
R_anchura=Ref(lambda_0,n_capa,h,n_sustrato)
'''
std_h=1.5
R_anchura = [Ref(lambda_0,n_capa,random.gauss(h,std_h),n_sustrato) for h in range(int(h_capa)-10,int(h_capa)+10)]
x=np.linspace(int(h_capa)-100,int(h_capa)+100,len(R_anchura))

'''
Mínimos cuadrados
'''
a,b=np.polyfit(x,R_anchura,1)
print("a,b=",a,',',b)
R_anchura_min=a*x+b
print(R_anchura)
'''
Se pinta el resultado
'''
xplot,yplot = [],[]
xplot.append(x)
xplot.append(x)
yplot.append(R_anchura)
yplot.append(R_anchura_min)

plot_figure(xplot,yplot,xlabel='anchura lámina (nm)',ylabel='Reflexión, $\lambda$='+str(lambda_0),path='./',
            pngname='lamina_dielectrica_delgada',line_width=1,symbol_size=3)
0.10549602692184423
a,b= 0.0006111576841620394 , -0.20527394373971516
[0.04029694572055799, 0.055098573903597056, 0.05295065857722898, 0.060283836493347454, 0.05142033204954698, 0.07114177152276514, 0.07261616166688423, 0.0731869443819809, 0.10748768938641953, 0.10378937885715762, 0.10712906306616983, 0.09205631880424592, 0.12113363435817465, 0.12074428167942133, 0.12119528706027435, 0.13642430718862145, 0.15356876356316831, 0.1496455707335638, 0.16322208408866035, 0.15270636372430318]

Reflexión en INCIDENCIA OBLICUA en la interfase entre dos medios con índices de refracción $n_1$ y $n_2$. Se incide desde el medio $1$.

In [ ]:
from math import pi
import numpy as np

def A_f(theta):
  return np.cos(theta)

def B_f(theta,n1,n2): 
  return np.sqrt(1.0-(n1*np.sin(theta)/n2)**2)

def Rs(theta,n1,n2):
  A=A_f(theta)  
  B=B_f(theta,n1,n2)  
  return np.abs((n1*A-n2*B)/(n1*A+n2*B))**2

def Rp(theta,n1,n2):  
  A=A_f(theta)
  B=B_f(theta,n1,n2)
  return np.abs((n1*B-n2*A)/(n1*B+n2*A))**2
In [ ]:
n1=1.0 # Región de incidencia
n2=3.0 # Región de transmisión

wavelengths = np.linspace(lon_onda_ini, lon_onda_fin, 1000)
R = Rs(0.0,n1,n2)*np.ones(shape=wavelengths.shape)
T = 1.0 -R

plot_figure_rgb(wavelengths,R,T,xlabel='$\lambda$(nm)',ylabel='Reflexión/Transmisión',path='./',
            pngname='incidencia_oblicua_longitud_onda')

angles = np.linspace(0, pi/2.0,90)
R = Rp(angles,n1,n2)
T = 1.0 -R
angles_plot=angles*360.0/(2.0*pi)
plot_figure_rgb(angles_plot,R,T,xlabel='$\Theta_{incidente}$ (deg)',ylabel='Reflexión/Transmisión (polarización p)',path='./',
            pngname='incidencia_oblicua_angulo')

brewster=np.arctan(n2/n1)*360.0/(2.0*pi)
print("Ángulo de Brewster (deg)=",brewster)
print(brewster/90.0)

print("Rp=",Rp(brewster*2.0*pi/360.0,n1,n2))
print("Rs=",Rs(brewster*2.0*pi/360.0,n1,n2))

R = Rs(angles,n1,n2)
T = 1.0 -R
plot_figure_rgb(angles_plot,R,T,xlabel='$\Theta_{incidente}$ (deg)',ylabel='Reflexión/Transmisión (polarización s)',path='./',
            pngname='incidencia_oblicua_angulo')
/usr/local/lib/python3.7/dist-packages/IPython/core/pylabtools.py:125: UserWarning: Tight layout not applied. The left and right margins cannot be made large enough to accommodate all axes decorations. 
  fig.canvas.print_figure(bytes_io, **kw)
/usr/local/lib/python3.7/dist-packages/IPython/core/pylabtools.py:125: UserWarning: Tight layout not applied. The left and right margins cannot be made large enough to accommodate all axes decorations. 
  fig.canvas.print_figure(bytes_io, **kw)
Ángulo de Brewster (deg)= 71.56505117707799
0.7951672353008665
Rp= 0.0
Rs= 0.6399999999999999
/usr/local/lib/python3.7/dist-packages/IPython/core/pylabtools.py:125: UserWarning: Tight layout not applied. The left and right margins cannot be made large enough to accommodate all axes decorations. 
  fig.canvas.print_figure(bytes_io, **kw)