8 from numpy
import linalg
as la
9 from scipy.stats
import lognorm
10 from scipy.integrate
import quad
11 from scipy.spatial
import distance
12 import matplotlib
as mpl
13 import matplotlib.pyplot
as plt
17 oci_wl = [310, 315, 320, 325, 330, 335, 340, 345, 350, 355, 360, 365, 370, 375, 380, 385,
18 390, 395, 400, 405, 410, 415, 420, 425, 430, 435, 440, 445, 450, 455, 460, 465,
19 470, 475, 480, 485, 490, 495, 500, 505, 510, 515, 520, 525, 530, 535, 540, 545,
20 550, 555, 560, 565, 570, 575, 580, 585, 590, 595, 600, 605, 610, 615, 620, 625,
21 630, 635, 640, 645, 650, 655, 660, 665, 670, 675, 680, 685, 690, 695, 700, 705,
22 710, 715, 720, 725, 730, 735, 740, 745, 750, 755, 760, 765, 770, 775, 780, 785,
23 790, 795, 800, 805, 810, 815, 820, 825, 830, 835, 840, 845, 850, 855, 860, 865,
24 870, 875, 880, 885, 890, 895, 940, 1040, 1250, 1378, 1615, 2130, 2260 ]
26 viirs_wl = [ 412, 488, 550, 670, 865, 1240, 1610, 2250 ]
29 l2 = np.atleast_1d(np.linalg.norm(a, order, axis))
31 return a / np.expand_dims(l2, axis)
34 s1,s2,qx,qs,qb,gs = bh.bhmie(2*np.pi*sz/wl,m,1)
40 def __init__(self, name="", platform='oci', m=1.4+0j, start_sz=200, stop_sz=20000, points=50):
42 if (platform ==
'oci'):
43 self.
wl = np.copy(oci_wl[8:-7])
44 elif (platform ==
'viirs'):
45 self.
wl = np.copy(viirs_wl)
53 self.
m_real = np.zeros((self.
nwl), dtype=np.float64)
54 self.
m_imag = np.zeros((self.
nwl), dtype=np.float64)
55 self.
m_real[:] = np.real(m)
56 self.
m_imag[:] = np.imag(m)
60 self.
lsig[0] = np.log((self.
sz[1]-self.
sz[0])/2)
62 self.
sig[0] = (self.
sz[1]-self.
sz[0])/2
64 self.
lsig[i] = (self.
lsz[i+1]-self.
lsz[i-1])/5.0
65 self.
sig[i] = (self.
sz[i+1]-self.
sz[i-1])/4.5
72 print(
'Generating kernel: '+ self.
name, end =
' ')
75 lpdf =
lambda y, s, scale: lognorm.pdf(y, s=s, loc=0, scale=scale)
79 xs = np.linspace(self.
sz[isz]-5*self.
sig[isz], self.
sz[isz]+ 5*self.
sig[isz], self.
points )
80 ys = np.zeros(len(xs))
81 for k
in range(len(xs)):
82 ys[k] = lpdf(xs[k],self.
lsig[isz],self.
sz[isz])*
mie(xs[k],self.
wl[iwl],m[iwl])
83 self.
kernel[iwl,isz] = np.trapz(ys,xs)
89 self.
kernel[:,0] = 4*(self.
wl[0]/self.
wl[:])**4
95 I = np.identity(self.
nsz, dtype=np.float64)
97 H0 = -np.identity(self.
nsz, dtype=np.float64)
101 H0[i,j] = 1
if (j==i-1)
else H0[i,j]
109 H3 = np.zeros([self.
nsz, self.
nwl])
126 mpl.rcParams[
"font.size"] = 18
128 ax = fig.add_subplot(111, projection=
'3d')
129 wlg, szg = np.meshgrid(self.
wl, self.
sz)
131 ax.plot_wireframe(wlg, szg, self.
ikernel.T)
133 ax.plot_wireframe(wlg, szg, self.
kernel.T)
137 ofilepath = odir +
'/KERN_' + self.
name +
'.txt'
138 with open(ofilepath,
'w')
as outfile:
139 list = self.
kernel.tolist()
140 json.dump(list, outfile, separators=(
',',
':'), indent=4)
144 jd = json.dumps(self.__dict__, default=
lambda o: o.tolist(), indent=4)
152 ofilepath = odir +
'/KERN_' + self.
name +
'_all.txt'
153 with open(ofilepath,
'w')
as outfile:
155 outfile.write(json_obj)
159 with open(ifilepath,
'r', encoding=
'utf-8')
as infile:
160 obj_text = infile.read()
161 dict = json.loads(obj_text)
162 self.
name = dict[
'name']
163 self.
wl = np.array(dict[
'wl'])
164 self.
nwl = dict[
'nwl']
165 self.
start = dict[
'start']
166 self.
stop = dict[
'stop']
167 self.
points = dict[
'points']
168 self.
lsz = np.array(dict[
'lsz'])
169 self.
sz = np.array(dict[
'sz'])
170 self.
nsz = dict[
'nsz']
171 self.
m_real = np.array(dict[
'm_real'])
172 self.
m_imag = np.array(dict[
'm_imag'])
173 self.
kernel = np.array(dict[
'kernel'])
174 self.
lsig = np.array(dict[
'lsig'])
175 self.
sig = np.array(dict[
'sig'])