def clean_streak(image, stat="<STR_LIT>", maxiter=<NUM_LIT:15>, sigrej=<NUM_LIT>,<EOL>lower=None, upper=None, binwidth=<NUM_LIT>, mask=None,<EOL>rpt_clean=<NUM_LIT:0>, atol=<NUM_LIT>, verbose=True):
<EOL>try:<EOL><INDENT>from stsci.imagestats import ImageStats<EOL><DEDENT>except ImportError:<EOL><INDENT>ImageStats = None<EOL><DEDENT>if mask is not None and image.science.shape != mask.shape:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>Nrpt = <NUM_LIT:0><EOL>warn_maxiter = False<EOL>NUpdRows = <NUM_LIT:0><EOL>NMaxIter = <NUM_LIT:0><EOL>STDDEVCorr = <NUM_LIT:0.0><EOL>MaxCorr = <NUM_LIT:0.0><EOL>wmean = <NUM_LIT:0.0><EOL>stat = stat.lower().strip()<EOL>if stat not in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>corr = np.empty(image.science.shape[<NUM_LIT:0>], dtype=np.float64)<EOL>cumcorr = np.zeros(image.science.shape[<NUM_LIT:0>], dtype=np.float64)<EOL>cnpix = np.zeros(image.science.shape[<NUM_LIT:0>], dtype=np.int)<EOL>corr_scale = np.empty(image.science.shape[<NUM_LIT:0>], dtype=np.float64)<EOL>npix = np.empty(image.science.shape[<NUM_LIT:0>], dtype=np.int)<EOL>sigcorr2 = np.zeros(image.science.shape[<NUM_LIT:0>], dtype=np.float64)<EOL>updrows = np.zeros(image.science.shape[<NUM_LIT:0>], dtype=np.int)<EOL>imerr2 = image.err**<NUM_LIT:2><EOL>nonconvi0 = np.arange(image.science.shape[<NUM_LIT:0>])<EOL>corr0 = np.zeros(image.science.shape[<NUM_LIT:0>], dtype=np.float64)<EOL>if stat == '<STR_LIT>':<EOL><INDENT>def getcorr(): return (<NUM_LIT> * SMedian - <NUM_LIT> * SMean)<EOL><DEDENT>elif stat == '<STR_LIT>':<EOL><INDENT>def getcorr(): return (<NUM_LIT> * SMedian - <NUM_LIT> * SMean)<EOL><DEDENT>elif stat == '<STR_LIT>':<EOL><INDENT>def getcorr(): return (SMean)<EOL><DEDENT>elif stat == '<STR_LIT>':<EOL><INDENT>def getcorr(): return (SMedian)<EOL><DEDENT>elif stat == '<STR_LIT>':<EOL><INDENT>if ImageStats is None:<EOL><INDENT>raise ImportError('<STR_LIT>')<EOL><DEDENT>def getcorr():<EOL><INDENT>imstat = ImageStats(image.science[i][BMask], '<STR_LIT>',<EOL>lower=lower, upper=upper, nclip=<NUM_LIT:0>)<EOL>assert(imstat.npix == NPix)<EOL>return (imstat.mode)<EOL><DEDENT><DEDENT>elif stat == '<STR_LIT>':<EOL><INDENT>if ImageStats is None:<EOL><INDENT>raise ImportError('<STR_LIT>')<EOL><DEDENT>def getcorr():<EOL><INDENT>imstat = ImageStats(image.science[i][BMask], '<STR_LIT>',<EOL>lower=lower, upper=upper, nclip=<NUM_LIT:0>)<EOL>assert(imstat.npix == NPix)<EOL>return (imstat.midpt)<EOL><DEDENT><DEDENT>nmax_rpt = <NUM_LIT:1> if rpt_clean is None else max(<NUM_LIT:1>, rpt_clean+<NUM_LIT:1>)<EOL>for rpt in range(nmax_rpt):<EOL><INDENT>Nrpt += <NUM_LIT:1><EOL>if verbose:<EOL><INDENT>if Nrpt <= <NUM_LIT:1>:<EOL><INDENT>if nmax_rpt > <NUM_LIT:1>:<EOL><INDENT>LOG.info("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>LOG.info("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>LOG.info("<STR_LIT>"<EOL>"<STR_LIT>".format(Nrpt - <NUM_LIT:1>))<EOL><DEDENT><DEDENT>corr[:] = <NUM_LIT:0.0><EOL>corr_scale[:] = <NUM_LIT:0.0><EOL>npix[:] = <NUM_LIT:0><EOL>tcorr = <NUM_LIT:0.0><EOL>tnpix = <NUM_LIT:0><EOL>tnpix2 = <NUM_LIT:0><EOL>NMaxIter = <NUM_LIT:0><EOL>mask_arr = None<EOL>for i in range(image.science.shape[<NUM_LIT:0>]):<EOL><INDENT>if mask is not None:<EOL><INDENT>mask_arr = mask[i]<EOL><DEDENT>SMean, SSig, SMedian, NPix, NIter, BMask = djs_iterstat(<EOL>image.science[i], MaxIter=maxiter, SigRej=sigrej,<EOL>Min=lower, Max=upper, Mask=mask_arr, lineno=i+<NUM_LIT:1><EOL>)<EOL>if NPix > <NUM_LIT:0>:<EOL><INDENT>corr[i] = getcorr()<EOL>npix[i] = NPix<EOL>corr_scale[i] = <NUM_LIT:1.0> / np.average(image.invflat[i][BMask])<EOL>sigcorr2[i] = corr_scale[i]**<NUM_LIT:2> *np.sum((image.err[i][BMask])**<NUM_LIT:2>)/NPix**<NUM_LIT:2><EOL>cnpix[i] = NPix<EOL>tnpix += NPix<EOL>tnpix2 += NPix*NPix<EOL>tcorr += corr[i] * NPix<EOL><DEDENT>if NIter > NMaxIter:<EOL><INDENT>NMaxIter = NIter<EOL><DEDENT><DEDENT>if tnpix <= <NUM_LIT:0>:<EOL><INDENT>LOG.warning('<STR_LIT>')<EOL>return False, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0.0>, <NUM_LIT:0.0>, <NUM_LIT:0><EOL><DEDENT>if NMaxIter >= maxiter:<EOL><INDENT>warn_maxiter = True<EOL><DEDENT>wmean = tcorr / tnpix<EOL>Bkgrnd = wmean<EOL>corr[npix > <NUM_LIT:0>] -= wmean<EOL>corr *= corr_scale<EOL>trim_npix = npix[npix > <NUM_LIT:0>]<EOL>trim_corr = corr[npix > <NUM_LIT:0>]<EOL>cwmean = np.sum(trim_npix * trim_corr) / tnpix<EOL>current_max_corr = np.amax(np.abs(trim_corr - cwmean))<EOL>wvar = np.sum(trim_npix * (trim_corr - cwmean) ** <NUM_LIT:2>) / tnpix<EOL>uwvar = wvar / (<NUM_LIT:1.0> - float(tnpix2) / float(tnpix) ** <NUM_LIT:2>)<EOL>STDDEVCorr = np.sqrt(uwvar)<EOL>cumcorr += corr<EOL>for i in range(image.science.shape[<NUM_LIT:0>]):<EOL><INDENT>if npix[i] < <NUM_LIT:1>:<EOL><INDENT>continue<EOL><DEDENT>updrows[i] = <NUM_LIT:1><EOL>ffdark = (image.dark[i] + image.flash[i]) * image.invflat[i]<EOL>t1 = np.maximum(image.science[i] + ffdark, <NUM_LIT:0.0>)<EOL>truecorr = corr[i] * image.invflat[i]<EOL>image.science[i] -= truecorr<EOL>t2 = np.maximum(image.science[i] + ffdark, <NUM_LIT:0.0>)<EOL>T = (t1 - t2) * image.invflat[i]<EOL>imerr2[i] -= T<EOL>image.err[i] = np.sqrt(np.abs(imerr2[i]))<EOL><DEDENT>if atol is not None:<EOL><INDENT>if current_max_corr < atol:<EOL><INDENT>break<EOL><DEDENT>nonconvi = np.nonzero(np.abs(corr) > atol)[<NUM_LIT:0>]<EOL>nonconvi_int = np.intersect1d(nonconvi, nonconvi0)<EOL>if (nonconvi.shape[<NUM_LIT:0>] == nonconvi0.shape[<NUM_LIT:0>] and<EOL>nonconvi.shape[<NUM_LIT:0>] == nonconvi_int.shape[<NUM_LIT:0>] and<EOL>np.all(corr0[nonconvi]*corr[nonconvi] < <NUM_LIT:0.0>) and Nrpt > <NUM_LIT:1>):<EOL><INDENT>LOG.warning("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(nonconvi.shape[<NUM_LIT:0>]))<EOL>break<EOL><DEDENT>nonconvi0 = nonconvi.copy()<EOL>corr0 = corr.copy()<EOL><DEDENT>if verbose:<EOL><INDENT>if Nrpt <= <NUM_LIT:1>:<EOL><INDENT>LOG.info("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>LOG.info("<STR_LIT>"<EOL>"<STR_LIT>".format(Nrpt - <NUM_LIT:1>))<EOL><DEDENT><DEDENT><DEDENT>if verbose and Nrpt > <NUM_LIT:1>:<EOL><INDENT>LOG.info('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>LOG.info('<STR_LIT>'<EOL>'<STR_LIT>'.format(STDDEVCorr))<EOL>LOG.info('<STR_LIT>'<EOL>'<STR_LIT>'.format(current_max_corr))<EOL><DEDENT>truecorr_sig2 = ((sigcorr2 * (image.invflat ** <NUM_LIT:2>).T).T).astype(image.err.dtype)  <EOL>image.err[:, :] = np.sqrt(np.abs(imerr2 + truecorr_sig2))<EOL>if warn_maxiter:<EOL><INDENT>LOG.warning(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(maxiter))<EOL><DEDENT>trim_cnpix = cnpix[cnpix > <NUM_LIT:0>]<EOL>trim_cumcorr = cumcorr[cnpix > <NUM_LIT:0>]<EOL>tcnpix = np.sum(trim_cnpix)<EOL>tcnpix2 = np.sum(trim_cnpix ** <NUM_LIT:2>)<EOL>cwmean = np.sum(trim_cnpix * trim_cumcorr) / tcnpix<EOL>trim_cumcorr -= cwmean<EOL>wvar = np.sum(trim_cnpix * trim_cumcorr ** <NUM_LIT:2>) / tcnpix<EOL>uwvar = wvar / (<NUM_LIT:1.0> - float(tcnpix2) / float(tcnpix) ** <NUM_LIT:2>)<EOL>STDDEVCorr = np.sqrt(uwvar)<EOL>MaxCorr = np.amax(np.abs(trim_cumcorr))<EOL>NUpdRows = np.sum(updrows)<EOL>return True, NUpdRows, NMaxIter, Bkgrnd, STDDEVCorr, MaxCorr, Nrpt-<NUM_LIT:1><EOL>
Apply destriping algorithm to input array.

Parameters
----------
image : `StripeArray` object
    Arrays are modifed in-place.

stat : str
    Statistics for background computations
    (see :py:func:`clean` for more details)

mask : `numpy.ndarray`
    Mask array. Pixels with zero values are masked out.

maxiter, sigrej : see `clean`

rpt_clean : int
    An integer indicating how many *additional* times stripe cleaning
    should be performed on the input image. Default = 0.

atol : float, None
    The threshold for maximum absolute value of bias stripe correction
    below which repeated cleanings can stop. When `atol` is `None`
    cleaning will be repeated `rpt_clean` number of times.
    Default = 0.01 [e].

verbose : bool
    Print informational messages. Default = True.

Returns
-------
Success : bool
    Indicates successful execution.

NUpdRows : int
    Number of updated rows in the image.

NMaxIter : int
    Maximum number of clipping iterations performed on image rows.

Bkgrnd, STDDEVCorr, MaxCorr : float
    Background, standard deviation of corrections and maximum correction
    applied to the non-flat-field-corrected (i.e., RAW) image rows.

Nrpt : int
    Number of *additional* (performed *after* initial run) cleanings.