<jupyter_start><jupyter_text>refellips demo: Solid/AirThis demo presents a comparison between refellips and WVASE outputs as well as an example use case for fitting single-wavelength multi-angle ellipsometry data with refellips.<jupyter_code>%matplotlib inline
%load_ext autoreload
%autoreload 2
import sys
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import glob
from refnx.analysis import CurveFitter
from refnx.reflect import Slab
from refellips.dataSE import DataSE, open_EP4file
from refellips.reflect_modelSE import ReflectModelSE
from refellips.objectiveSE import ObjectiveSE
from refellips.structureSE import RI<jupyter_output><empty_output><jupyter_text>Import data<jupyter_code>#Ellipsomsetry data to model using refellips
dname = 'testData1_11nm_PNIPAM_on_Si_EP4.dat'
data = DataSE(data=dname)

#Ellipsometry data modelled in WVASE
WVASE_test = pd.read_csv(open('WVASE_example_2nmSiO2_11nmPNIPAM_658nm.txt','r'))<jupyter_output><empty_output><jupyter_text>Build model<jupyter_code>si     = RI('../materials/silicon.csv')
sio2   = RI('../materials/silica.csv')
PNIPAM = RI('../materials/pnipam.csv')
air    = RI('../materials/air.csv')

polymer_layer = PNIPAM(150)
polymer_layer.name = 'PNIPAM'
polymer_layer.thick.setp(vary=True, bounds=(100,500))

silica_layer = sio2(20)
silica_layer.name = 'Silica'
silica_layer.thick.setp(vary=False, bounds=(1, 60))

struc = air(np.inf) | polymer_layer | silica_layer | si(np.inf)

model = ReflectModelSE(struc, wavelength=658)

model.DeltaOffset.setp(value=0, vary=False, bounds=(-10,10))<jupyter_output><empty_output><jupyter_text>Comparison of refellips and WVASE outputs for a 2 nm SiO$_2$ and 15 nm PNIPAM system<jupyter_code>fig, ax = plt.subplots()
axt = ax.twinx()

aois = np.linspace(50,75,100)
psi, delta = model(aois)

ax.plot(WVASE_test['Angle of Incidence'], WVASE_test['Psi'],ls='--', color='k', zorder=5, label='wvase')
axt.plot(WVASE_test['Angle of Incidence'], WVASE_test['Delta'],ls='--', color='k', zorder=5)

ax.plot(aois, psi, color='r', label='refellips')
axt.plot(aois, delta, color='r')

ax.legend(frameon=False)
ax.set(ylabel='Psi', xlabel='AOI (°)')
axt.set(ylabel='Delta')
plt.show()<jupyter_output><empty_output><jupyter_text>Fitting experimental data  Model & data pre fit<jupyter_code>fig, ax = plt.subplots()
axt = ax.twinx()

aois = np.linspace(50,75,100)
psi, delta = model(aois)
ax.plot(aois, psi, color='r')
p = ax.scatter(data.aoi, data.psi, color='r')

axt.plot(aois, delta, color='b')
d = axt.scatter(data.aoi, data.delta, color='b')

ax.legend(handles=[p,d], labels=['Psi', 'Delta'])
ax.set(ylabel='Psi', xlabel='AOI, °')
axt.set(ylabel='Delta')
plt.show()
objective = ObjectiveSE(model, data)
fitter = CurveFitter(objective)
fitter.fit(method='differential_evolution');<jupyter_output>10it [00:00, 87.14it/s]<jupyter_text>Model & data post fit<jupyter_code>fig, ax = plt.subplots()
axt = ax.twinx()

aois = np.linspace(50,75,100)
psi, delta = model(aois)
ax.plot(aois, psi, color='r')
p = ax.scatter(data.aoi, data.psi, color='r')

axt.plot(aois, delta, color='b')
d = axt.scatter(data.aoi, data.delta, color='b')

ax.legend(handles=[p,d], labels=['Psi', 'Delta'])
ax.set(ylabel='Psi', xlabel='AOI, °')
axt.set(ylabel='Delta')
plt.show()
for i, x in enumerate(objective.model.parameters):
    print(x)<jupyter_output>________________________________________________________________________________
Parameters: 'instrument parameters'
<Parameter: 'wavelength'  , value=658 (fixed)  , bounds=[-inf, inf]>
<Parameter:'delta offset' , value=0 (fixed)  , bounds=[-10.0, 10.0]>
________________________________________________________________________________
Parameters: 'Structure - ' 
________________________________________________________________________________
Parameters:      'air'     
<Parameter: 'air - thick' , value=inf (fixed)  , bounds=[-inf, inf]>
<Parameter: 'air - rough' , value=0 (fixed)  , bounds=[-inf, inf]>
<Parameter:'air - volfrac solvent', value=0 (fixed)  , bounds=[0.0, 1.0]>
________________________________________________________________________________
Parameters:    'PNIPAM'    
<Parameter:'pnipam - thick', value=111.826 +/- 0.492, bounds=[100.0, 500.0]>
<Parameter:'pnipam - rough', value=0 (fixed)  , bounds=[-inf, inf]>
<Parameter:'pnipam - volfrac solvent', value=0 (fixed)  , bound[...]
{'fraction_non_alphanumeric': 0.15366919714745803, 'fraction_numerical': 0.025304807913503567, 'mean_word_length': 6.8483754512635375, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '412664', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1570, 'n_words': 319, 'path': 'demos/refellipsDemo.ipynb', 'repo_name': 'haydenrob/refellips', 'size': '4347'}