summaryrefslogtreecommitdiff
path: root/tutorials/module_4/spectroscopy_problem/spectroscopy.py
diff options
context:
space:
mode:
Diffstat (limited to 'tutorials/module_4/spectroscopy_problem/spectroscopy.py')
-rw-r--r--tutorials/module_4/spectroscopy_problem/spectroscopy.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/tutorials/module_4/spectroscopy_problem/spectroscopy.py b/tutorials/module_4/spectroscopy_problem/spectroscopy.py
index 404e5ca..1ef6579 100644
--- a/tutorials/module_4/spectroscopy_problem/spectroscopy.py
+++ b/tutorials/module_4/spectroscopy_problem/spectroscopy.py
@@ -15,7 +15,7 @@ Problem:
- Interpolate and convert x-axis from pixels to nm (true wavelength) using Hg lamp data (using data in file: **Lampa_Calibrare_Mercur.xlsx**)
- Find response function of the spectrometer using the tungsten lamp data from file: "**Calibrare Intensitate Oxigen.xlsx**)": $R=\frac{I_{measured}}{I_{true}}$ (where True is computed by Planck's law of radiation (see notes in the pptx above)
- Convert y-axis from Intensity [a.u.] into Intensity in [W/(cm^2*sr*nm)] by dividing the measured Oxygen spectrum with the response function: $I_{oxygen, true}=\frac{I_{oxygen, measured}}{R}$
-- Once the spectra is in real units: compute the density of one of the oxygen lines by integrating underneath one of the peaks (see equation from Slide 39 - bottom). We will give all of the constants that are in this equation (see the "I**ntensity_Calibration_Oxygen_Discharge_Solution.xlsx**")
+- Once the spectra is in real units: compute the density of one of the oxygen lines by integrating underneath one of the peaks (see equation from Slide 39 - bottom). We will give all of the constants that are in this equation (see the "Intensity_Calibration_Oxygen_Discharge_Solution.xlsx")
"""
import numpy as np
@@ -118,7 +118,7 @@ I_Ox_measured = df_Ox['I_Plasma Oxygen [a.u.]']-df_Ox['I_Background [a.u.]']
I_Ox_true = R * I_Ox_measured
-# Plot Hg intensity-wavelength plot
+# Plot Hg spectra [a.u.] plot
plt.figure(figsize=(8,5))
plt.plot(wavelength, I_Ox_measured, linestyle='-')
plt.xlabel('Wavelength [$nm$]')
@@ -128,7 +128,7 @@ plt.title('Wavelength-Intensity ($Ox_{measured}$)')
plt.grid(True)
plt.show()
-# Plot Hg intensity-wavelength plot
+# Plot Hg spectra real units plot
plt.figure(figsize=(8,5))
plt.plot(wavelength, I_Ox_true, linestyle='-')
plt.xlabel('Wavelength [$nm$]')
@@ -141,17 +141,24 @@ plt.show()
# %% Calculate Dencity of Ox at upper state
-from scipy.interpolate import interp1d
-from scipy.integrate import quad
+from scipy.integrate import simpson
-# Create an interpolated callable function
-I_Ox_true = interp1d(wavelength, I_Ox_true, kind='linear',
- fill_value=0, bounds_error=False)
+I_Ox_true = I_Ox_true.to_numpy()
-# Now integrate
+# Integrate numerator
delta = 1
peak = 846.5
bound_lower = peak - delta
bound_upper = peak + delta
-numerator, err = quad(I_Ox_true, bound_lower, bound_upper)
+mask = (wavelength >= bound_lower) & (wavelength <= bound_upper)
+wavelength_trimmed = wavelength[mask]
+I_Ox_trimmed = I_Ox_true[mask]
+numerator = simpson(I_Ox_trimmed, wavelength_trimmed)
+
+v = c/(peak*10**(-9))
+A = 3.6e6 # 1/s
+l = 0.015 # m
+
+n = numerator / (1/(4*np.pi)*h*v*A*l)
+