coefficients
- miepython.core.coefficients(m, x, n_pole=0, internal=False)[source]
Computes the Mie coefficients for a sphere.
This function calculates the Mie coefficients for electromagnetic scattering by a sphere. It supports both single values and arrays for the refractive index and size parameter. For arrays, the lengths of m and x must match. If the length of m or x is zero, the function assumes scalar values.
If n_pole > 0, the function returns only the 1 to nth multipole coefficients for each input.
- Parameters:
m (complex or array-like) – The complex refractive index of the sphere. If an array, must match the length of x.
x (float or array-like) – The size parameter of the sphere. If an array, must match the length of m.
n_pole (int, optional) – The specific multipole order to compute. Defaults to 0, which calculates all terms and returns the full arrays of coefficients.
internal (bool, optional) – If True then returns Mie coefficients needed to calculate fields inside the sphere.
- Returns:
ndarray –
[a, b], or[a, b, c, d]wheninternalis True. Forscalar
mandxeach entry is a 1-D array of coefficients, so the result has shape(2, n_terms)or(4, n_terms). For array input each entry gains a leading axis over the spheres, giving(2, n_spheres, n_pole)or(4, n_spheres, n_pole).
Notes
If the imaginary part of the refractive index is positive, it is automatically corrected to its conjugate value to ensure a valid input.
Every returned coefficient is a real term; the arrays carry no padding.
Examples
Compute coefficients for a single sphere:
>>> import miepython as mie >>> a, b = mie.coefficients(1.5 - 0.1j, 0.1) >>> len(a), len(b) (3, 3) >>> print(f"{a[0]:.6e}") 3.333700e-05-1.973631e-04j >>> print(f"{b[0]:.6e}") 6.672963e-08-2.754694e-07j
Keep only the dipole term for each of several spheres:
>>> a, b = mie.coefficients([1.5 - 0.1j, 1.4 - 0.05j], [2.0, 1.8], n_pole=1) >>> a.shape (2, 1) >>> print(f"{a[0, 0]:.6f}") 0.447946-0.386652j