distortion¶
Distortion utilities.
StructuredGrid(xy) |
A structured 2D-grid, stored as a complex 2D-array. |
GeometricDistortion([center, Kcoeffs, ...]) |
Brown-Conrady (achromatic) distortion model. |
ChromaticDistortion([wref, coeffs]) |
A polynomial description of Transverse Chromatic Distortion. |
-
class
spectrogrism.distortion.StructuredGrid(xy)[source]¶ A structured 2D-grid, stored as a complex 2D-array.
create(nx, ny[, step, offset, rotation])Create a regular rectangular grid. reorder(signature)Manipulate self.xy to match signature. plot([ax, label, color])Plot structured grid. estimate_parameters([rmin, frac, rescale, fig])Estimate regular grid parameters from triangulation analysis. rms(xy)Compute RMS distance to 2D-array. adjust_distortion(other, gdist[, scale, ...])Adjust geometric distortion to match other (compatible) grid. plot_offsets(other[, ax, units])Plot offset between self and other grid (used as reference). -
classmethod
create(nx, ny, step='auto', offset=0, rotation=0.0)[source]¶ Create a regular rectangular grid.
Parameters:
-
nx¶
-
ny¶
-
x¶ Flattened x-coordinate array.
-
y¶ Flattened y-coordinate array.
-
signature¶ Return a 4-character signature string such as ‘x+y-‘.
Standard order – x increasing along 1st axis and y increasing along 0th axis – corresponds to ‘x+y+’. ‘y-x+’ corresponds to a transposed coordinate array, with y decreasing along the 1st axis, and x increasing along the 0th axis.
Noting ‘+.’ a mean finite difference where the real part is positive and larger (in absolute value) than the imaginary part, one has the following correspondance:
fd[0] | +. -. .+ .- fd[1] | ------+----------------------- +. | y+x+ y-x+ -. | y+x- y-x- .+ | x+y+ x-y+ .- | x+y- x-y-
-
estimate_parameters(rmin=0.1, frac=0.1, rescale=False, fig=None)[source]¶ Estimate regular grid parameters from triangulation analysis.
Parameters: - rmin (float) – minimal circle ratio (see
matplotlib.tri.TriAnalyzer.get_flat_tri_mask()) - frac (float) – fraction of edges used for distortion parameters
- rescale (bool) – rescale long edges (not trustworthy for significantly distorted grid)
- fig (matplotlib.pyplot.Figure) – produde a control plot if not None
Returns: (step, rotation [rad], complex offset, complex center of distortion)
- rmin (float) – minimal circle ratio (see
-
rms(xy)[source]¶ Compute RMS distance to 2D-array.
Note
intput grids are supposed to be compatible both in shape and signature. RMS cannot be computed or is meaningless otherwise.
-
adjust_distortion(other, gdist, scale=False, rotation=False, offset=False, **options)[source]¶ Adjust geometric distortion to match other (compatible) grid.
If scale (resp. rotation and offset), the grid scale (resp. rotation and offset) is adjusted simultaneously.
Other options are transmitted to
Minuitinitialization.
-
classmethod
-
class
spectrogrism.distortion.GeometricDistortion(center=0, Kcoeffs=[], Pcoeffs=[], scale=1, rotation=0, offset=0)[source]¶ Brown-Conrady (achromatic) distortion model.
\[\begin{split}x_d &= x_u \times (1 + K_1 r^2 + K_2 r^4 + \ldots) \\ &+ \left(P_2(r^2 + 2x_u^2) + 2P_1 x_u y_u\right) (1 + P_3 r^2 + P_4 r^4 + \ldots) \\ y_d &= y_u \times (1 + K_1r^2 + K_2r^4 + \ldots) \\ &+ \left(P_1(r^2 + 2y_u^2) + 2P_2 x_u y_u\right) (1 + P_3 r^2 + P_4 r^4 + \ldots)\end{split}\]where:
- \(z_u = x_u + j y_u\) is the undistorted complex position,
- \(z_d = x_d + j y_d\) is the distorted complex position,
- \(z_0 = x_0 + j y_0\) is the complex center of distortion,
- \(r = |z_u - z_0|\) is the undistorted distance to CoD.
The K-coefficients (resp. P-coefficients) model the radial (resp. tangential) distortion.
Note there’s a possibility to rescale (scale s + rotation \(\alpha\) + offset \(\delta z\)) the input (undistorted) positions before applying the distortion pattern (see
GeometricDistortion.rescale()).Reference: Optical distortion
forward(xyu)Apply distortion to undistorted (rescaled) positions. backward(xyd[, lcol])Correct distortion from distorted complex positions. rescale(xy)Rescale input complex positions. unscale(xy)Unscale output complex positions. plot([xy, ax])Plot distortions for a 2D-grid of complex positions. Initialize from center of distortion and K- and P-coefficients.
Parameters: - center (complex) – complex position of center of distortion [m]
- Kcoeffs (list) – radial distortion coefficients
- Pcoeffs (list) – tangential distortion coefficients (empty or length >= 2)
- scale (float) – scaling to be applied to input coordinates
- rotation (float) – rotation to be applied to input coordinates [rad]
- offset (complex) – offset to be applied to input coordinates [m]
-
center= None¶ Center of distortion (complex) [m]
-
scale= None¶ Coordinate scaling
-
rotation= None¶ Coordinate rotation [rad]
-
offset= None¶ Coordinate complex offset [m]
-
x0¶ x-coordinate of center of distortion.
-
y0¶ y-coordinate of center of distortion.
-
Kcoeffs¶ Radial coefficients.
-
Pcoeffs¶ Tangential coefficients.
-
class
spectrogrism.distortion.ChromaticDistortion(wref=1e-06, coeffs=[])[source]¶ A polynomial description of Transverse Chromatic Distortion.
The Transverse Chromatic Aberration (so-called lateral color) occurs when different wavelengths are focused at different positions in the focal plane.
Reference: Chromatic aberration
See also: Klein, Brauers & Aach, 2010, for a more detailed modeling of Transversal Chromatic Aberrations.
coeffsExpose non-null coefficients \([c_{i \geq 1}]\). amplitude(wavelengths)Compute amplitude of the (radial) chromatic distortion. Initialize from reference wavelength and lateral color coefficients.
\[dr = \sum_{i=1}^N c_i (\lambda - \lambda_{\mathrm{ref}})^i\]Note that \(c_0 = 0\).
Parameters: -
wref= None¶ Reference wavelength [m]
-
coeffs¶ Expose non-null coefficients \([c_{i \geq 1}]\).
-
amplitude(wavelengths)[source]¶ Compute amplitude of the (radial) chromatic distortion.
Parameters: wavelengths (numpy.ndarray) – wavelengths [m] Returns: lateral color radial amplitude
-