Add optika.distortion.PolynomialDistortionModel which can interpolate between object and sensor coordinates.#154
Merged
Conversation
Introduce the `optika.distortion` subpackage, which maps scene coordinates (wavelength + field position) to sensor coordinates and back: - `AbstractDistortionModel` defines the `distort`/`undistort` interface. - `AbstractInterpolatedDistortionModel` adds the calibration-point interface (`coordinates_scene`, `coordinates_sensor`, axes). - `PolynomialDistortionModel` fits forward and inverse polynomials (with a mean-centered reference for conditioning) and exposes them as the public `fit`/`fit_inverse` cached properties. Register the subpackage in `optika/__init__.py` and add round-trip tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The distortion model relies on named-arrays features (the polynomial fit `center` field) that are only available in named-arrays 1.5+. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #154 +/- ##
==========================================
+ Coverage 99.27% 99.29% +0.01%
==========================================
Files 108 111 +3
Lines 5391 5537 +146
==========================================
+ Hits 5352 5498 +146
Misses 39 39
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Plot the magnitude of the forward-fit residual (calibration sensor positions minus fit predictions) as a function of field angle using `na.plt.pcolormesh`, with a separate subplot for each wavelength and a shared colorbar. Update the class example to demonstrate it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
optika.distortion, a polynomial model of optical distortionoptika.distortion.PolynomialDistortionModel which can interpolate between object and sensor coordinates.
Replace the if/else branch selecting the subplot count with `na.shape(wavelength).get(axis_wavelength, 1)`, which the existing tests fully exercise (the scalar-wavelength else-branch was never hit). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Use a non-interactive matplotlib backend in CI so plotting tests (e.g. `PolynomialDistortionModel.plot_residual`) run headless, matching the named-arrays workflow. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Make the example sensor distortion quadratic in both field components, increase the field sampling, and set the subplot aspect ratio to equal. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`vmin`/`vmax` set the residual color limits (defaulting to zero and the maximum residual). `figsize` overrides the figure size; when omitted it is now derived automatically from the number of wavelength subplots and the field-of-view aspect ratio (via `field.x.ptp() / field.y.ptp()`). Extend the test to exercise the new arguments. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <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.
Summary
Adds the
optika.distortionsubpackage for mapping scene coordinates (wavelength + field position) to sensor coordinates and back.AbstractDistortionModel— defines thedistort/undistortinterface. Distortion carries wavelength alongside position (the scene→sensor mapping generally depends on wavelength, e.g. spectrograph dispersion), so the two methods are inverses only up to model accuracy.AbstractInterpolatedDistortionModel— adds the calibration-point interface (coordinates_scene,coordinates_sensor,axis_wavelength,axis_field).PolynomialDistortionModel— fits separate forward and inverse polynomials viana.PolynomialFitFunctionArray, using a mean-centered reference (center=inputs.mean(...)) for numerical conditioning. The underlying fits are exposed as the publicfit/fit_inversecached properties for introspection (coefficients, rms, etc.).Registers the subpackage in
optika/__init__.py.Notes
This factors the distortion concept into a reusable object. The inline polynomial-distortion logic in
systems/_interpolated.py(distortion/distortion_inverse) is a natural follow-up to migrate onto this abstraction.Testing
pytest optika/distortion/_distortion_test.py— 22 passed (round-trip, type, and fit-introspection tests acrossdegree∈ {1, 2}).black --checkandruff checkclean.🤖 Generated with Claude Code