derive_tort

sofia_redux.instruments.exes.derive_tort.derive_tort(data, header, maxiter=5, fixed=False, edge_method='deriv', custom_wavemap=None, top_pixel=None, bottom_pixel=None, start_pixel=None, end_pixel=None)[source]

Derive distortion parameters and identify orders and illuminated regions.

The input flat is first undistorted (tort) using default parameters. For cross-dispersed data, the distortion is tested and (optionally) optimized by doing the following:

  1. Enhance the edges in the image, using edge_method.

  2. Take the 2D FFT of the resulting image.

  3. Use the power maxima in the FFT image to determine the order spacing.

  4. Calculate the rotation angle from the FFT.

  5. If the angle is not close to zero, use it to correct the krot parameter and redo the distortion correction by reiterating this algorithm.

This process must be closely monitored: if the flat frame has insufficient signal, or the optical parameters used to calculate the distortion correction are insufficiently accurate, the spacing and rotation angle may be wrongly calculated at this step.

Parameters:
datanumpy.ndarray

2D image [nspec, nspat], typically a blackbody flat frame.

headerfits.Header

FITS header for the flat file containing distortion parameters.

maxiterint, optional

The maximum number of iterations to use while optimizing distortion parameters.

fixedbool, optional

If True, will not attempt to optimize distortion parameters.

edge_method{‘deriv’, ‘sqderiv’, ‘sobel’}, optional

Sets the edge enhancement method for optimizing the cross-dispersed distortion parameters. May be one derivative (‘deriv’), squared derivative (‘sqderiv’), or Sobel (‘sobel’).

custom_wavemapstr or bool, optional

Filename for a text file containing explicit order edges for a cross-dispersed mode, as whitespace-separated integers indicating bottom, top, left, and right edges for each order (one per line). If set, it is used to directly set the order mask for a cross-dispersed mode. If set to a value other than a string or None, a ‘customWVM.dat’ file is expected in the current directory.

top_pixelint, optional

If provided, is used to directly set the top edge of the order. Used for single-order modes only (medium, low); ignored for cross-dispersed modes.

bottom_pixelint, optional

If provided, is used to directly set the bottom edge of the order. Used for single-order modes only (medium, low); ignored for cross-dispersed modes.

start_pixelint, optional

If provided, is used to directly set the left edge of all orders. May be used for either single-order or cross-dispersed modes.

end_pixelint, optional

If provided, is used to directly set the right edge of all orders. May be used for either single-order or cross-dispersed modes.

Returns:
tortdata, tortillum2-tuple of numpy.ndarray

Undistorted flat data and illumination array. Both have shape [nspec, nspat]. The illumination array contains integer values with 1 = illuminated, 0 = unilluminated, -1 = pixel that does not correspond to any region in the raw frame (after distortion correction).