This repository has been archived by the owner on May 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbh_mie.py
173 lines (135 loc) · 5.37 KB
/
bh_mie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# -*- coding: utf-8 -*-
from numpy import *
def bhmie(x,refrel,nang):
# This file is converted from mie.m, see http://atol.ucsd.edu/scatlib/index.htm
# Bohren and Huffman originally published the code in their book on light scattering
# Calculation based on Mie scattering theory
# input:
# x - size parameter = k*radius = 2pi/lambda * radius
# (lambda is the wavelength in the medium around the scatterers)
# refrel - refraction index (n in complex form for example: 1.5+0.02*i;
# nang - number of angles for S1 and S2 function in range from 0 to pi/2
# output:
# S1, S2 - funtion which correspond to the (complex) phase functions
# Qext - extinction efficiency
# Qsca - scattering efficiency
# Qback - backscatter efficiency
# gsca - asymmetry parameter
nmxx=150000
s1_1=zeros(nang,dtype=complex128)
s1_2=zeros(nang,dtype=complex128)
s2_1=zeros(nang,dtype=complex128)
s2_2=zeros(nang,dtype=complex128)
pi=zeros(nang)
tau=zeros(nang)
if (nang > 1000):
print ('error: nang > mxnang=1000 in bhmie')
return
# Require NANG>1 in order to calculate scattering intensities
if (nang < 2):
nang = 2
pii = 4.*arctan(1.)
dx = x
drefrl = refrel
y = x*drefrl
ymod = abs(y)
# Series expansion terminated after NSTOP terms
# Logarithmic derivatives calculated from NMX on down
xstop = x + 4.*x**0.3333 + 2.0
nmx = max(xstop,ymod) + 15.0
nmx=fix(nmx)
# BTD experiment 91/1/15: add one more term to series and compare resu<s
# NMX=AMAX1(XSTOP,YMOD)+16
# test: compute 7001 wavelen>hs between .0001 and 1000 micron
# for a=1.0micron SiC grain. When NMX increased by 1, only a single
# computed number changed (out of 4*7001) and it only changed by 1/8387
# conclusion: we are indeed retaining enough terms in series!
nstop = int(xstop)
if (nmx > nmxx):
print ( "Value Error: nmx > nmxx=%f for |m|x=%f" % ( nmxx, ymod) )
return
dang = .5*pii/ (nang-1)
amu=arange(0.0,nang,1)
amu=cos(amu*dang)
pi0=zeros(nang)
pi1=ones(nang)
# Logarithmic derivative D(J) calculated by downward recurrence
# beginning with initial value (0.,0.) at J=NMX
nn = int(nmx)-1
d=zeros(nn+1)
for n in range(0,nn):
en = nmx - n
d[nn-n-1] = (en/y) - (1./ (d[nn-n]+en/y))
#*** Riccati-Bessel functions with real argument X
# calculated by upward recurrence
psi0 = cos(dx)
psi1 = sin(dx)
chi0 = -sin(dx)
chi1 = cos(dx)
xi1 = psi1-chi1*1j
qsca = 0.
gsca = 0.
p = -1
for n in range(0,nstop):
en = n+1.0
fn = (2.*en+1.)/(en* (en+1.))
# for given N, PSI = psi_n CHI = chi_n
# PSI1 = psi_{n-1} CHI1 = chi_{n-1}
# PSI0 = psi_{n-2} CHI0 = chi_{n-2}
# Calculate psi_n and chi_n
psi = (2.*en-1.)*psi1/dx - psi0
chi = (2.*en-1.)*chi1/dx - chi0
xi = psi-chi*1j
#*** Store previous values of AN and BN for use
# in computation of g=<cos(theta)>
if (n > 0):
an1 = an
bn1 = bn
#*** Compute AN and BN:
an = (d[n]/drefrl+en/dx)*psi - psi1
an = an/ ((d[n]/drefrl+en/dx)*xi-xi1)
bn = (drefrl*d[n]+en/dx)*psi - psi1
bn = bn/ ((drefrl*d[n]+en/dx)*xi-xi1)
#*** Augment sums for Qsca and g=<cos(theta)>
qsca += (2.*en+1.)* (abs(an)**2+abs(bn)**2)
gsca += ((2.*en+1.)/ (en* (en+1.)))*( real(an)* real(bn)+imag(an)*imag(bn))
if (n > 0):
gsca += ((en-1.)* (en+1.)/en)*( real(an1)* real(an)+imag(an1)*imag(an)+real(bn1)* real(bn)+imag(bn1)*imag(bn))
#*** Now calculate scattering intensity pattern
# First do angles from 0 to 90
pi=0+pi1 # 0+pi1 because we want a hard copy of the values
tau=en*amu*pi-(en+1.)*pi0
s1_1 += fn* (an*pi+bn*tau)
s2_1 += fn* (an*tau+bn*pi)
#*** Now do angles greater than 90 using PI and TAU from
# angles less than 90.
# P=1 for N=1,3,...% P=-1 for N=2,4,...
# remember that we have to reverse the order of the elements
# of the second part of s1 and s2 after the calculation
p = -p
s1_2+= fn*p* (an*pi-bn*tau)
s2_2+= fn*p* (bn*pi-an*tau)
psi0 = psi1
psi1 = psi
chi0 = chi1
chi1 = chi
xi1 = psi1-chi1*1j
#*** Compute pi_n for next value of n
# For each angle J, compute pi_n+1
# from PI = pi_n , PI0 = pi_n-1
pi1 = ((2.*en+1.)*amu*pi- (en+1.)*pi0)/ en
pi0 = 0+pi # 0+pi because we want a hard copy of the values
#*** Have summed sufficient terms.
# Now compute QSCA,QEXT,QBACK,and GSCA
# we have to reverse the order of the elements of the second part of s1 and s2
s1=concatenate((s1_1,s1_2[-2::-1]))
s2=concatenate((s2_1,s2_2[-2::-1]))
gsca = 2.*gsca/qsca
qsca = (2./ (dx*dx))*qsca
qext = (4./ (dx*dx))* real(s1[0])
# more common definition of the backscattering efficiency,
# so that the backscattering cross section really
# has dimension of length squared
qback = 4*(abs(s1[2*nang-2])/dx)**2
#qback = ((abs(s1[2*nang-2])/dx)**2 )/pii #old form
return s1,s2,qext,qsca,qback,gsca