Initial Commit
This commit is contained in:
parent
c46f17029d
commit
374fc24f04
11 changed files with 674 additions and 0 deletions
46
Examples/P_q_vs_a_p.py
Normal file
46
Examples/P_q_vs_a_p.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
"""
|
||||
Plots Mie and Rayleigh form factors at varying particle radii.
|
||||
"""
|
||||
|
||||
from scattering import *
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Default Scattering Parameters
|
||||
n_p = 2.0 # particle refractive index
|
||||
n_s = 1.332 # medium refractive index (water)
|
||||
lambda_vac = 685e-9 # wavelength of light in vacuum [meters]
|
||||
phi = 0.03 # particle volume fraction
|
||||
n_ang = 100 # number of sampled angles
|
||||
|
||||
a_p_range = [50e-9, 100e-9, 250e-9, 500e-9, 1000e-9] # particle radii [meters]
|
||||
p_q = np.empty(shape=(n_ang, np.size(a_p_range), 2)) # initialize result array
|
||||
|
||||
# Collect Scattering Data
|
||||
for i in range(np.size(a_p_range)):
|
||||
_, _, _, _, [q, p_q[:, i, 0], _, _, _, _, _, _] = \
|
||||
mie_scattering(n_p, n_s, a_p_range[i], lambda_vac, phi, n_ang=n_ang, struct='PY')
|
||||
_, _, _, _, [_, p_q[:, i, 1], _, _] = \
|
||||
rayleigh_scattering(n_p, n_s, a_p_range[i], lambda_vac, phi, n_ang=n_ang)
|
||||
|
||||
# Generate Colors
|
||||
colormap = plt.get_cmap('plasma')
|
||||
c = np.empty(shape=(np.size(a_p_range), 3))
|
||||
for i in range(np.size(a_p_range)):
|
||||
c[i, :] = colormap.colors[round(256 * i / np.size(a_p_range))]
|
||||
|
||||
# Plot
|
||||
fig, ax1 = plt.subplots()
|
||||
for i in range(np.size(a_p_range)):
|
||||
if i == 0:
|
||||
ax1.plot(q, p_q[:, i, 0] / p_q[0, i, 0], label=r'Mie, $a_p$ = %i nm' % (a_p_range[i] * 1e9), c=c[i])
|
||||
ax1.plot(q, p_q[:, i, 1] / p_q[0, i, 1], linestyle='--',
|
||||
label=r'Rayleigh, $a_p$ = %i nm' % (a_p_range[i] * 1e9), c=c[i])
|
||||
else:
|
||||
ax1.plot(q, p_q[:, i, 0] / p_q[0, i, 0], label=r'$a_p$ = %i nm' % (a_p_range[i] * 1e9), c=c[i])
|
||||
ax1.plot(q, p_q[:, i, 1] / p_q[0, i, 1], linestyle='--', c=c[i])
|
||||
ax1.set(xlabel='q', ylabel='Normalized P(q)', title=r'$n_p$ = %.3f, $n_s$ = %.3f, $\lambda$ = %i nm, $\phi$ = %.2f' % (n_p, n_s, lambda_vac*1e9, phi))
|
||||
ax1.legend(loc='upper right')
|
||||
ax1.set(ylim=[-0.05, 1.1])
|
||||
plt.show()
|
||||
|
||||
BIN
Examples/Results/Intensity Plot.png
Normal file
BIN
Examples/Results/Intensity Plot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 109 KiB |
BIN
Examples/Results/Mie vs Rayleigh l_star.png
Normal file
BIN
Examples/Results/Mie vs Rayleigh l_star.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
BIN
Examples/Results/P(q) vs a_p.png
Normal file
BIN
Examples/Results/P(q) vs a_p.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 74 KiB |
BIN
Examples/Results/S(q) Models.png
Normal file
BIN
Examples/Results/S(q) Models.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
BIN
Examples/Results/Silica Fit.png
Normal file
BIN
Examples/Results/Silica Fit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
38
Examples/S_q_models.py
Normal file
38
Examples/S_q_models.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
"""
|
||||
Plots various structure factor models.
|
||||
"""
|
||||
|
||||
from scattering import *
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Default Scattering Parameters
|
||||
a_p = 200e-9 # meters
|
||||
n_p = 1.5 # particle refractive index
|
||||
n_s = 1.332 # medium refractive index (water)
|
||||
lambda_vac = 685e-9 # wavelength of light in vacuum [meters]
|
||||
phi = 0.03 # particle volume fraction
|
||||
n_ang = 100 # number of sampled angles
|
||||
|
||||
s_q = np.empty(shape=(n_ang, 3)) # initialize result array
|
||||
|
||||
# Collect Scattering Data
|
||||
_, _, _, _, [q, _, s_q[:, 0], _, _, _, _, _] = mie_scattering(n_p, n_s, a_p, lambda_vac, phi, n_ang=n_ang,
|
||||
struct='PY')
|
||||
_, _, _, _, [_, _, s_q[:, 1], _, _, _, _, _] = mie_scattering(n_p, n_s, a_p, lambda_vac, phi, n_ang=n_ang,
|
||||
struct='PYAnnulus', optional_params=[1.2*a_p])
|
||||
_, _, _, _, [_, _, s_q[:, 2], _, _, _, _, _] = mie_scattering(n_p, n_s, a_p, lambda_vac, phi, n_ang=n_ang,
|
||||
struct='SHS', optional_params=[0.2, 0.05])
|
||||
|
||||
# Plot
|
||||
fig, ax1 = plt.subplots()
|
||||
ax1.plot(q, np.ones_like(s_q[:, 0]), 'k', label='No Interaction', linewidth=2)
|
||||
ax1.plot(q, s_q[:, 0], 'k-.', label='Hard Sphere', linewidth=2)
|
||||
ax1.plot(q, s_q[:, 1], 'k:', label='1.2$a_p$ Excluded Annulus', linewidth=2)
|
||||
ax1.plot(q, s_q[:, 2], 'k--', label='Sticky Hard Sphere', linewidth=2)
|
||||
ax1.set(xlabel=r'$q$', ylabel='S(q)',
|
||||
title=r'$n_p$ = %.3f, $n_s$ = %.3f, $a_p$ = %i nm, $\lambda$ = %i nm, $\phi$ = %.2f'
|
||||
% (n_p, n_s, a_p*1e9, lambda_vac*1e9, phi))
|
||||
ax1.legend()
|
||||
|
||||
plt.show()
|
||||
56
Examples/intensity_plot.py
Normal file
56
Examples/intensity_plot.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
"""
|
||||
Plots Mie intensities and form factor versus scattering angle.
|
||||
"""
|
||||
|
||||
from scattering import *
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Default Scattering Parameters
|
||||
a_p = 500e-9 # # particle radius [meters]
|
||||
n_p = 1.5 # particle refractive index
|
||||
n_s = 1.0 # medium refractive index
|
||||
lambda_vac = 685e-9 # wavelength of light in vacuum [meters]
|
||||
phi = 0.03 # particle volume fraction
|
||||
n_ang = 100 # number of sampled angles
|
||||
|
||||
# Collect Data
|
||||
theta, i1, i2, _, _ \
|
||||
= mie_scattering(n_p, n_s, a_p, lambda_vac, phi)
|
||||
_, i1r, i2r, _, _ \
|
||||
= rayleigh_scattering(n_p, n_s, a_p, lambda_vac, phi)
|
||||
theta = np.append(theta, np.pi + theta)
|
||||
i1 = np.append(i1, i1[::-1])
|
||||
i2 = np.append(i2, i2[::-1])
|
||||
i1r = np.append(i1r, i1r[::-1])
|
||||
i2r = np.append(i2r, i2r[::-1])
|
||||
|
||||
# Generate Colors
|
||||
n_colors = 3
|
||||
colormap = plt.get_cmap('plasma')
|
||||
c = np.empty(shape=(n_colors, 3))
|
||||
for i in range(n_colors):
|
||||
c[i, :] = colormap.colors[round(256 * i / n_colors)]
|
||||
|
||||
# Plot
|
||||
fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw=dict(projection='polar'))
|
||||
ax1.plot(theta, i1, label='Perpendicular Mie', c=c[0])
|
||||
ax1.plot(theta, i2, label='Parallel Mie', c=c[2])
|
||||
ax1.plot(theta, 0.5*(i1+i2), label='Mie P(q)', c=c[1])
|
||||
# ax1.plot(theta, i1r, label='Perpendicular Rayleigh', c=c[0], linestyle='--')
|
||||
# ax1.plot(theta, i2r, label='Parallel Rayleigh', c=c[2], linestyle='--')
|
||||
# ax1.plot(theta, 0.5*(i1r+i2r), label='Rayleigh P(q)', c=c[1], linestyle='--')
|
||||
ax1.set_title("Intensity")
|
||||
ax1.legend()
|
||||
|
||||
ax2.plot(theta, np.log10(i1 + 1), label='Perpendicular Mie', c=c[0])
|
||||
ax2.plot(theta, np.log10(i2 + 1), label='Parallel Mie', c=c[2])
|
||||
ax2.plot(theta, np.log10(0.5*(i1+i2) + 1), label='Mie P(q)', c=c[1])
|
||||
# ax2.plot(theta, np.log10(i1r + 1), label='Perpendicular Rayleigh', c=c[0], linestyle='--')
|
||||
# ax2.plot(theta, np.log10(i2r + 1), label='Parallel Rayleigh', c=c[2], linestyle='--')
|
||||
# ax2.plot(theta, np.log10(0.5*(i1r+i2r) + 1), label='Rayleigh P(q)', c=c[1], linestyle='--')
|
||||
ax2.set_title("Log Intensity")
|
||||
ax2.legend()
|
||||
|
||||
plt.suptitle(r'$n_p$ = %.3f, $n_s$ = %.3f, $a_p$ = %i nm, $\lambda$ = %i nm, $\phi$ = %.2f'
|
||||
% (n_p, n_s, a_p*1e9, lambda_vac*1e9, phi))
|
||||
plt.show()
|
||||
58
Examples/mie_vs_rayleigh.py
Normal file
58
Examples/mie_vs_rayleigh.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
"""
|
||||
Plots l* for varying input parameters for both Mie and Rayleigh scattering.
|
||||
"""
|
||||
|
||||
from scattering import *
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Default Scattering Parameters
|
||||
n_p = 1.8 # particle refractive index
|
||||
n_s = 1.332 # medium refractive index (water)
|
||||
a_p = 250e-9 # particle radii [meters]
|
||||
lambda_vac = 685e-9 # wavelength of light in vacuum [meters]
|
||||
phi = 0.03 # particle volume fraction
|
||||
|
||||
# Generate Parameter Ranges
|
||||
n_range = 100 # number of data points between values
|
||||
phi_range = np.linspace(0.01, 0.15, n_range)
|
||||
a_p_range = np.linspace(150e-9/2, 1000e-9/2, n_range)
|
||||
n_p_range = np.linspace(1.6, 2, n_range)
|
||||
|
||||
# Initialize Result Array
|
||||
l_star = np.empty(shape=(n_range, 3, 2))
|
||||
|
||||
# Collect Scattering Data
|
||||
for i in range(n_range):
|
||||
_, _, _, l_star[i, 0, 0], _ \
|
||||
= mie_scattering(n_p, n_s, a_p, lambda_vac, phi_range[i])
|
||||
_, _, _, l_star[i, 1, 0], _ \
|
||||
= mie_scattering(n_p, n_s, a_p_range[i], lambda_vac, phi)
|
||||
_, _, _, l_star[i, 2, 0], _ \
|
||||
= mie_scattering(n_p_range[i], n_s, a_p, lambda_vac, phi)
|
||||
|
||||
_, _, _, l_star[i, 0, 1], _ \
|
||||
= rayleigh_scattering(n_p, n_s, a_p, lambda_vac, phi_range[i])
|
||||
_, _, _, l_star[i, 1, 1], _ \
|
||||
= rayleigh_scattering(n_p, n_s, a_p_range[i], lambda_vac, phi)
|
||||
_, _, _, l_star[i, 2, 1], _ \
|
||||
= rayleigh_scattering(n_p_range[i], n_s, a_p, lambda_vac, phi)
|
||||
|
||||
# Plot Data
|
||||
fig, (ax1, ax2, ax3) = plt.subplots(1, 3)
|
||||
ax1.plot(phi_range, l_star[:, 0, 0]*1e6, 'k', label='Mie', linewidth=2)
|
||||
ax1.plot(phi_range, l_star[:, 0, 1]*1e6, 'k--', label='Rayleigh', linewidth=2)
|
||||
ax1.legend()
|
||||
ax1.set(xlabel=r'$\phi$', ylabel='l* [µm]')
|
||||
|
||||
ax2.plot(a_p_range*1e9, l_star[:, 1, 0]*1e6, 'k', label='Mie', linewidth=2)
|
||||
ax2.plot(a_p_range*1e9, l_star[:, 1, 1]*1e6, 'k--', label='Rayleigh', linewidth=2)
|
||||
ax2.set(xlabel=r'$a_p$ [nm]')
|
||||
|
||||
ax3.plot(n_p_range, l_star[:, 2, 0]*1e6, 'k', label='Mie', linewidth=2)
|
||||
ax3.plot(n_p_range, l_star[:, 2, 1]*1e6, 'k--', label='Rayleigh', linewidth=2)
|
||||
ax3.set(xlabel=r'$n_p$')
|
||||
|
||||
# title with default parameters listed
|
||||
plt.suptitle(r'$n_p$ = %.3f, $n_s$ = %.3f, $a_p$ = %i nm, $\lambda$ = %i nm, $\phi$ = %.2f' % (n_p, n_s, a_p*1e9, lambda_vac*1e9, phi))
|
||||
plt.show()
|
||||
55
Examples/silica_data_fit.py
Normal file
55
Examples/silica_data_fit.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
"""
|
||||
Generates l* values versus particle volume concentration for silica particles with varying form factor models.
|
||||
Plots model versus experimental data (courtesy of Qi Li).
|
||||
"""
|
||||
|
||||
from scattering import *
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Scattering Parameters
|
||||
n_p = 1.446 # particle refractive index (silica)
|
||||
n_s = 1.332 # medium refractive index (water)
|
||||
a_p = 345e-9/2 # particle radii [meters]
|
||||
lambda_vac = 685e-9 # wavelength of light in vacuum [meters]
|
||||
|
||||
# Generate Parameter Range
|
||||
n_range = 100 # number of data points between values
|
||||
phi_range = np.linspace(0.03, 0.15, n_range)
|
||||
|
||||
# Initialize Result Array
|
||||
l_star_phi = np.empty(shape=(n_range, 4))
|
||||
|
||||
# Silica Data (courtesy of Qi Li)
|
||||
silica_data = np.array([[0.065, 0.067, 0.069, 0.072, 0.075, 0.135],
|
||||
[0.000230, 0.000225, 0.000216, 0.000215, 0.000205, 0.000130]])
|
||||
|
||||
# Collect Scattering Data
|
||||
for i in range(n_range):
|
||||
_, _, _, l_star_phi[i, 0], _ \
|
||||
= mie_scattering(n_p, n_s, a_p, lambda_vac, phi_range[i])
|
||||
_, _, _, l_star_phi[i, 1], _ \
|
||||
= mie_scattering(n_p, n_s, a_p, lambda_vac, phi_range[i], struct='PY')
|
||||
_, _, _, l_star_phi[i, 2], _ \
|
||||
= mie_scattering(n_p, n_s, a_p, lambda_vac, phi_range[i], struct='SHS', optional_params=[0.2, 0.05])
|
||||
_, _, _, l_star_phi[i, 3], _ \
|
||||
= mie_scattering(n_p, n_s, a_p, lambda_vac, phi_range[i], struct='PYAnnulus', optional_params=[1.2*a_p])
|
||||
|
||||
# Generate Colors
|
||||
n_colors = 4
|
||||
colormap = plt.get_cmap('plasma')
|
||||
c = np.empty(shape=(n_colors, 3))
|
||||
for i in range(n_colors):
|
||||
c[i, :] = colormap.colors[round(256 * i / n_colors)]
|
||||
|
||||
# Plot Data
|
||||
fig, ax1 = plt.subplots()
|
||||
ax1.plot(phi_range, l_star_phi[:, 0]*1e6, label='No Interactions', linewidth=2, c=c[0])
|
||||
ax1.plot(phi_range, l_star_phi[:, 1]*1e6, linestyle='--', label='Hard Sphere', linewidth=2, c=c[1])
|
||||
ax1.plot(phi_range, l_star_phi[:, 2]*1e6, linestyle=':', label='Sticky Hard Sphere', linewidth=2, c=c[2])
|
||||
ax1.plot(phi_range, l_star_phi[:, 3]*1e6, linestyle='-.', label='1.2$a_p$ Excluded Annulus', linewidth=2, c=c[3])
|
||||
ax1.plot(silica_data[0, :], silica_data[1, :]*1e6, 'k.', label='Silica Data', markersize=10)
|
||||
ax1.legend()
|
||||
ax1.set(xlabel=r'$\phi$', ylabel='l* [µm]')
|
||||
|
||||
plt.show()
|
||||
Loading…
Add table
Add a link
Reference in a new issue