Files
APLabs-Notebook/113.AtomicSpectroscopy/Untitled-1.ipynb
T
2026-10-02 11:10:29 +02:00

37 KiB
Executable File

Atomic Spectroscopy

Calibration of the Spectrometer

In [33]:
import pandas
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
from scipy.optimize import curve_fit

lambda_func = lambda x: 1/(x**2)

data = pandas.DataFrame({
    'l': [0.7065, 0.6678, 0.5876, 0.5048, 0.5016, 0.4922, 0.4713, 0.4471, 0.4388],
    '1/l^2': [lambda_func(x) for x in [0.7065, 0.6678, 0.5876, 0.5048, 0.5016, 0.4922, 0.4713, 0.4471, 0.4388]],
    's': [5.5, 6.3, 8.5, 12.1, 12.3, 12.9, 14.3, 16.3, 17.1],
    'ds': [0.2] * 9
    })

a, b, r_value, p_value, std_err = stats.linregress(data['1/l^2'], data['s'])

_, pcov = curve_fit(lambda x, a, b: a*x + b, data['1/l^2'], data['s'])
std_a, std_b = np.sqrt(np.diag(pcov))

plt.errorbar(data['1/l^2'], data['s'], yerr=data['ds'], fmt='o')
plt.plot(data['1/l^2'], a*data['1/l^2'] + b, label=f'Fit: s = {a:.2f} * (1/l^2) + {b:.2f}\nR² = {r_value**2:.4f}')
plt.grid()
plt.title('Scale division $s$ vs. Inverse of wavelength squared $1/l^2$')
plt.xlabel(r'Inverse of wavelength squared $\frac{1}{l^{2}}$ \mu m$^{-2}$')
plt.ylabel(r'Scale division $s$ (mm)')
plt.show()

print(data['1/l^2'])
0    2.003437
1    2.242369
2    2.896253
3    3.924292
4    3.974522
5    4.127782
6    4.501996
7    5.002541
8    5.193579
Name: 1/l^2, dtype: float64

Balmer series line: Hydrogen lamp

In [41]:
from math import sqrt

lamdb = lambda s: sqrt(a / (s - b)) * 1e-6
dlambda = lambda s, ds: (1e-6 / 2) * np.sqrt(a / (s - b)) * np.sqrt((std_a / a)**2 + (ds**2 + std_b**2) / (s - b)**2)
R_inf = lambda lam, m: (1/lam) * (1/2**2 - 1/m**2)**(-1) * 1e-6
dR_inf = lambda lam, dlam, m: sqrt((dlam/lam**2 * (1/2**2 - 1/m**2)**(-1) * 1e-6)**2)

data2 = pandas.DataFrame({
    'Colour': ['Red', 'Green', 'Blue'],
    'Scale Division': [6.5, 12.8, 13.3],
    'Uncertainty in Scale Division': [0.2, 0.2, 0.2],
    'lambda (um)': [lamdb(6.5)*1e6, lamdb(12.8)*1e6, lamdb(13.3)*1e6],
    'Uncertainty in lambda (um)': [dlambda(6.5, 0.2)*1e6, dlambda(12.8, 0.2)*1e6, dlambda(13.3, 0.2)*1e6],
    'm': [3, 4, 5],
    'R_inf (m^-1)': [R_inf(lamdb(6.5)*1e-6, 3), R_inf(lamdb(12.8)*1e-6, 4), R_inf(lamdb(13.3)*1e-6, 5)],
    'Uncertainty in R_inf (m^-1)': [dR_inf(lamdb(6.5)*1e-6, dlambda(6.5, 0.2)*1e-6, 3), dR_inf(lamdb(12.8)*1e-6, dlambda(12.8, 0.2)*1e-6, 4), dR_inf(lamdb(13.3)*1e-6, dlambda(13.3, 0.2)*1e-6, 5)]
})

for index, row in data2.iterrows():
    print(f"{row['Colour']} line: λ = {row['lambda (um)']:.2f} ± {row['Uncertainty in lambda (um)']:.2f} um, R_inf = {row['R_inf (m^-1)']:.6f} ± {row['Uncertainty in R_inf (m^-1)']:.6f} m^-1")
    
R_inf_mean = data2['R_inf (m^-1)'].mean()
R_inf_std = data2['R_inf (m^-1)'].std()
print(f"\nMean R_inf: {R_inf_mean:.6f} m^-1 \nStandard Deviation of R_inf: {R_inf_std:.6f} m^-1")
Red line: λ = 0.66 ± 0.01 um, R_inf = 10972121.627219 ± 198901.784729 m^-1
Green line: λ = 0.50 ± 0.01 um, R_inf = 10756601.022272 ± 127180.294680 m^-1
Blue line: λ = 0.49 ± 0.01 um, R_inf = 9766273.819141 ± 113001.920313 m^-1

Mean R_inf: 10498332.156211 m^-1 
Standard Deviation of R_inf: 643074.132153 m^-1
In [ ]: