Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
more examples
  • Loading branch information
bsumlin committed Sep 21, 2017
1 parent d41c590 commit 2cdbcc4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 23 deletions.
21 changes: 0 additions & 21 deletions PyMieScatt/Mie.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,6 @@ def ScatteringFunction(m, wavelength, diameter, minAngle=0, maxAngle=180, angula
measure = (4*np.pi/wavelength)*np.sin(measure/2)*(diameter/2)
return measure,SL,SR,SU

def qSpaceScatteringFunction(m,wavelength,diameter,minAngle=0,maxAngle=180,angularResolution=0.5,normed=False):
# http://pymiescatt.readthedocs.io/en/latest/forward.html#qSpaceScatteringFunction
x = np.pi*diameter/wavelength
_steps = int(1+(maxAngle-minAngle)/angularResolution)
theta = np.logspace(np.log10(minAngle),np.log10(maxAngle),_steps)*np.pi/180
qR = (4*np.pi/wavelength)*np.sin(theta/2)*(diameter/2)
SL = np.zeros(_steps)
SR = np.zeros(_steps)
SU = np.zeros(_steps)
for j in range(_steps):
u = np.cos(theta[j])
S1, S2 = MieS1S2(m,x,u)
SL[j] = (np.sum(np.conjugate(S1)*S1)).real
SR[j] = (np.sum(np.conjugate(S2)*S2)).real
SU[j] = (SR[j]+SL[j])/2
if normed:
SL /= np.max(SL)
SR /= np.max(SR)
SU /= np.max(SU)
return qR,SL,SR,SU

def SF_withSizeDistribution(m, wavelength, ndp, dp, minAngle=0, maxAngle=180, angularResolution=0.5, space='theta', normed=False):
# http://pymiescatt.readthedocs.io/en/latest/forward.html#SF_withSizeDistribution
_steps = int(1+maxAngle/angularResolution)
Expand Down
2 changes: 1 addition & 1 deletion PyMieScatt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# A collection of forward and inverse Mie routines, q-Space analysis tools, and structure factor tools

from PyMieScatt.Mie import MieQ, RayleighMieQ, LowFrequencyMieQ, Mie_withSizeDistribution, ScatteringFunction, SF_withSizeDistribution, qSpaceScatteringFunction, MatrixElements, MieQ_withDiameterRange, MieQ_withWavelengthRange, MieQ_withSizeParameterRange, Mie_Lognormal
from PyMieScatt.Mie import MieQ, RayleighMieQ, LowFrequencyMieQ, Mie_withSizeDistribution, ScatteringFunction, SF_withSizeDistribution, MatrixElements, MieQ_withDiameterRange, MieQ_withWavelengthRange, MieQ_withSizeParameterRange, Mie_Lognormal
from PyMieScatt.CoreShell import MieQCoreShell, CoreShellScatteringFunction, CoreShellMatrixElements
from PyMieScatt.Inverse import GraphicalInversion, GraphicalInversion_SD, IterativeInversion, IterativeInversion_SD, Inversion, Inversion_SD
from PyMieScatt._version import __version__
74 changes: 73 additions & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,76 @@ This produces a nice video, which I'll embed here just as soon as ReadTheDocs su
<video width="320" height="240" controls>
<source src="mir_ripples.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</video>


Angular Scattering Function of Salt Aerosol
-------------------------------------------

Recently, a colleague needed to know how much light a distribution of salt aerosol would scatter into two detectors, one at 60° and one at 90°. We modeled a lognormal distribution of NaCl particles based on laboratory measurements and then tried to figure out how much light we'd see at various angles.

.. code-block:: python
import PyMieScatt as ps # import PyMieScatt and abbreviate as ps
import matplotlib.pyplot as plt # import standard plotting library and abbreviate as plt
import numpy as np # import numpy and abbreviate as np
from scipy.integrate import trapz # import a single function for integration using trapezoidal rule
m = 1.536 # refractive index of NaCl
wavelength = 405 # replace with the laser wavelength (nm)
dp_g = 85 # geometric mean diameter - replace with your own (nm)
sigma_g = 1.5 # geometric standard deviation - replace with your own (unitless)
N = 1e5 # total number of particles - replace with your own (cm^-3)
B = ps.Mie_Lognormal(m,wavelength,sigma_g,dp_g,N,returnDistribution=True) # Calculate optical properties
S = ps.SF_withSizeDistribution(m,wavelength,B[7],B[8])
#%% Make graphs - lots of this is really unnecessary decoration for a pretty graph.
plt.close('all')
fig1 = plt.figure(figsize=(10.08,6.08))
ax1 = fig1.add_subplot(1,1,1)
ax1.plot(S[0],S[1],'b',ls='dashdot',lw=1,label="Parallel Polarization")
ax1.plot(S[0],S[2],'r',ls='dashed',lw=1,label="Perpendicular Polarization")
ax1.plot(S[0],S[3],'k',lw=1,label="Unpolarized")
x_label = ["0", r"$\mathregular{\frac{\pi}{4}}$", r"$\mathregular{\frac{\pi}{2}}$",r"$\mathregular{\frac{3\pi}{4}}$",r"$\mathregular{\pi}$"]
x_tick = [0,np.pi/4,np.pi/2,3*np.pi/4,np.pi]
ax1.set_xticks(x_tick)
ax1.set_xticklabels(x_label,fontsize=14)
ax1.tick_params(which='both',direction='in')
ax1.set_xlabel("Scattering Angle ϴ",fontsize=16)
ax1.set_ylabel(r"Intensity ($\mathregular{|S|^2}$)",fontsize=16,labelpad=10)
handles, labels = ax1.get_legend_handles_labels()
fig1.legend(handles,labels,fontsize=14,ncol=3,loc=8)
fig1.suptitle("Scattering Intensity Functions",fontsize=18)
fig1.show()
plt.tight_layout(rect=[0.01,0.05,0.915,0.95])
# Highlight certain angles and compute integral
sixty = [0.96<x<1.13 for x in S[0]]
ninety = [1.48<x<1.67 for x in S[0]]
ax1.fill_between(S[0],0,S[3],where=sixty,color='g',alpha=0.15)
ax1.fill_between(S[0],0,S[3],where=ninety,color='g',alpha=0.15)
ax1.set_yscale('log')
int_sixty = trapz(S[3][110:130],S[0][110:130])
int_ninety = trapz(S[3][169:191],S[0][169:191])
# Annotate plot with integral results
ax1.annotate("Integrated value = {i:1.3f}".format(i=int_sixty),
xy=(np.pi/3, S[3][120]), xycoords='data',
xytext=(np.pi/6, 0.8), textcoords='data',
arrowprops=dict(arrowstyle="->",
connectionstyle="arc3"),
)
ax1.annotate("Integrated value = {i:1.3f}".format(i=int_ninety),
xy=(np.pi/2, S[3][180]), xycoords='data',
xytext=(2*np.pi/5, 2), textcoords='data',
arrowprops=dict(arrowstyle="->",
connectionstyle="arc3"),
)

0 comments on commit 2cdbcc4

Please sign in to comment.