Skip to content

Commit

Permalink
semi-semi major
Browse files Browse the repository at this point in the history
I guess. Added AutoMie_ab() and wrote it in to MieS1S2(). Updated some docs, but not all.
  • Loading branch information
bsumlin committed Oct 24, 2017
1 parent 4d02113 commit 4cd4024
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 27 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.3.4
Version: 1.3.4.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.3.4 - 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.3.4.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
18 changes: 12 additions & 6 deletions PyMieScatt/Mie.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ def LowFrequencyMie_ab(m,x):
bn = np.append(b1,b2)
return an,bn

def AutoMie_ab(m,x):
if x<0.5:
return LowFrequencyMie_ab(m,x)
else:
return Mie_ab(m,x)

def Mie_SD(m, wavelength, dp, ndp, interpolate=False, asDict=False):
# http://pymiescatt.readthedocs.io/en/latest/forward.html#Mie_SD
dp = coerceDType(dp)
Expand Down Expand Up @@ -230,7 +236,7 @@ def Mie_SD(m, wavelength, dp, ndp, interpolate=False, asDict=False):
def ScatteringFunction(m, wavelength, diameter, minAngle=0, maxAngle=180, angularResolution=0.5, space='theta', angleMeasure='radians', normed=False):
# http://pymiescatt.readthedocs.io/en/latest/forward.html#ScatteringFunction
x = np.pi*diameter/wavelength

_steps = int(1+(maxAngle-minAngle)/angularResolution) # default 361

