def djs_iterstat(InputArr, MaxIter=<NUM_LIT:10>, SigRej=<NUM_LIT>,<EOL>Max=None, Min=None, Mask=None, lineno=None):
NGood = InputArr.size<EOL>ArrShape = InputArr.shape<EOL>if NGood == <NUM_LIT:0>:<EOL><INDENT>imrow = _write_row_number(lineno=lineno, offset=<NUM_LIT:0>, pad=<NUM_LIT:1>)<EOL>LOG.warning('<STR_LIT>' + imrow)<EOL>return <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, None<EOL><DEDENT>if NGood == <NUM_LIT:1>:<EOL><INDENT>imrow = _write_row_number(lineno=lineno, offset=<NUM_LIT:0>, pad=<NUM_LIT:1>)<EOL>LOG.warning('<STR_LIT>'<EOL>'<STR_LIT>'.format(imrow))<EOL>return <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, None<EOL><DEDENT>if np.unique(InputArr).size == <NUM_LIT:1>:<EOL><INDENT>imrow = _write_row_number(lineno=lineno, offset=<NUM_LIT:0>, pad=<NUM_LIT:1>)<EOL>LOG.warning('<STR_LIT>'<EOL>'<STR_LIT>'.format(imrow))<EOL>return <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, None<EOL><DEDENT>if Max is None:<EOL><INDENT>Max = InputArr.max()<EOL><DEDENT>if Min is None:<EOL><INDENT>Min = InputArr.min()<EOL><DEDENT>if Mask is None:<EOL><INDENT>Mask = np.ones(ArrShape, dtype=np.byte)<EOL><DEDENT>else:<EOL><INDENT>Mask = Mask.copy()<EOL><DEDENT>Mask[InputArr > Max] = <NUM_LIT:0><EOL>Mask[InputArr < Min] = <NUM_LIT:0><EOL>FMean = np.sum(<NUM_LIT:1.0> * InputArr * Mask) / NGood<EOL>FSig  = np.sqrt(np.sum((<NUM_LIT:1.0> * InputArr - FMean) ** <NUM_LIT:2> * Mask) / (NGood - <NUM_LIT:1>))<EOL>NLast = -<NUM_LIT:1><EOL>Iter  = <NUM_LIT:0><EOL>NGood = np.sum(Mask)<EOL>if NGood < <NUM_LIT:2>:<EOL><INDENT>imrow = _write_row_number(lineno=lineno, offset=<NUM_LIT:0>, pad=<NUM_LIT:1>)<EOL>LOG.warning('<STR_LIT>'<EOL>'<STR_LIT>'.format(imrow))<EOL>return <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, None<EOL><DEDENT>SaveMask = Mask.copy()<EOL>if Iter >= MaxIter:  <EOL><INDENT>NLast = NGood<EOL><DEDENT>while (Iter < MaxIter) and (NLast != NGood) and (NGood >= <NUM_LIT:2>):<EOL><INDENT>LoVal = FMean - SigRej * FSig<EOL>HiVal = FMean + SigRej * FSig<EOL>Mask[InputArr < LoVal] = <NUM_LIT:0><EOL>Mask[InputArr > HiVal] = <NUM_LIT:0><EOL>NLast = NGood<EOL>npix = np.sum(Mask)<EOL>if npix >= <NUM_LIT:2>:<EOL><INDENT>FMean = np.sum(<NUM_LIT:1.0> * InputArr * Mask) / npix<EOL>FSig = np.sqrt(np.sum(<EOL>(<NUM_LIT:1.0> * InputArr - FMean) ** <NUM_LIT:2> * Mask) / (npix - <NUM_LIT:1>))<EOL>SaveMask = Mask.copy()  <EOL>NGood = npix<EOL>Iter += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>logical_mask = SaveMask.astype(np.bool)<EOL>if NLast > <NUM_LIT:1>:<EOL><INDENT>FMedian = np.median(InputArr[logical_mask])<EOL>NLast = NGood<EOL><DEDENT>else:<EOL><INDENT>FMedian = FMean<EOL><DEDENT>return FMean, FSig, FMedian, NLast, Iter, logical_mask<EOL>
Iterative sigma-clipping.

Parameters
----------
InputArr : `numpy.ndarray`
    Input image array.

MaxIter, SigRej : see `clean`

Max, Min : float
    Max and min values for clipping.

Mask : `numpy.ndarray`
    Mask array to indicate pixels to reject, in addition to clipping.
    Pixels where mask is zero will be rejected.
    If not given, all pixels will be used.

lineno : int or None
    Line number to be used in log and/or warning messages.

Returns
-------
FMean, FSig, FMedian, NPix : float
    Mean, sigma, and median of final result.

NIter : int
    Number of performed clipping iterations

BMask : `numpy.ndarray`
    Logical image mask from the final iteration.