Skip to content

Commit 463f936

Browse files
committed
removed option to specify kd as Quantity; must now be float/complex
1 parent 7e90738 commit 463f936

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

pymie/mie.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ def calc_dwell_time(radius, n_medium, n_particle, wavelen,
321321
angles = Quantity(np.linspace(min_angle, np.pi, num_angles), 'rad')
322322
distance = radius.max()
323323
k = 2*np.pi/wavelen_media
324+
kd = (k*distance).to("").magnitude
324325
(diff_cscat_par,
325-
diff_cscat_perp) = diff_scat_intensity_complex_medium(m,
326-
x, angles,
327-
k*distance)
326+
diff_cscat_perp) = diff_scat_intensity_complex_medium(m, x, angles,
327+
kd)
328328

329329
cscat = integrate_intensity_complex_medium(diff_cscat_par,
330330
diff_cscat_perp,
@@ -360,8 +360,9 @@ def calc_reflectance(radius, n_medium, n_particle, wavelen,
360360
if np.any(np.imag(x) > 0):
361361
distance = rmax
362362
k = np.atleast_1d(2*np.pi/wavelen_media)
363+
kd = (k*distance).to("").magnitude
363364
diff_cscat = diff_scat_intensity_complex_medium(m, x, thetas,
364-
k*distance)
365+
kd)
365366
refl_cscat = integrate_intensity_complex_medium(diff_cscat,
366367
distance, thetas, k)[0]
367368
else:
@@ -963,10 +964,6 @@ def _scat_fields_complex_medium(m, x, thetas, kd, near_field=False):
963964
Q. Fu and W. Sun, "Mie theory for light scattering by a spherical particle
964965
in an absorbing medium". Applied Optics, 40, 9 (2001).
965966
'''
966-
# convert units from whatever units the user specifies
967-
if isinstance(kd, Quantity):
968-
kd = kd.to('').magnitude
969-
970967
# calculate mie coefficients
971968
nstop = _nstop(np.array(x).max())
972969
n = np.arange(nstop)+1.
@@ -1177,9 +1174,6 @@ def diff_scat_intensity_complex_medium(m, x, thetas, kd, phis=None,
11771174
in an absorbing medium". Applied Optics, 40, 9 (2001).
11781175
11791176
"""
1180-
if isinstance(kd, Quantity):
1181-
kd = kd.to('').magnitude
1182-
11831177
# ensure that broadcasting will work correctly
11841178
kd = np.atleast_1d(kd)[:, np.newaxis]
11851179
if cartesian:
@@ -1438,10 +1432,6 @@ def diff_abs_intensity_complex_medium(m, x, thetas, ktd):
14381432
in an absorbing medium". Applied Optics, 40, 9 (2001).
14391433
14401434
'''
1441-
# convert units from whatever units the user specifies
1442-
if isinstance(ktd, Quantity):
1443-
ktd = ktd.to('').magnitude
1444-
14451435
# calculate mie coefficients
14461436
nstop = _nstop(np.array(x).max())
14471437
n = np.arange(nstop)+1.

pymie/tests/test_mie.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def test_cross_section_complex_medium():
520520
n_matrix, x_scat, x,
521521
wavelen)[0]
522522
# With Mie solutions in absorbing medium
523-
rho_scat = k*distance
523+
rho_scat = (k*distance).to("").magnitude
524524
I_parperp = mie.diff_scat_intensity_complex_medium(m, x, theta, rho_scat)
525525
cscat_exact = mie.integrate_intensity_complex_medium(I_parperp,
526526
distance, theta, k)[0]
@@ -562,7 +562,7 @@ def test_cross_section_complex_medium():
562562
n_matrix, x_scat, x,
563563
wavelen)[0]
564564
# With full Mie solutions that include the near fields
565-
rho_scat = k*distance
565+
rho_scat = (k*distance).to("").magnitude
566566
I_parperp = mie.diff_scat_intensity_complex_medium(m, x, theta, rho_scat,
567567
near_field=True)
568568
cscat_exact2 = mie.integrate_intensity_complex_medium(I_parperp,
@@ -577,7 +577,7 @@ def test_cross_section_complex_medium():
577577
m = index_ratio(n_particle, n_matrix)
578578
k = 2*np.pi*n_matrix/wavelen
579579
x = size_parameter(wavelen, n_matrix, radius)
580-
rho_scat = k*distance
580+
rho_scat = (k*distance).to("").magnitude
581581

582582
# With full Mie solutions
583583
I_parperp = mie.diff_scat_intensity_complex_medium(m, x, theta, rho_scat)
@@ -608,7 +608,7 @@ def test_multilayer_complex_medium():
608608
angles = np.linspace(0, np.pi, 10000)
609609
distance = Quantity(100000000.0,'nm')
610610
k = 2*np.pi*n_sample/wavelen
611-
kd = k*distance
611+
kd = (k*distance).to("").magnitude
612612

613613
# With far-field Mie solutions
614614
cscat_real = mie.calc_cross_sections(marray, xarray, wavelen/n_sample)[0]
@@ -697,7 +697,7 @@ def test_diff_scat_intensity_complex_medium_cartesian():
697697
# parameters for calculating scattering
698698
m = index_ratio(n_particle, n_matrix)
699699
x = size_parameter(wavelen, n_matrix, radius)
700-
kd = 2*np.pi*n_matrix/wavelen*Quantity(10000.0,'nm')
700+
kd = (2*np.pi*n_matrix/wavelen*Quantity(10000.0,'nm')).to("").magnitude
701701

702702
# calculate differential scattered intensity in par/perp basis
703703
I_parperp = mie.diff_scat_intensity_complex_medium(m, x, thetas_2d, kd,
@@ -736,7 +736,7 @@ def test_integrate_intensity_complex_medium_cartesian():
736736
x = size_parameter(wavelen, n_matrix, radius)
737737
k = 2*np.pi*n_matrix/wavelen
738738
distance = Quantity(10000.0,'nm')
739-
kd = k*distance
739+
kd = (k*distance).to("").magnitude
740740

741741
# calculate the differential scattered intensities
742742
I_xy = mie.diff_scat_intensity_complex_medium(m, x, thetas_2d, kd,
@@ -781,7 +781,7 @@ def test_value_errors():
781781
x = size_parameter(wavelen, n_matrix, radius)
782782
k = 2*np.pi*n_matrix/wavelen
783783
distance = Quantity(10000.0,'nm')
784-
kd = k*distance
784+
kd = (k*distance).to("").magnitude
785785

786786
with pytest.raises(ValueError):
787787
# try to calculate near field in cartesian

pymie/tests/test_mie_vectorized.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def test_vectorized_angular_functions(self, num_wavelen,
617617
# scattering calculations
618618
k = 2*np.pi*n_matrix/wavelen
619619
d = 10*np.atleast_1d(radius)[-1]
620-
kd = np.atleast_1d(k*d)
620+
kd = np.atleast_1d(k*d).to("").magnitude
621621
i12 = mie.diff_scat_intensity_complex_medium(m, x, thetas,
622622
kd,
623623
cartesian=cartesian,

0 commit comments

Comments
 (0)