-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_mstm.py
130 lines (114 loc) · 5.02 KB
/
test_mstm.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
# Copyright 2011-2013, 2016 Vinothan N. Manoharan, Annie Stephenson, and
# Victoria Hwang
#
# This file is part of the mstm-wrapper project.
#
# This package is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this package. If not, see <http://www.gnu.org/licenses/>.
"""
Tests for MSTM wrapper
.. moduleauthor:: Annie Stephenson <[email protected]>
.. moduleauthor:: Victoria Hwang <[email protected]>
.. moduleauthor:: Vinothan N. Manoharan <[email protected]>
"""
import mstm
import numpy as np
import pandas as pd
from nose.tools import assert_raises, assert_equal
from numpy.testing import assert_almost_equal, assert_array_almost_equal
def test_single_sphere():
"""
Test results for 1 sphere against structcol.mie and holopy.multisphere (F77)
"""
# make target object
xpos = [0]
ypos = [0]
zpos = [0]
radii = [0.125]
n_matrix = 1.54
n_spheres = 1.33
target = mstm.Target(xpos, ypos, zpos, radii, n_matrix, n_spheres)
wavelength = 0.4, 0.5, 2
theta = np.linspace(0, 180, 181)
# calculate the cross section for random polarization
calculation = mstm.MSTMCalculation(target, wavelength, theta, phi=None)
result = calculation.run()
total_csca = result.calc_cross_section(np.array([1, 0, 0, 0]), 0., 180.)
refl_csca = result.calc_cross_section(np.array([1, 0, 0, 0]), 90., 180.)
assert_almost_equal(total_csca[0], 0.011348999571838181, decimal = 6) # compare result with mie
assert_almost_equal(refl_csca[0], 8.6652839744818315e-05, decimal = 7) # compare result with mie
assert_almost_equal(total_csca[0], 0.011318622135323661, decimal = 4) # compare result with multisphere
assert_almost_equal(refl_csca[0], 8.6407209410860873e-05, decimal = 6) # compare result with multisphere
def test_two_spheres():
"""
Test results for 2 spheres against holopy.multisphere (F77)
"""
# make target object
xpos = [0,1]
ypos = [0,0]
zpos = [0,0]
radii = [0.125, 0.125]
n_matrix = 1.54
n_spheres = 1.33
target = mstm.Target(xpos, ypos, zpos, radii, n_matrix, n_spheres)
wavelength = 0.4, 0.5, 2
theta = np.linspace(0, 180, 181)
# calculate the cross section for random polarization
calculation = mstm.MSTMCalculation(target, wavelength, theta, phi=None)
result = calculation.run()
total_csca = result.calc_cross_section(np.array([1, 0, 0, 0]), 0., 180.)
refl_csca = result.calc_cross_section(np.array([1, 0, 0, 0]), 90., 180.)
assert_almost_equal(total_csca[0], 0.022626741536566294, decimal = 3) # compare result with multisphere
assert_almost_equal(refl_csca[0], 0.0001636858558060008, decimal = 5) # compare result with multisphere
def test_three_spheres():
"""
Test results for 3 spheres against holopy.multisphere (F77)
"""
# make target object
xpos = [0, 1, 0]
ypos = [0, 0, 1]
zpos = [0, 0, 0]
radii = [0.125, 0.125, 0.125]
n_matrix = 1.54
n_spheres = 1.33
target = mstm.Target(xpos, ypos, zpos, radii, n_matrix, n_spheres)
wavelength = 0.4, 0.5, 2
theta = np.linspace(0, 180, 181)
# calculate the cross section for random polarization
calculation = mstm.MSTMCalculation(target, wavelength, theta, phi=None)
result = calculation.run()
total_csca = result.calc_cross_section(np.array([1, 0, 0, 0]), 0., 180.)
refl_csca = result.calc_cross_section(np.array([1, 0, 0, 0]), 90., 180.)
assert_almost_equal(total_csca[0], 0.033904226206668324, decimal = 3) # compare result with multisphere
assert_almost_equal(refl_csca[0], 0.00024189819424174622, decimal = 5) # compare result with multisphere
def test_random_orient_one_sphere():
"""
Tests results for 1 sphere of random orientation against itself from a previous run
"""
# make target object
xpos = [0]
ypos = [0]
zpos = [0]
radii = [0.125]
n_matrix = 1.54
n_spheres = 1.33
target = mstm.Target(xpos, ypos, zpos, radii, n_matrix, n_spheres)
wavelength = 0.4, 0.5, 2
theta = np.linspace(0, 180, 181)
# calculate the cross section for random polarization
calculation = mstm.MSTMCalculation(target, wavelength, theta, phi = None, fixed = False)
result = calculation.run()
total_csca = result.calc_cross_section(np.array([1, 0, 0, 0]), 0., 180.)
refl_csca = result.calc_cross_section(np.array([1, 0, 0, 0]), 90., 180.)
assert_almost_equal(total_csca[0], 0.01134861, decimal = 5) # compare result with number from previous run
assert_almost_equal(refl_csca[0], 8.66921190e-05, decimal = 5) # compare result with number from previous run