Trace once for the distortion, vignetting, and sensor angle - #212
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #212 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 121 121
Lines 7402 7408 +6
=========================================
+ Hits 7402 7408 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
`linearize` fits the distortion and the vignetting from the same rays, traced with identical arguments, and then traced a third time through `rayfunction_default` for the cosine of the angle at which light strikes the sensor. None of the three reads the intensity. Factor the fitting out of `distortion` and `vignetting` into `_fit_distortion` and `_fit_vignetting`, so a caller needing both can trace once and fit twice, and take `direction` from those same rays. The public methods keep their behaviour, they just trace and then call the fitter. before: 4 raytraces, 4 stop solves, 3.46 s after: 2 raytraces, 1 stop solve, 2.64 s with `num_interpolation` set: 1.66 s -> 1.06 s The distortion and vignetting models are unchanged bit for bit, along with the scene, sensor, and illumination arrays they are fit to. `direction` moves by 2.31%. It was evaluated on `grid_input.wavelength`, a single value, 629.77 A for ESIS, no matter which band was asked for; it is now averaged over the band being linearized. A caller linearizing a line far from that wavelength was getting a worse answer than this: 12% at 300 A, 23% at 950 A. The average now includes the wavelength axis explicitly rather than relying on `axis_wavelength_`, which is empty whenever `grid_input` holds a scalar wavelength and would have let that axis survive into the result. `direction` has to stay a scalar, since `AbstractImagingSensor.expose` indexes it by the cell centers of the *scene's* wavelength grid, which is unrelated to the grid being linearized: an array either fails to broadcast or pairs up wavelengths which are not the same. `test_linearize` now asserts it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
roytsmart
force-pushed
the
perf/share-fit-trace
branch
from
August 28, 2026 15:30
fd0e4c4 to
8a7083a
Compare
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.
Depends on #211 and must merge after it. Opened against that branch so the diff shows only this change; retargeted to
mainimmediately, so deleting #211's branch on merge cannot close this PR.Why
linearizefits the distortion and the vignetting from the same rays, traced with identical arguments, and then traced a third time throughrayfunction_defaultfor the cosine of the angle at which light strikes the sensor. None of the three reads the intensity.What changes
distortionandvignettingkeep their behaviour; their fitting bodies move into_fit_distortionand_fit_vignetting, so a caller needing both can trace once and fit twice.directioncomes from those same rays.What moves, and what does not
directionwas evaluated ongrid_input.wavelength— a single value, 629.77 Å for ESIS — no matter which band was asked for. It is now averaged over the band being linearized. The old value was worse the further the requested band sat from that wavelength:It feeds
sensor.expose, which uses it for the path length through the depletion region, so this is a radiometric correction rather than a refactor artifact.The trap this had to avoid
The existing averaging line reads:
axis_wavelength_is derived fromgrid_input, which holds a scalar wavelength for ESIS, so it is(). That was harmless whiledirectioncame fromrayfunction_default, which has no wavelength axis either. Fed the shared trace, the axis survives:An array
directionis not merely different, it is broken.exposeindexes it by the cell centers of the scene's wavelength grid, which has nothing to do with the grid being linearized:So the average now names the wavelength axis explicitly, and
test_linearizeassertsdirectionis a scalar.Worth knowing while reviewing:
_linear_test's sensor is an ideal material that ignoresdirectionentirely (9000 photons in, 9000 electrons out, and the mismatched-shape case does not even raise), so none ofLinearSystem's own tests exercise it.Tests
Full suite: 17768 passed, 304 skipped, 17 xfailed.
_sequential.pyat 100% line coverage. Sixndfilterstests fail with a numbaReferenceError: underlying object has vanished, identically onmain— a pre-existing local flake, not from this branch.🤖 Generated with Claude Code