Skip to content

Commit d2008e9

Browse files
committed
made broadcasting in integrate_intensity_complex_medium more general
1 parent 3bca993 commit d2008e9

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

pymie/mie.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,25 +1276,18 @@ def integrate_intensity_complex_medium(dscat, distance, thetas, k,
12761276
if phis.ndim == 1:
12771277
phis, thetas = np.meshgrid(phis, thetas)
12781278

1279-
# reshape arrays for broadcasting. We use length of k (which should be
1280-
# num_values) to determine whether I_1 and I_2 are specified as
1281-
# (num_values, num_angles) or just (num_angles)
1279+
# reshape arrays for broadcasting. k should have axis corresponding to
1280+
# theta (and possibly phi, which will be accounted for in thetas.shape
1281+
# since meshgrid was used)
12821282
k = np.atleast_1d(k)
1283-
num_values = k.shape[0]
1284-
num_thetas = thetas.shape[0]
1283+
num_leading_axes = np.ndim(k)
1284+
k = k.reshape(k.shape + thetas.ndim*(1,))
1285+
# add axis for leading k dimensions (values, etc.)
1286+
thetas = thetas.reshape(num_leading_axes*(1,) + thetas.shape)
12851287
if phis is not None:
1286-
num_phis = phis.shape[-1]
1287-
k = k.reshape((num_values, 1, 1))
1288-
dscat = dscat.reshape((2, num_values, num_thetas, num_phis))
1289-
thetas = thetas[np.newaxis, ...]
1290-
# phis has only two dimensions because by the time we use it, we have
1291-
# already integrated over theta
1292-
phis = phis[0, :]
1293-
phis = phis.reshape(1, num_phis)
1294-
else:
1295-
dscat = dscat.reshape((2, num_values, num_thetas))
1296-
k = k.reshape((num_values, 1))
1297-
thetas = thetas.reshape((1, num_thetas))
1288+
# phis does not have a trailing dimension corresponding to theta
1289+
# because by the time we use it, we have already integrated over theta
1290+
phis = phis[..., 0, :]
12981291

12991292
# this line converts the unitless intensities to cross section
13001293
# Multiply by distance (= to radius of particle in montecarlo.py) because
@@ -1371,7 +1364,7 @@ def integrate_intensity_complex_medium(dscat, distance, thetas, k,
13711364
# k has trailing axes for theta (and possibly phi) that are no longer
13721365
# needed after the integration. We remove them here
13731366
k_shape = k.shape
1374-
k = k.reshape(num_values)
1367+
k = np.atleast_1d(k.squeeze())
13751368

13761369
# multiply by factor that accounts for attenuation in the incident light
13771370
# (see Sudiarta and Chylek (2001), eq 10).

0 commit comments

Comments
 (0)