lab-II/optics/interf.py
2018-03-18 18:02:21 +01:00

149 lines
3.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding: utf-8
from __future__ import division, print_function, unicode_literals
from lab import *
import uncertainties.umath as um
import uncertainties.unumpy as unp
import numpy as np
import matplotlib.pyplot as plt
# convert micrometer readings to SI unit
length = lambda x,y,z: x*1e-4 + y*1/4*1e-4 + z*1e-6
##
## Part I
##
k = 60 # number of wavefronts
l0 = ufloat(633, 1)*1e-9 # laser wavelength
# micrometer calibration
d0 = k*l0/2 # expected value
d = length(0,3,10) # measured value
df = d - d0 # offset
# laser wavelength measure
d = sample(length(*i)-df.n for i in [(0,3,9.5), (0,3,10),
(0,3,10.5), (0,3,10)]).tval()
l1 = 2*d/k
print(mformat('''
# Part I (Fabry-Perot interferometer)
offset: {} μm
λ: {} nm
''', df*1e6, l1*1e9))
##
## Part II
##
df = length(2,0,1) # micrometer offset
k = 70 # number of wavefronts
# laser wavelength measure
d = sample(length(*i)-df for i in [(2,0,22.5), (2,0,23.5), (2,0,23.5),
(2,0,23.5), (2,0,23), (2,0,23)]).tval()
l2 = 2*d/k
print(mformat('''
# Part II (Michelson interferometer)
λ: {} nm''', l2*1e9))
## compare wavelengths
alpha = check_measures(l1, l2)
l = combine_measures(l1, l2)
print(mformat('''
comparibility test λ₁ - λ₂
α={:.2f} α>ε: {}
λbest: {} nm
''', alpha, alpha>epsilon, l*1e9))
##
## Part III
##
d = 3e-2 # air cavity thickness
Patm = 101.3e3 # atmosferic pressure
k = array(17, 20, 17, 18, 19) # number of wavefronts
P = array(82e3, 83e3, 84e3, 83e3, 84e3) # gauge pressure
m = sample(*(k*l.n/(2*d*P)))
print(mformat('''
# Part III (air refraction index)
m: {} Pa⁻¹
''', m.tval()))
##
## Part IV
##
d = ufloat(6, 1)*1e-3 # glass pane thickness
t = ufloat(12, 1)*np.pi/180 # angle
k = sample(162, 112, 124, 122).tval() # number of wavefronts
n = (2*d-k*l) / (2*d-k*l/(1-um.cos(t))) # refraction index
print(mformat('''
# Part IV (glass refraction index)
n: {}
''', n))
##
## Part V
##
# peak position
S = array(8.9, 10.7, 11.7, 12.7, 13.4,
14.1, 14.7, 15.6, 16.3, 16.7,
17.3, 18.0, 18.3, 18.9)*1e-2
# uncertainty
sigmaS = 2e-3
# peak number
n = np.arange(1, len(S))
d = ufloat(1e-3, 0) # slit length
L = ufloat(125.1, 0.5)*1e-2 # screen distance
ti = um.atan(S[0]/L) # incidence angle
# drop first peak
S = S[1:]
x = np.linspace(0, 13, 200)
peak = lambda n, t, l: L.n*np.sqrt(1/(np.cos(t)-n*l/d.n)**2 - 1)
f, (tio, lo) = curve(n, S, peak, sigmaS, guess=[ti.n, l.n])
plt.xlabel('peak order')
plt.ylabel('distance from center (m)')
plt.errorbar(n, S, sigmaS, color='#604848', linestyle='', linewidth=1.1)
plt.scatter(n, S, color='#a17e3e')
plt.plot(x, f(x), color='#65788f')
plt.show()
alpha = check_measures(l, lo)
beta = chi_squared_fit(n, S, f, sigmaS)
print(mformat('''
# Part V (ruler diffraction)
λₒ: {} nm
θₒ: {} rad
compatibility test λ - λₒ:
α={:.2f}, α>ε: {}
χ² test:
α={:.2f}, α>ε: {}
''', lo*1e9, tio
, alpha, alpha>epsilon
, beta, beta>epsilon))