PolynomialDistortionModel#

class optika.distortion.PolynomialDistortionModel(coordinates_scene, coordinates_sensor, axis_wavelength, axis_field, degree=1, where=True)[source]#

Bases: AbstractInterpolatedDistortionModel

A 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);
../_images/optika.distortion.PolynomialDistortionModel_0_0.png

Attributes

axis_field

The logical axes corresponding to changing position in the scene.

axis_wavelength

The logical axis corresponding to changing wavelength.

coordinates_scene

The wavelength and position of each calibration point in the scene.

coordinates_sensor

The position of each calibration point mapped onto the sensor.

degree

The degree of the polynomial used to model the distortion.

fit

The polynomial fit mapping scene position to sensor position.

fit_inverse

The polynomial fit mapping sensor position back to scene position.

where

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 fit as 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

Inheritance diagram of optika.distortion.PolynomialDistortionModel
Parameters:
distort(coordinates)[source]#

Convert scene coordinates to sensor coordinates.

Parameters:

coordinates (AbstractSpectralPositionalVectorArray) – The wavelength and position of each point in the scene.

Return type:

SpectralPositionalVectorArray

plot_residual(figsize=None, cmap=None, vmin=None, vmax=None, **kwargs)[source]#

Plot the residual of the forward fit as 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:
Return type:

tuple[Figure, ScalarArray]

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.

Parameters:

prefix (None | str) – an optional string, the length of which is used to calculate how much whitespace to add to the result.

Return type:

str

undistort(coordinates)[source]#

Convert sensor coordinates to scene coordinates.

Parameters:

coordinates (AbstractSpectralPositionalVectorArray) – The wavelength and sensor position of each point.

Return type:

SpectralPositionalVectorArray

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.

degree: int = 1#

The degree of the polynomial used to model the distortion.

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.