Download Latest Version Fixes for Monte Carlo and Rayleigh modules source code.zip (12.6 MB)
Home / 3.3.1
Name Modified Size InfoDownloads / Week
Parent folder
Fixes for Monte Carlo and Rayleigh modules source code.tar.gz 2026-10-28 12.5 MB
Fixes for Monte Carlo and Rayleigh modules source code.zip 2026-10-28 12.6 MB
README.md 2026-10-28 5.8 kB
Totals: 3 Items   25.1 MB 0
  • Improve generation of random Mie angles, thanks @antonsoo
  • Fix broken Rayleigh calculation for small spheres with absorption, thanks @antonsoo
  • Bump python version to 3.15, stop testing 3.10

3.3.1 (10/28/2026)

  • fix rayleigh.efficiencies_mx subtracting scattering from extinction. With the m = n - ik convention the absorption term is negative, so abs(absorption + qsca) gave absorption minus scattering, and qext for m = 1.5 - 1e-6j at x = 0.01 came out 21% low (thanks @antonsoo). The x**4 term now follows Bohren & Huffman's Re(ratio**2) rather than |ratio|**2, which agrees with Mie to 2e-5 instead of 6e-4 at m = 1.5 - 1j, x = 0.1. m is conjugated first, as core.py does. The Rayleigh qext also sets the albedo and qext normalizations, so rayleigh.S1_S2 and the intensities change too
  • handle perfectly conducting spheres in rayleigh. As elsewhere in the package, m.real == 0 now means a perfect conductor, which radiates a magnetic dipole b1 = -a1/2 alongside its electric one: qext = qsca = 10/3 x4, qback = 9 x4 and g = -2/5. The dielectric formulas were used before, so m = -1j gave a qext about three times the Mie value; it now agrees to 2e-5 at x = 0.01
  • validate input to the rayleigh functions as core.py now does. A NaN or infinite m or x, a negative x, or a negative real part of m raises ValueError; before, rayleigh.efficiencies_mx(nan, 0.05) returned NaN and m = -1.5 - 0.1j or x = -0.05 returned normal-looking efficiencies
  • say why S1_S2 and the functions built on it reject an array of spheres, in both core and rayleigh. They vectorize over mu and describe one sphere, but an array m or x failed with numpy's "truth value of an array is ambiguous"
  • return g from rayleigh.efficiencies_mx with the same shape and type as the other efficiencies. It was the int 0 even for an array of spheres
  • document the rayleigh module: what the approximation is, which expressions go beyond the leading Rayleigh term, its accuracy against Mie, and tested examples
  • support Python 3.11 through 3.15. requires-python is now >=3.11, 3.10 is dropped from the classifiers, the black target versions and the CI matrix, and 3.15 is added to all three
  • raise ValueError for a refractive index or size parameter the kernels would misread. The kernels treat any index that fails m.real > 0 as a perfect conductor, so m = nan or m = -1.5 silently returned the answer for a metal sphere, and an infinite m returned NaN. A NaN x raised "cannot convert float NaN to integer" on the pure-Python backend while numba returned NaN, an infinite x raised a different unhelpful error on each backend, and a negative x returned zeros. coefficients, efficiencies_mx, S1_S2 and the near fields, and everything built on them, now reject a NaN or infinite m or x, a negative x, and a negative real part of m, checking every entry of an array. m.real == 0 still means a perfect conductor and x = 0 is still allowed
  • fix monte_carlo.mu_with_uniform_cdf returning wrong angles for fine tables. cdf began at I(-1)/num rather than zero, so a target below that value left the inversion loop at index zero and interpolated against the last entry. cdf now integrates the phase function with the trapezoidal rule, starting at exactly 0 and ending at exactly 1 (it used to end slightly above 1), so tables differ slightly from 3.3.0. cdf and mu_with_uniform_cdf also raise ValueError when num is less than 2 (thanks @antonsoo)
  • replace the inversion loop in monte_carlo.mu_with_uniform_cdf with np.interp
  • warn when monte_carlo.cdf uses too few angles to resolve the phase function. The raw integral should be one, so a RuntimeWarning is issued when it is off by more than 1%; normalizing used to hide the error silently. A large sphere needs roughly x2 angles, because its forward peak is only about 8/x2 wide in cos(theta)
  • size the table inside monte_carlo.mu_with_uniform_cdf from x, as max(2000, 5*x**2) angles instead of a fixed 2000. At x = 100 the sampled mean cosine was 0.930 against g = 0.868; it is now 0.869. Large spheres are slower to tabulate: seconds at x = 100, about a minute at x = 300
  • raise ValueError from monte_carlo.cdf and mu_with_uniform_cdf when the phase function is not finite
  • rewrite the monte_carlo docstrings, with tested examples of drawing random scattering angles
  • name the encoding on every text read and write. open(path) and Path.read_text() decode with the locale's preferred encoding, which is UTF-8 on Linux and macOS but cp1252 on Windows, so tests/test_makefile.py passed everywhere except the four Windows jobs, where it died on the emoji in the Makefile's echo lines. Two more latent cases are fixed alongside it: the scattnlay metadata read in tests/test_scattnlay_reference.py, which survived only because that JSON happens to be pure ASCII, and the write_text in docs/data/generate_scattnlay_reference_fields.py
  • check for locale-dependent text I/O in the test suite, by walking the syntax trees of every Python file in the repository and requiring an explicit encoding=. The failure is invisible on the platforms this package is developed on, so a Windows-only break was waiting for whoever next added a non-ASCII character to a file something reads
Source: README.md, updated 2026-10-28