Package: ratter
ratterratteris a python tool to calculate the optical response -- most importantlyReflection andTransmission -- of a stack of layers of different materials. For this is uses the fresnel formalae and transfer matrix calculations.It provides classes to define a stack of materials, while giving all, some or no numeric values. Withratteryou can calculate the optical properties of this
stack as numerical values or as functions - formulae or algorithms. With the power ofnumpyandsympy,rattergives numeric and symbolic calculations as a mixture and allows you to jump between the two freely.If you give all values that are necessary to calculate the reflectance of a stack,ratterwill just calculate and return that value. If you leave numerical values unset and give a symbol instead, for example adas the thickness of an interlayer,ratterwill return the reflection as a sympy formula with free symbold. This formula can then be turned into an algorithmic function withdas an argument. This function will be a numpy function and vectorized, such that it can be applied to an array ofd's. This enables fast numeric calculations of the dependencies of the optical properties of a stack from any free parameter.Example 1: general symbolic calculationsIn a stack of multiple layers, the two outer layers are considered infinite half-spaces.fromratterimport*# define three materialsm1=Material('1')m2=Material('2')m3=Material('3')# define three layersl1=Layer('l1',m1)l2=Layer('l2',m2)l3=Layer('l3',m3)# define the order of the layersstack=Layerstack([l1,l2,l3])# calculate the (complex) reflectance amplituder=stack.reflectance_amplitude().simplify()stack.transmittance_amplitude().simplify()Example 2: numeric calculation of a double layer coatingfromratterimport*fromsympyimportconjugatewavelength=600# length units: nm# define materials with their refractive index at the wavelengthSi=Material('Si',refractive_index_value=3.9400+0.019934j)# Green 2008air=Material('air',refractive_index_value=1.00027698)# Ciddor 1996SiO2=Material('SiO2',refractive_index_value=1.4580)# Malitson 1965AlOx=Material('Al2O3',refractive_index_value=1.7675)# Malitson and Dodge 1972# define the layersenvironment=Layer('env',air)coating1=Layer('coat1',SiO2)coating2=Layer('coat2',AlOx)bulk=Layer('bulk',Si)# define the order of materialsstack=Layerstack([environment,coating1,coating2,bulk])# calculate absolute reflectivity Rr=stack.reflectance_amplitude()R=conjugate(r)*r# substitute symbols with numbersR_=R.subs(LAMBDA_VAC,wavelength)# create a vectorized numpy function out of symbolic definitionR_of_coating_thickness=as_function_of(R_,[coating1.thickness_symbol,coating2.thickness_symbol])Plotusing the fast vectorized functionimportnumpyasnpimportmatplotlib.pyplotaspltd1=np.arange(0,500)ford2in[50,200,500]:reflectivity_values=np.real(R_of_coating_thickness(d1,d2))plt.plot(d1,reflectivity_values,label='{}'.format(d2))plt.legend(title='$Al_2O_3$ thickness (nm)')plt.ylabel('reflectivity')plt.xlabel('$SiO_2$ thickness (nm)')Installationratteris written for Python 3, tested in Python 3.7. It depends onnumpyandsympy. To run the tests, you will also needscipyandtmm.To install usepippip install ratterTheoretical backgroundThe theory behind the formulae used byratterare the Fresnel Formulae.ratterassumes incoming light as a plane wave, described by its complex field amplitude and phase. The interaction with a material layer leads to a change in phase and amplitude (dependent on the refractive index of the material), which can be expressed as a transfer matrix. The consecutive propagation through the layers can be described as a consecutive application of the matrices. Thus a stack of layers can be described as one single transfer matrix.rattercalculates that matrix symbolically usingsympy.For a detailed description, I recommend the explanations of Steven J. Byrnes:arXiv:1603.02720 [physics.comp-ph]LimitationsAs of now,ratterdoes not support an angle of incidence other than 0, meaning perfectly normal incidence. It does not consider polarization at all.It does not support incoherent light and thus gives unrealistic results for thick layers which do not maintain coherence.The calculation of spatially resolved absorption is also not included.All of these above can and hopefully will be implemented in future versions.Similar toolsIf it is required to numerically calculate the reflectance, absorption or transmission, other python tools give very complete solutions:tmmOpenTMMPyTMMratteris tested to give the same results astmm.