@@ -1314,58 +1314,25 @@ def integrate_intensity_complex_medium(dscat, thetas, kd,
13141314 (1/np.abs(k)**2) to recover the dimensional cross-sections.
13151315
13161316 """
1317- # expand dims if phis is specified
1317+ # do phi integral first because it's the last dimension in dscat when
1318+ # specified (thus phis will broadcast with dscat)
13181319 if phis is not None :
1319- if phis .ndim == 1 :
1320- thetas = thetas [:, np .newaxis ]
1321- phis = phis [np .newaxis , :]
1322-
1323- # reshape arrays for broadcasting. k should have axis corresponding to
1324- # theta (and possibly phi, which will be accounted for in thetas.shape)
1325- kd = np .atleast_1d (kd )
1326- num_leading_axes = np .ndim (kd )
1327- kd = kd .reshape (kd .shape + thetas .ndim * (1 ,))
1328- # add axis for leading k dimensions (values, etc.)
1329- thetas = thetas .reshape (num_leading_axes * (1 ,) + thetas .shape )
1330- if phis is not None :
1331- # phis does not have a trailing dimension corresponding to theta
1332- # because by the time we use it, we have already integrated over theta
1333- phis = phis [..., 0 , :]
1334-
1335- dsigma_1 = dscat [0 ]
1336- dsigma_2 = dscat [1 ]
1337-
1338- if phis is None :
1339- # include Jacobian
1340- integrand_par = dsigma_1 * np .abs (np .sin (thetas ))
1341- integrand_perp = dsigma_2 * np .abs (np .sin (thetas ))
1342-
1343- # Integrate over theta
1344- integral_par = np .trapezoid (integrand_par , x = thetas )
1345- integral_perp = np .trapezoid (integrand_perp , x = thetas )
1346-
1320+ integrand = np .trapezoid (dscat , x = phis )
1321+ else :
1322+ integrand = dscat
13471323 # integrate over phi: multiply by factor to integrate over phi
13481324 # (this factor is the integral of cos(phi)**2 and sin(phi)**2 in
13491325 # parallel and perpendicular polarizations, respectively)
13501326 # This factor is needed to account for polarization, which introduces
13511327 # factors of cos(phi) and sin(phi) for the electric fields.
1352- sigma_1 = (integral_par * (phi_max / 2 + np .sin (2 * phi_max )/ 4 -
1353- phi_min / 2 - np .sin (2 * phi_min )/ 4 ))
1354- sigma_2 = (integral_perp * (phi_max / 2 - np .sin (2 * phi_max )/ 4 -
1355- phi_min / 2 + np .sin (2 * phi_min )/ 4 ))
1356- else :
1357- integrand_1 = dsigma_1 * np .abs (np .sin (thetas ))
1358- integrand_2 = dsigma_2 * np .abs (np .sin (thetas ))
1359-
1360- # Integrate over theta and phi
1361- sigma_1 = np .trapezoid (np .trapezoid (integrand_1 , x = thetas , axis = 1 ),
1362- x = phis )
1363- sigma_2 = np .trapezoid (np .trapezoid (integrand_2 , x = thetas , axis = 1 ),
1364- x = phis )
1328+ integrand [0 ] = (integrand [0 ] * (phi_max / 2 + np .sin (2 * phi_max )/ 4
1329+ - phi_min / 2 - np .sin (2 * phi_min )/ 4 ))
1330+ integrand [1 ] = (integrand [1 ] * (phi_max / 2 - np .sin (2 * phi_max )/ 4
1331+ - phi_min / 2 + np .sin (2 * phi_min )/ 4 ))
13651332
1366- # kd has trailing axes for theta (and possibly phi) that are no longer
1367- # needed after the integration. We remove them here
1368- kd = np .atleast_1d ( kd . squeeze () )
1333+ # integrate diff. cross-sections over theta using Jacobian
1334+ integrand = integrand * np . abs ( np . sin ( thetas ))
1335+ sigma = np .trapezoid ( integrand , x = thetas )
13691336
13701337 # multiply by factor that accounts for attenuation in the incident light
13711338 # (see Sudiarta and Chylek (2001), eq 10).
@@ -1381,9 +1348,10 @@ def integrate_intensity_complex_medium(dscat, thetas, kd,
13811348 + (1 - exponent ) / (2 * kd .imag )** 2 ))
13821349
13831350 # calculate the averaged sigma
1384- sigma = (sigma_1 + sigma_2 )/ 2 * factor
1351+ sigma = sigma * factor
1352+ sigma_avg = sigma .sum (axis = 0 )/ 2
13851353
1386- return (sigma , ( sigma_1 * factor ), ( sigma_2 * factor ) )
1354+ return (sigma_avg , sigma [ 0 ], sigma [ 1 ] )
13871355
13881356
13891357def diff_abs_intensity_complex_medium (m , x , thetas , ktd ):
0 commit comments