SimpleDistortionModel#

class optika.distortion.SimpleDistortionModel(plate_scale, dispersion, angle, reference)[source]#

Bases: AbstractLinearDistortionModel

A simple analytic distortion model consisting of a rotation of the field, an isotropic plate scale, and a linear spectral dispersion along the rotated \(x\) axis.

This captures the distortion of an idealized spectrograph: the field center at the reference wavelength maps to the reference position on the sensor, and other wavelengths are displaced along the dispersion direction.

Examples

Distort a grid of scene coordinates and plot the result on the sensor, colored by wavelength.

import matplotlib.pyplot as plt
import astropy.units as u
import named_arrays as na
import optika

model = optika.distortion.SimpleDistortionModel(
    plate_scale=1 * u.arcsec / u.pix,
    dispersion=2 * u.nm / u.pix,
    angle=15 * u.deg,
    reference=na.SpectralPositionalVectorArray(
        wavelength=550 * u.nm,
        position=na.Cartesian2dVectorArray(0, 0) * u.pix,
    ),
)

scene = na.SpectralPositionalVectorArray(
    wavelength=na.linspace(500, 600, axis="wavelength", num=3) * u.nm,
    position=na.Cartesian2dVectorLinearSpace(
        start=-10 * u.arcsec,
        stop=+10 * u.arcsec,
        axis=na.Cartesian2dVectorArray("field_x", "field_y"),
        num=5,
    ),
)

sensor = model.distort(scene)

fig, ax = plt.subplots(constrained_layout=True)
ax.set_aspect("equal")
for wavelength in scene.wavelength.ndarray:
    na.plt.scatter(
        sensor.position.x,
        sensor.position.y,
        where=scene.wavelength == wavelength,
        label=f"{wavelength}",
        ax=ax,
    )
ax.set_xlabel(f"detector $x$ ({na.unit(sensor.position.x):latex_inline})")
ax.set_ylabel(f"detector $y$ ({na.unit(sensor.position.y):latex_inline})")
ax.legend();
../_images/optika.distortion.SimpleDistortionModel_0_0.png

Attributes

angle

The angle of the dispersion direction with respect to the scene.

center

The reference point subtracted from the coordinates before applying matrix.

dispersion

The magnitude of the spectral dispersion, in units such as \(\text{nm} / \text{pix}\).

intercept

The constant offset added after applying matrix.

matrix

The linear part of the affine transformation.

plate_scale

The spatial plate scale, in units such as \(\text{arcsec} / \text{pix}\).

reference

The reference wavelength and the sensor position that the field center maps to at that wavelength.

Methods

__init__(plate_scale, dispersion, angle, ...)

distort(coordinates)

Convert scene coordinates to sensor coordinates.

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.SimpleDistortionModel
Parameters:
distort(coordinates)#

Convert scene coordinates to sensor coordinates.

Parameters:

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

Return type:

SpectralPositionalVectorArray

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)#

Convert sensor coordinates to scene coordinates.

Parameters:

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

Return type:

SpectralPositionalVectorArray

angle: Quantity | AbstractScalar = <dataclasses._MISSING_TYPE object>#

The angle of the dispersion direction with respect to the scene.

property center: SpectralPositionalVectorArray#

The reference point subtracted from the coordinates before applying matrix.

dispersion: Quantity | AbstractScalar = <dataclasses._MISSING_TYPE object>#

The magnitude of the spectral dispersion, in units such as \(\text{nm} / \text{pix}\).

property intercept: AbstractSpectralPositionalVectorArray#

The constant offset added after applying matrix.

property matrix: SpectralPositionalMatrixArray#

The linear part of the affine transformation.

plate_scale: Quantity | AbstractScalar = <dataclasses._MISSING_TYPE object>#

The spatial plate scale, in units such as \(\text{arcsec} / \text{pix}\).

reference: AbstractSpectralPositionalVectorArray = <dataclasses._MISSING_TYPE object>#

The reference wavelength and the sensor position that the field center maps to at that wavelength.