Skip to content

Commit

Permalink
updated scatteringfunction
Browse files Browse the repository at this point in the history
and docs
  • Loading branch information
bsumlin committed Sep 20, 2017
1 parent 7f3f879 commit 48b65d1
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 47 deletions.
4 changes: 2 additions & 2 deletions PyMieScatt.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Metadata-Version: 1.1
Name: PyMieScatt
Version: 1.2.0
Version: 1.2.1
Summary: A collection of forward and inverse Mie solving routines based on Bohren and Huffman's Mie Theory derivations.
Home-page: http://air.eece.wustl.edu/people/ben-sumlin/
Author: Benjamin Sumlin
Author-email: bsumlin@wustl.edu
License: GPL
Description: 1.2.0 - Added error bounds as an option for the graphical inversion method. Added new automatic inversion methods Inversion() and Inversion_SD(). Significantly improved the iterative methods.
Description: 1.2.1 - Added error bounds as an option for the graphical inversion method. Added new automatic inversion methods Inversion() and Inversion_SD(). Significantly improved the iterative methods.
Docs are hosted at `ReadTheDocs <http://pymiescatt.readthedocs.io/>`_.
Keywords: Mie Rayleigh scattering absorption extinction light refraction
Platform: UNKNOWN
Expand Down
2 changes: 2 additions & 0 deletions PyMieScatt/Mie.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,15 @@ def ScatteringFunction(m, wavelength, diameter, minAngle=0, maxAngle=180, angula
adjust = 1

if space in ['q','qspace','QSPACE','qSpace']:
_steps *= 10
if minAngle==0:
minAngle = 1e-5
measure = np.logspace(np.log10(minAngle),np.log10(maxAngle),_steps)*np.pi/180
_q = True
else:
measure = np.linspace(minAngle,maxAngle,_steps)*adjust
_q = False

SL = np.zeros(_steps)
SR = np.zeros(_steps)
SU = np.zeros(_steps)
Expand Down
2 changes: 1 addition & 1 deletion PyMieScatt/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.0"
__version__ = "1.2.1"
8 changes: 7 additions & 1 deletion build/lib/PyMieScatt/Mie.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,15 @@ def ScatteringFunction(m, wavelength, diameter, minAngle=0, maxAngle=180, angula
adjust = 1

if space in ['q','qspace','QSPACE','qSpace']:
_steps *= 10
if minAngle==0:
minAngle = 1e-5
measure = np.logspace(np.log10(minAngle),np.log10(maxAngle),_steps)*adjust
measure = np.logspace(np.log10(minAngle),np.log10(maxAngle),_steps)*np.pi/180
_q = True
else:
measure = np.linspace(minAngle,maxAngle,_steps)*adjust
_q = False

SL = np.zeros(_steps)
SR = np.zeros(_steps)
SU = np.zeros(_steps)
Expand All @@ -247,6 +251,8 @@ def ScatteringFunction(m, wavelength, diameter, minAngle=0, maxAngle=180, angula
SL /= np.max(SL)
SR /= np.max(SR)
SU /= np.max(SU)
if _q:
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):
Expand Down
2 changes: 1 addition & 1 deletion build/lib/PyMieScatt/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.0"
__version__ = "1.2.1"
Binary file removed dist/PyMieScatt-1.2.0.tar.gz
Binary file not shown.
Binary file not shown.
Binary file added dist/PyMieScatt-1.2.1.tar.gz
Binary file not shown.
Binary file removed docs/_static/mie_ripples.mp4
Binary file not shown.
30 changes: 17 additions & 13 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ This produces the following image:

.. image:: images/sif.png

We can do better, though! Suppose we wanted to, for educational purposes, demonstrate how the "Mie ripples" develop as we increase size parameter. This script uses 405 nm light incident upon a particle of m=1.536+0.05i. Its diameter increases from 10 to 10000 nm and the result is plotted and a figure file is saved. The final few lines gather the figures into an mp4 video. Note that the Mie mathematics need only one line per loop, and the rest is generating images and movies.
We can do better, though! Suppose we wanted to, for educational purposes, demonstrate how the "Mie ripples" develop as we increase size parameter. This script considers a weakly absorbing particle of m=1.536+0.0015i. Its size parameter increases from 0.08 to 500 nm, the scattering function is plotted and a figure file is saved. The final few lines gather the figures into an mp4 video. Note that the Mie mathematics need only one line per loop, and the rest is generating images and movies.

First, install ffmpeg exe using conda:
.. code-block::
Expand All @@ -117,52 +117,56 @@ First, install ffmpeg exe using conda:
import os
wavelength=450.0
m=1.536+0.5j
drange = np.logspace(1,4,250)
m=1.536+0.0015j
drange = np.logspace(1,np.log10(500*405/np.pi),250)
for i,d in enumerate(drange):
if 250%(i+1)==0:
print("Working on image " + str(i) + "...",flush=True)
theta,SL,SR,SU = ps.ScatteringFunction(m,wavelength,d,space='theta',normed=True)
plt.close('all')
fig1 = plt.figure(figsize=(10.08,6.08))
ax1 = fig1.add_subplot(1,1,1)
#ax2 = fig1.add_subplot(1,2,2)
ax1.semilogy(theta,SL,'b',ls='dashdot',lw=1,label="Parallel Polarization")
ax1.semilogy(theta,SR,'r',ls='dashed',lw=1,label="Perpendicular Polarization")
ax1.semilogy(theta,SU,'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("ϴ",fontsize=16)
ax1.set_ylabel(r"Intensity ($\mathregular{|S|^2}$)",fontsize=16,labelpad=10)
ax1.set_ylim([1e-7,1])
ax1.set_xlim([0,np.pi])
ax1.annotate("dp = {dd:1.0f} nm".format(dd=d), xy=(3, 1e-6), xycoords='data',
xytext=(0.7, 0.1), textcoords='axes fraction',
ax1.set_ylim([1e-9,1])
ax1.set_xlim([1e-3,theta[-1]])
ax1.annotate("x = πd/λ = {dd:1.2f}".format(dd=np.round(np.pi*d/405,2)), xy=(3, 1e-6), xycoords='data',
xytext=(0.05, 0.1), textcoords='axes fraction',
horizontalalignment='left', verticalalignment='top',
fontsize=18
)
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])
plt.savefig('output\\' + str(i).rjust(3,'0') + '.png')
filenames = os.listdir('output\\')
with imageio.get_writer('movie.mp4', mode='I', fps=10) as writer:
dur = [0.1 for x in range(250)]
dur[249]=10
with imageio.get_writer('mie_ripples.mp4', mode='I', fps=10) as writer:
for filename in filenames:
image = imageio.imread('output\\' + filename)
writer.append_data(image)
This produces a nice video, which I'll show you just as soon as ReadTheDocs can embed mp4 files. For now, you can find it `here <https://github.com/bsumlin/PyMieScatt/blob/master/docs/images/mie_ripples.mp4?raw=true>`_.
This produces a nice video, which I'll embed here just as soon as ReadTheDocs supports Github content embedding. For now, you can download it `here <https://github.com/bsumlin/PyMieScatt/blob/master/docs/images/mie_ripples.mp4?raw=true>`_.


.. raw:: html
Expand Down
28 changes: 0 additions & 28 deletions docs/forward.rst
Original file line number Diff line number Diff line change
Expand Up @@ -446,34 +446,6 @@ These functions compute the angle-dependent scattered field intensities and scat
SU : numpy.ndarray
An array of the scattered intensity of unpolarized light, which is the average of SL and SR. Same size as the **theta** array.
.. py:Function:: qSpaceScatteringFunction(m, wavelength, diameter[, normed=False])
Creates arrays for plotting the angular scattering intensity functions in q-space with parallel, perpendicular, and unpolarized light. Uses :py:func:`MieS1S2` to compute S\ :sub:`1` and S\ :sub:`2`. The scattering angle variable, **qR**, is calculated by :math:`qR=(4\pi /\lambda)\,sin(\theta /2)\,(d_p /2)`.
**Parameters**
m : complex
The complex refractive index with the convention *m = n+ik*.
wavelength : float
The wavelength of incident light, in nanometers.
diameter : float
The diameter of the particle, in nanometers.
normed : bool, optional
If True, will normalize the output such that the maximum intensity will be 1.0. Defaults to False.
**Returns**
qR : numpy.ndarray
An array of the q-space angles used in calculations. Size is 3600.
SL : numpy.ndarray
An array of the scattered intensity of left-polarized (parallel) light. Same size as the **qR** array.
SR : numpy.ndarray
An array of the scattered intensity of right-polarized (perpendicular) light. Same size as the **qR** array.
SU : numpy.ndarray
An array of the scattered intensity of unpolarized light, which is the average of SL and SR. Same size as the **qR** array.
.. py:Function:: MatrixElements(m, wavelength, diameter, mu)
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You can install PyMieScatt from `The Python Package Index (PyPI) <https://pypi.p
$ pip install PyMieScatt


or from `GitHub <https://github.com/bsumlin/PyMieScatt>`_. The current version is 1.2.0.
or from `GitHub <https://github.com/bsumlin/PyMieScatt>`_. The current version is 1.2.1.


.. toctree::
Expand Down
Binary file removed docs/mie_ripples.mp4
Binary file not shown.

0 comments on commit 48b65d1

Please sign in to comment.