coadd

sofia_redux.instruments.exes.coadd.coadd(data, header, flat, variance, illum=None, weights=None, good_frames=None, weight_mode=None, std_wt=False, threshold=0)[source]

Combine individual frames to increase signal-to-noise.

First, a template of the spectrum is created from all frames, averaging in the spectral direction. By default, all input frames are weighted by their correlation with this spatial template, so that if a frame is unusually noisy had some other error, it will not contribute significantly to the coadded frame. If this is not desired, an unweighted coadd can be performed, or the user can directly specify the weights to use.

The weighted frames are then summed to effect a weighted mean of the input data. If the threshold parameter is provided, outlier rejection is additionally performed before the weighted mean. If provided, the variance is propagated accordingly.

Parameters:
datanumpy.ndarray

3D data cube [nframe, ny, nx]. Input data is assumed to be distortion corrected and rotated as needed to align the spectral direction along the x-axis.

headerfits.Header

Header of FITS file. Will be updated in place.

flatnumpy.ndarray

2D processed flat, as produced by makeflat [ny, nx].

variancenumpy.ndarray

3D variance cube [nframe, ny, nx]. Will be updated in place.

illumnumpy.ndarray of int, optional

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

weightsarray-like, optional

Array [nframe] of fractional weights to use for input frames. If a weight is set to zero the frame will be skipped. Must add up to 1.0. If not provided, weights will be calculated for all frames.

good_framesarray-like, optional

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

weight_mode{‘unweighted’, ‘useweights’, None}, optional

If ‘unweighted’, all good frames will be given equal weight. If ‘useweights’, the weights array will be used to weight the frames. Otherwise, weights will be calculated from a correlation with the spatial template.

std_wtbool, optional

If set, frames will be weighted by the square root of their variance planes. Otherwise, they will be weighted by the flat.

thresholdfloat, optional

If >0, will be used as an outlier rejection threshold in the mean combination.

Returns:
coadded_data, coadded_variancenumpy.ndarray, numpy.ndarray

The coadded data and variance, both [ny,nx].