Skip to content

Commit c7498e9

Browse files
committed
added test for vectorization over 2D array of angles
1 parent 27e6364 commit c7498e9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pymie/tests/test_mie_vectorized.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,3 +928,37 @@ def test_vectorized_calc_reflectance(self, n_medium, num_wavelen,
928928

929929
assert_allclose(refl.magnitude, refl_loop, rtol=1e-14)
930930
assert refl.units == 1/wavelen.units**2
931+
932+
def test_multidimensional_vectorization(self):
933+
"""Tests that specifying a multidimensional array of angles works.
934+
This is to check that we can specify, for example, a different set of
935+
thetas for every wavelength
936+
937+
"""
938+
num_wavelen = 11
939+
num_angles = 13
940+
num_layer = 2
941+
m, x, wavelen, radius, n_particle, n_matrix = \
942+
mx(num_wavelen=num_wavelen, num_layer=num_layer, **self.mxargs,
943+
return_all=True)
944+
n_medium = 1.33
945+
946+
# make array of wavelength and angles where at each wavelength there is
947+
# a different set of angles
948+
thetas = np.linspace(np.linspace(0, 0.5*np.pi, num_angles),
949+
np.linspace(np.pi-0.5*np.pi, np.pi, num_angles),
950+
num_wavelen)
951+
952+
form_factor = mie.calc_ang_scat(m, x, thetas)
953+
expected_shape = (num_wavelen, num_angles, 2)
954+
assert form_factor.shape == expected_shape
955+
956+
# we should get same values from loop
957+
iparperp_loop = []
958+
for i in range(num_wavelen):
959+
# m[[i]] notation preserves 2D array
960+
iparperp = mie.calc_ang_scat(m[[i]], x[[i]], thetas[i])
961+
iparperp_loop.append(iparperp)
962+
# concatenate along wavelength axis
963+
iparperp_loop = np.concatenate(iparperp_loop, axis=0)
964+
assert_equal(form_factor, iparperp_loop)

0 commit comments

Comments
 (0)