PolynomialDistortionModel#
- class optika.distortion.PolynomialDistortionModel(coordinates_scene, coordinates_sensor, axis_wavelength, axis_field, degree=1, where=True)[source]#
Bases:
AbstractInterpolatedDistortionModelA distortion model which fits a polynomial to known scene/sensor coordinates.
The forward model (
distort()) is a polynomial fit mapping scene position to sensor position as a function of wavelength. The inverse model (undistort()) is a separate polynomial fit in the opposite direction, so the round trip is exact only to the accuracy of the two fits.Examples
Plot the fit residual of a distortion model with a deliberately underfit (linear) polynomial.
import numpy as np import astropy.units as u import named_arrays as na import optika scene = na.SpectralPositionalVectorArray( wavelength=na.linspace(500, 600, axis="wavelength", num=3) * u.nm, position=na.Cartesian2dVectorLinearSpace( start=-1 * u.deg, stop=+1 * u.deg, axis=na.Cartesian2dVectorArray("field_x", "field_y"), num=13, ), ) sensor = na.Cartesian2dVectorArray( x=scene.position.x * (10 * u.mm / u.deg) + scene.position.x**2 * (1 * u.mm / u.deg**2), y=scene.position.y * (10 * u.mm / u.deg) + scene.position.y**2 * (1 * u.mm / u.deg**2), ) model = optika.distortion.PolynomialDistortionModel( coordinates_scene=scene, coordinates_sensor=sensor, axis_wavelength="wavelength", axis_field=("field_x", "field_y"), degree=1, ) fig, ax = model.plot_residual() na.plt.set_aspect("equal", ax=ax);
Attributes
The logical axes corresponding to changing position in the scene.
The logical axis corresponding to changing wavelength.
The wavelength and position of each calibration point in the scene.
The position of each calibration point mapped onto the sensor.
The degree of the polynomial used to model the distortion.
The polynomial fit mapping scene position to sensor position.
The polynomial fit mapping sensor position back to scene position.
A boolean mask selecting which calibration points to use for fitting.
Methods
__init__(coordinates_scene, ...[, degree, where])distort(coordinates)Convert scene coordinates to sensor coordinates.
plot_residual([figsize, cmap, vmin, vmax])Plot the residual of the forward
fitas a function of field angle, with a separate subplot for each wavelength.to_string([prefix])Public-facing version of the
__repr__method that allows for defining a prefix string, which can be used to calculate how much whitespace to add to the beginning of each line of the result.undistort(coordinates)Convert sensor coordinates to scene coordinates.
Inheritance Diagram

- Parameters:
coordinates_scene (AbstractSpectralPositionalVectorArray)
coordinates_sensor (AbstractCartesian2dVectorArray)
axis_wavelength (str)
degree (int)
where (bool | AbstractScalar)
- distort(coordinates)[source]#
Convert scene coordinates to sensor coordinates.
- Parameters:
coordinates (AbstractSpectralPositionalVectorArray) – The wavelength and position of each point in the scene.
- Return type:
- plot_residual(figsize=None, cmap=None, vmin=None, vmax=None, **kwargs)[source]#
Plot the residual of the forward
fitas a function of field angle, with a separate subplot for each wavelength.The residual is the magnitude of the difference between the calibration sensor positions,
coordinates_sensor, and the positions predicted by the forward polynomial fit.- Parameters:
figsize (None | tuple[float, float]) – The size of the returned figure in inches. If
None, the size is chosen automatically from the number of wavelengths and the aspect ratio of the field of view.cmap (None | str | Colormap) – The colormap used to map the residual magnitude to colors.
vmin (None | int | float | complex | ndarray | Quantity | AbstractArray) – The residual value mapped to the lowest color. If
None, defaults to zero.vmax (None | int | float | complex | ndarray | Quantity | AbstractArray) – The residual value mapped to the highest color. If
None, defaults to the maximum residual.kwargs – Additional keyword arguments passed to
named_arrays.plt.pcolormesh().
- Return type:
- to_string(prefix=None)#
Public-facing version of the
__repr__method that allows for defining a prefix string, which can be used to calculate how much whitespace to add to the beginning of each line of the result.
- undistort(coordinates)[source]#
Convert sensor coordinates to scene coordinates.
- Parameters:
coordinates (AbstractSpectralPositionalVectorArray) – The wavelength and sensor position of each point.
- Return type:
- axis_field: tuple[str, str] = <dataclasses._MISSING_TYPE object>#
The logical axes corresponding to changing position in the scene.
- axis_wavelength: str = <dataclasses._MISSING_TYPE object>#
The logical axis corresponding to changing wavelength.
- coordinates_scene: AbstractSpectralPositionalVectorArray = <dataclasses._MISSING_TYPE object>#
The wavelength and position of each calibration point in the scene.
- coordinates_sensor: AbstractCartesian2dVectorArray = <dataclasses._MISSING_TYPE object>#
The position of each calibration point mapped onto the sensor.
- property fit: PolynomialFitFunctionArray#
The polynomial fit mapping scene position to sensor position.
- property fit_inverse: PolynomialFitFunctionArray#
The polynomial fit mapping sensor position back to scene position.
- where: bool | AbstractScalar = True#
A boolean mask selecting which calibration points to use for fitting.