clean

sofia_redux.instruments.exes.clean.clean(data, header, std, mask=None, radius=10, threshold=20.0, propagate_nan=False)[source]

Correct bad pixels.

Bad pixels to correct may be indicated in an input mask, with good values indicated with 1 or True and bad values indicated with 0 or False.

Bad pixels may also be identified from a reference bad pixel mask on disk. The filename should be passed in as header[‘BPM’]. In this FITS image, pixels that are known to be bad are marked with a value of 0; good pixels are marked with a value of 1.

Alternatively, bad pixels may be identified from their noise characteristics: if the standard deviation associated with a pixel is greater than a threshold value times the mean standard deviation for the frame, then it is marked as a bad pixel. Bad pixels are corrected by using neighboring good values to linearly interpolate over the bad ones. The search for good pixels checks first in the y-direction, then in the x-direction. If good pixels cannot be identified within a 10-pixel radius, then the bad pixel will not be corrected. If there is a different uncertainty frame for each input data frame, this algorithm should be run in a loop on each frame individually.

Parameters:
datanumpy.ndarray

Data cube of shape (nframe, nspec, nspat) or image (nspec, nspat).

headerfits.Header

Header associated with the input data. Will be updated in-place.

stdnumpy.ndarray

2D or 3D uncertainty array (i.e. sqrt(variance)) of shape (nspec, nspat) or (nframe, nspec, nspat). If a 2D array is passed in, it will be applied to all frames.

masknumpy.ndarray of int or bool, optional

Bad pixel array of shape (nspec, nspat) or (nframe, nspec, nspat) indicating pixels to correct (good=1, bad=0). If not None, will be updated with additional bad pixels found. It is permitted for a 2D mask to be applied over all frames.

radiusint or array-like of int, optional

The maximum distance over which to perform interpolation. If an array is supplied, this is the maximum distance for each dimension in numpy (row, col) order (y, x).

thresholdfloat, optional

Threshold for bad pixel identification, as a factor to multiply by the standard deviation.

propagate_nanbool, optional

If True, bad pixels in the data will be replaced by NaN rather than interpolated over.

Returns:
data, stdnumpy.ndarray, numpy.ndarray

The cleaned data and error.