if angleMeasure in ['radians','RADIANS','rad','RAD']:
Expand All @@ -251,12 +257,12 @@ def ScatteringFunction(m, wavelength, diameter, minAngle=0, maxAngle=180, angula
_q = False
if x == 0:
return measure,0,0,0
_measure = np.linspace(minAngle,maxAngle,_steps)*np.pi/180
SL = np.zeros(_steps)
SR = np.zeros(_steps)
SU = np.zeros(_steps)
for j in range(_steps):
u = np.cos(measure[j])
u = np.cos(_measure[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
Expand Down Expand Up @@ -298,12 +304,12 @@ def SF_SD(m, wavelength, dp, ndp, minAngle=0, maxAngle=180, angularResolution=0.
def MieS1S2(m,x,mu):
# http://pymiescatt.readthedocs.io/en/latest/forward.html#MieS1S2
nmax = np.round(2+x+4*np.power(x,1/3))
an, bn = Mie_ab(m,x)
an, bn = AutoMie_ab(m,x)
pin, taun = MiePiTau(mu,nmax)
n = np.arange(1,int(nmax)+1)
n2 = (2*n+1)/(n*(n+1))
S1 = np.sum(n2*(an*pin+bn*taun))
S2 = np.sum(n2*(an*taun+bn*pin))
S1 = np.sum(n2[0:len(an)]*(an*pin[0:len(an)]+bn*taun[0:len(bn)]))
S2 = np.sum(n2[0:len(an)]*(an*taun[0:len(an)]+bn*pin[0:len(bn)]))
return S1, S2

def MiePiTau(mu,nmax):
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, AutoMieQ, LowFrequencyMieQ, Mie_SD, ScatteringFunction, SF_SD, MieS1S2, MiePiTau, MatrixElements, MieQ_withDiameterRange, MieQ_withWavelengthRange, MieQ_withSizeParameterRange, Mie_Lognormal
from PyMieScatt.Mie import MieQ, Mie_ab, Mie_cd, RayleighMieQ, AutoMieQ, LowFrequencyMieQ, LowFrequencyMie_ab, AutoMie_ab, Mie_SD, ScatteringFunction, SF_SD, MieS1S2, MiePiTau, MatrixElements, MieQ_withDiameterRange, MieQ_withWavelengthRange, MieQ_withSizeParameterRange, Mie_Lognormal
from PyMieScatt.CoreShell import MieQCoreShell, CoreShellScatteringFunction, CoreShellMatrixElements
from PyMieScatt.Inverse import ContourIntersection, ContourIntersection_SD, SurveyIteration, SurveyIteration_SD, Inversion, Inversion_SD, fastMieQ, fastMie_SD
from PyMieScatt._version import __version__
2 changes: 1 addition & 1 deletion PyMieScatt/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.3.4"
__version__ = "1.3.4.1"
18 changes: 12 additions & 6 deletions build/lib/PyMieScatt/Mie.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ def LowFrequencyMie_ab(m,x):
bn = np.append(b1,b2)
return an,bn

def AutoMie_ab(m,x):
if x<0.5:
return LowFrequencyMie_ab(m,x)
else:
return Mie_ab(m,x)

def Mie_SD(m, wavelength, dp, ndp, interpolate=False, asDict=False):
# http://pymiescatt.readthedocs.io/en/latest/forward.html#Mie_SD
dp = coerceDType(dp)
Expand Down Expand Up @@ -230,7 +236,7 @@ def Mie_SD(m, wavelength, dp, ndp, interpolate=False, asDict=False):
def ScatteringFunction(m, wavelength, diameter, minAngle=0, maxAngle=180, angularResolution=0.5, space='theta', angleMeasure='radians', normed=False):
# http://pymiescatt.readthedocs.io/en/latest/forward.html#ScatteringFunction
x = np.pi*diameter/wavelength

_steps = int(1+(maxAngle-minAngle)/angularResolution) # default 361

if angleMeasure in ['radians','RADIANS','rad','RAD']:
Expand All @@ -251,12 +257,12 @@ def ScatteringFunction(m, wavelength, diameter, minAngle=0, maxAngle=180, angula
_q = False
if x == 0:
return measure,0,0,0
_measure = np.linspace(minAngle,maxAngle,_steps)*np.pi/180
SL = np.zeros(_steps)
SR = np.zeros(_steps)
SU = np.zeros(_steps)
for j in range(_steps):
u = np.cos(measure[j])
u = np.cos(_measure[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
Expand Down Expand Up @@ -298,12 +304,12 @@ def SF_SD(m, wavelength, dp, ndp, minAngle=0, maxAngle=180, angularResolution=0.
def MieS1S2(m,x,mu):
# http://pymiescatt.readthedocs.io/en/latest/forward.html#MieS1S2
nmax = np.round(2+x+4*np.power(x,1/3))
an, bn = Mie_ab(m,x)
an, bn = AutoMie_ab(m,x)
pin, taun = MiePiTau(mu,nmax)
n = np.arange(1,int(nmax)+1)
n2 = (2*n+1)/(n*(n+1))
S1 = np.sum(n2*(an*pin+bn*taun))
S2 = np.sum(n2*(an*taun+bn*pin))
S1 = np.sum(n2[0:len(an)]*(an*pin[0:len(an)]+bn*taun[0:len(bn)]))
S2 = np.sum(n2[0:len(an)]*(an*taun[0:len(an)]+bn*pin[0:len(bn)]))
return S1, S2

def MiePiTau(mu,nmax):
Expand Down
2 changes: 1 addition & 1 deletion build/lib/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, AutoMieQ, LowFrequencyMieQ, Mie_SD, ScatteringFunction, SF_SD, MieS1S2, MiePiTau, MatrixElements, MieQ_withDiameterRange, MieQ_withWavelengthRange, MieQ_withSizeParameterRange, Mie_Lognormal
from PyMieScatt.Mie import MieQ, Mie_ab, RayleighMieQ, AutoMieQ, LowFrequencyMieQ, LowFrequencyMie_ab, AutoMie_ab, Mie_SD, ScatteringFunction, SF_SD, MieS1S2, MiePiTau, MatrixElements, MieQ_withDiameterRange, MieQ_withWavelengthRange, MieQ_withSizeParameterRange, Mie_Lognormal
from PyMieScatt.CoreShell import MieQCoreShell, CoreShellScatteringFunction, CoreShellMatrixElements
from PyMieScatt.Inverse import ContourIntersection, ContourIntersection_SD, SurveyIteration, SurveyIteration_SD, Inversion, Inversion_SD, fastMieQ, fastMie_SD
from PyMieScatt._version import __version__
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.3.4"
__version__ = "1.3.4.1"
Binary file removed dist/PyMieScatt-1.3.4-py3-none-any.whl
Binary file not shown.
Binary file added dist/PyMieScatt-1.3.4.1-py3-none-any.whl
Binary file not shown.
Binary file added dist/PyMieScatt-1.3.4.1.tar.gz
Binary file not shown.
Binary file removed dist/PyMieScatt-1.3.4.tar.gz
Binary file not shown.
8 changes: 2 additions & 6 deletions docs/forward.rst
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,7 @@ These functions compute the angle-dependent scattered field intensities and scat

.. py:Function:: MieS1S2(m,x,mu)
Calculates S\ :sub:`1` and S\ :sub:`2` at μ=cos(θ), where θ is the scattering angle. Must be explicitly imported via: ::
>>> from PyMieScatt.Mie import MieS1S2
Calculates S\ :sub:`1` and S\ :sub:`2` at μ=cos(θ), where θ is the scattering angle.

Uses :py:func:`Mie_ab` to calculate a\ :sub:`n` and b\ :sub:`n`, and :py:func:`MiePiTau` to calculate π\ :sub:`n` and τ\ :sub:`n`. S\ :sub:`1` and S\ :sub:`2` are calculated by:

Expand All @@ -534,9 +532,7 @@ These functions compute the angle-dependent scattered field intensities and scat

.. py:Function:: MiePiTau(mu,nmax)
Calculates π\ :sub:`n` and τ\ :sub:`n`. Must be explicitly imported via: ::
>>> from PyMieScatt.Mie import MiePiTau
Calculates π\ :sub:`n` and τ\ :sub:`n`.

This function uses recurrence relations to calculate π\ :sub:`n` and τ\ :sub:`n`, beginning with π\ :sub:`0` = 1, π\ :sub:`1` = 3μ (where μ is the cosine of the scattering angle), τ\ :sub:`0` = μ, and τ\ :sub:`1` = 3cos(2cos\ :sup:`-1` (μ)):

Expand Down
12 changes: 9 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ or from `GitHub <https://github.com/bsumlin/PyMieScatt>`_. Clone the repository

$ python setup.py install
The current version is 1.3.3.
The current version is 1.3.4.1.


.. toctree::
Expand All @@ -41,13 +41,19 @@ The current version is 1.3.3.



Revision Notes - version 1.3.4
Revision Notes - version 1.3.4.1
------------------------------

- Fixed a really dumb bug introduced in 1.3.3.
- Added a new sub-version delimiter. 1.x.y.z will be for minor revisions including some optimizations I've been working on that don't merit a full 1.x.y release.
- Added a new AutoMie_ab() function that uses LowFrequencyMie_ab() for *x = πd/λ* < 0.5 and Mie_ab() otherwise.
- Sped up the MieS1S2() function by using the new AutoMie_ab() function.
- Sped up the SF_SD() function by about 33% (on average) when the MieS1S2() optimizations are considered.
- Added Mie_cd() to __init__.py.

Revision History
----------------
- 1.3.4
- Fixed a really dumb bug introduced in 1.3.3.
- 1.3.3
- Fixed a big that caused SF_SD() to throw errors when a custom angle range was specified.
- Added MieS1S2() and MiePiTau() to __init__.py. Dunno why they weren't always there.
Expand Down

0 comments on commit 4cd4024

Please sign in to comment.