Repository navigation
Add scattering after correcting the Rayleigh absorption sign - #35
Merged
scottprahl merged 3 commits intoOct 28, 2026
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Follow-up to the Rayleigh absorption sign fix: - conjugate m up front, as core.py does, so absorption is simply -Im(...) instead of abs() hiding the sign - use Bohren & Huffman's Re(ratio**2) for the x**4 extinction term rather than |ratio|**2; at m = 1.5 - 1j, x = 0.1 the error against Mie falls from 6e-4 to 2e-5, and near resonance (m = 0.05 - 1.43j, x = 0.05) from 0.43% to 0.12% - compare qext tightly against mie.efficiencies_mx for weak, moderate, strong and near-resonant absorption; the 1% tolerance of test_efficiencies hid both the sign bug and the |ratio|**2 error - changelog entry crediting @antonsoo Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Owner
|
thanks for your PR! I fixed the problem and used a better approximation from Bohren & Huffman |
scottprahl
added a commit
that referenced
this pull request
Oct 28, 2026
Builds on the Rayleigh absorption-sign fix (PR #35): - call core._check_m_x from rayleigh.efficiencies_mx and S1_S2, so the Rayleigh functions reject NaN/infinite m or x, negative x and negative m.real exactly as the Mie functions do - add core._check_one_sphere so core and rayleigh S1_S2 (and everything built on them) say they take one sphere, instead of numpy's "truth value of an array is ambiguous" - return g with the same shape and type as the other efficiencies - treat m.real == 0 as a perfect conductor, as the rest of the package does: electric plus magnetic dipole (b1 = -a1/2), qext = qsca = 10/3 x**4, qback = 9 x**4, g = -2/5. The dielectric formulas used before gave 3.2x the Mie qext for m = -1j - rewrite the module docstring: the approximation, which expressions go beyond the leading Rayleigh term, accuracy against Mie, conventions, conductors, and doctested examples - tests for all of the above, including the array branch of the conjugation that left PR #35's coverage at 99% Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For a weakly absorbing sphere, the negative-imaginary index convention can give
qext < qsca, so the computed absorption is negative:Before:
After, both conventions give
Qabs=9.979361445e-08.Take the absolute value of the absorption contribution before adding scattering:
abs(qext.imag) + qsca. The existing expression appliesabsafter adding scattering, which subtracts scattering when the imaginary part is negative. Add eight weak-absorption regressions for convention agreement, positive absorption and the leading Rayleigh polarizability limit.Both backend suites pass all 553 tests on Python 3.12 and 3.14. Configured
make lintand combined 100% coverage pass. A separate continuation uses the shipped Segelstein water-index table: all 54 absorption/physical-unit configurations pass after, versus none before; 50 previously had negative absorption. Corrected absorption agrees with independent native Scattnlay within 3.4 parts per million for these small particles. All 27 complete positive-index, lossless and full-Mie controls are exactly unchanged, and an installed wheel reproduces the fixed source results. This does not change the scope or accuracy guarantees of the Rayleigh approximation.