spatial_shift

sofia_redux.instruments.exes.spatial_shift.spatial_shift(data, header, flat, variance, illum=None, good_frames=None, sharpen=False)[source]

Shift spectra for spatial alignment.

A shift is derived based on correlation with average spatial profile from all frames. The spatial template is generated using make_template. For each input frame, the image is collapsed over the spectral dimension, weighting by an inverse flat (squared), shifted by a small amount, then added to the collapsed spatial template. This signal is calculated for all spatial shifts of up to 4 pixels: the spatial shift chosen is the one that maximizes the signal.

Alternately, if sharpen is not set, the value maximized is the signal-to-noise (the above signal, divided by the collapsed uncertainty).

The image is then shifted by the calculated value in the spatial direction, i.e. along the y-axis. Input data is assumed to be undistorted and rotated to orient spectra along the x-axis.

Parameters:
datanumpy.ndarray

Data cube, [nframe, nspec, nspat].

headerfits.Header

Header from FITS file.

flatnumpy.ndarray

Processed flat image, [nspec, nspat].

variancenumpy.ndarray

Variance planes corresponding to data, [nframe, nspec, nspat].

illumnumpy.ndarray

Indicating illuminated regions of the frame, [nspec, nspat]. 1=illuminated, 0=unilluminated, -1=pixel that does not correspond to any region in the raw frame.

good_framesarray-like, optional

Array of indices of good frames. If provided, any frame not in good_frames will be skipped.

sharpenbool, optional

If set, signal will be maximized, rather than the signal-to-noise ratio.

Returns:
data, variance2-tuple of numpy.ndarray

Shifted data cube [nframe, nspec, nspat] and updated variance data [nframe, nspec, nspat].