def destripe_plus(inputfile, suffix='<STR_LIT>', stat='<STR_LIT>', maxiter=<NUM_LIT:15>,<EOL>sigrej=<NUM_LIT>, lower=None, upper=None, binwidth=<NUM_LIT>,<EOL>scimask1=None, scimask2=None,<EOL>dqbits=None, rpt_clean=<NUM_LIT:0>, atol=<NUM_LIT>,<EOL>cte_correct=True, clobber=False, verbose=True):
<EOL>from stsci.tools import parseinput<EOL>try:<EOL><INDENT>from stsci.tools.bitmask import interpret_bit_flags<EOL><DEDENT>except ImportError:<EOL><INDENT>from stsci.tools.bitmask import (<EOL>interpret_bits_value as interpret_bit_flags<EOL>)<EOL><DEDENT>flist = parseinput.parseinput(inputfile)[<NUM_LIT:0>]<EOL>if isinstance(scimask1, str):<EOL><INDENT>mlist1 = parseinput.parseinput(scimask1)[<NUM_LIT:0>]<EOL><DEDENT>elif isinstance(scimask1, np.ndarray):<EOL><INDENT>mlist1 = [scimask1.copy()]<EOL><DEDENT>elif scimask1 is None:<EOL><INDENT>mlist1 = []<EOL><DEDENT>elif isinstance(scimask1, list):<EOL><INDENT>mlist1 = []<EOL>for m in scimask1:<EOL><INDENT>if isinstance(m, np.ndarray):<EOL><INDENT>mlist1.append(m.copy())<EOL><DEDENT>elif isinstance(m, str):<EOL><INDENT>mlist1 += parseinput.parseinput(m)[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if isinstance(scimask2, str):<EOL><INDENT>mlist2 = parseinput.parseinput(scimask2)[<NUM_LIT:0>]<EOL><DEDENT>elif isinstance(scimask2, np.ndarray):<EOL><INDENT>mlist2 = [scimask2.copy()]<EOL><DEDENT>elif scimask2 is None:<EOL><INDENT>mlist2 = []<EOL><DEDENT>elif isinstance(scimask2, list):<EOL><INDENT>mlist2 = []<EOL>for m in scimask2:<EOL><INDENT>if isinstance(m, np.ndarray):<EOL><INDENT>mlist2.append(m.copy())<EOL><DEDENT>elif isinstance(m, str):<EOL><INDENT>mlist2 += parseinput.parseinput(m)[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>n_input = len(flist)<EOL>n_mask1 = len(mlist1)<EOL>n_mask2 = len(mlist2)<EOL>if n_input == <NUM_LIT:0>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>')<EOL><DEDENT>if n_mask1 == <NUM_LIT:0>:<EOL><INDENT>mlist1 = [None] * n_input<EOL><DEDENT>elif n_mask1 != n_input:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if n_mask2 == <NUM_LIT:0>:<EOL><INDENT>mlist2 = [None] * n_input<EOL><DEDENT>elif n_mask2 != n_input:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if n_input > <NUM_LIT:1>:<EOL><INDENT>for img, mf1, mf2 in zip(flist, mlist1, mlist2):<EOL><INDENT>destripe_plus(<EOL>inputfile=img, suffix=suffix, stat=stat,<EOL>lower=lower, upper=upper, binwidth=binwidth,<EOL>maxiter=maxiter, sigrej=sigrej,<EOL>scimask1=scimask1, scimask2=scimask2, dqbits=dqbits,<EOL>cte_correct=cte_correct, clobber=clobber, verbose=verbose<EOL>)<EOL><DEDENT>return<EOL><DEDENT>inputfile = flist[<NUM_LIT:0>]<EOL>scimask1 = mlist1[<NUM_LIT:0>]<EOL>scimask2 = mlist2[<NUM_LIT:0>]<EOL>cwddir = os.getcwd()<EOL>if not os.path.exists(os.path.join(cwddir, inputfile)):<EOL><INDENT>raise IOError("<STR_LIT>".format(inputfile))<EOL><DEDENT>header = fits.getheader(inputfile)<EOL>if (header['<STR_LIT>'] == '<STR_LIT>' and<EOL>((scimask1 is not None and scimask2 is None) or<EOL>(scimask1 is None and scimask2 is not None))):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>calacs_str = subprocess.check_output(['<STR_LIT>', '<STR_LIT>']).split()[<NUM_LIT:0>]<EOL>calacs_ver = [int(x) for x in calacs_str.decode().split('<STR_LIT:.>')]<EOL>if calacs_ver < [<NUM_LIT:8>, <NUM_LIT:3>, <NUM_LIT:1>]:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'.format(calacs_str))<EOL><DEDENT>is_subarray = False<EOL>ctecorr = header['<STR_LIT>']<EOL>aperture = header['<STR_LIT>']<EOL>detector = header['<STR_LIT>']<EOL>date_obs = Time(header['<STR_LIT>'])<EOL>blvtmp_name = inputfile.replace('<STR_LIT>', '<STR_LIT>')<EOL>blctmp_name = inputfile.replace('<STR_LIT>', '<STR_LIT>')<EOL>tra_name = inputfile.replace('<STR_LIT>', '<STR_LIT>')<EOL>flt_name = inputfile.replace('<STR_LIT>', '<STR_LIT>')<EOL>flc_name = inputfile.replace('<STR_LIT>', '<STR_LIT>')<EOL>if detector != '<STR_LIT>':<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>".format(inputfile))<EOL><DEDENT>if date_obs < SM4_DATE:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>".format(inputfile))<EOL><DEDENT>if header['<STR_LIT>'] and cte_correct:<EOL><INDENT>if aperture in SUBARRAY_LIST:<EOL><INDENT>is_subarray = True<EOL><DEDENT>else:<EOL><INDENT>LOG.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>cte_correct = False<EOL><DEDENT><DEDENT>if clobber:<EOL><INDENT>for tmpfilename in [blvtmp_name, blctmp_name, flt_name, flc_name,<EOL>tra_name]:<EOL><INDENT>if os.path.exists(tmpfilename):<EOL><INDENT>os.remove(tmpfilename)<EOL><DEDENT><DEDENT><DEDENT>acsccd.acsccd(inputfile)<EOL>dqbits = interpret_bit_flags(dqbits)<EOL>if dqbits is not None:<EOL><INDENT>if os.path.isfile(tra_name):<EOL><INDENT>with open(tra_name) as fh:<EOL><INDENT>tra_lines = fh.readlines()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>tra_lines = None<EOL><DEDENT>acs2d.acs2d(blvtmp_name, verbose=False, quiet=True)<EOL>dq1, dq2 = _read_DQ_arrays(flt_name)<EOL>mask1 = _get_mask(scimask1, <NUM_LIT:1>)<EOL>scimask1 = acs_destripe._mergeUserMaskAndDQ(dq1, mask1, dqbits)<EOL>mask2 = _get_mask(scimask2, <NUM_LIT:2>)<EOL>if dq2 is not None:<EOL><INDENT>scimask2 = acs_destripe._mergeUserMaskAndDQ(dq2, mask2, dqbits)<EOL><DEDENT>elif mask2 is None:<EOL><INDENT>scimask2 = None<EOL><DEDENT>if tra_lines is not None:<EOL><INDENT>with open(tra_name, mode='<STR_LIT:w>') as fh:<EOL><INDENT>fh.writelines(tra_lines)<EOL><DEDENT><DEDENT>if os.path.isfile(flt_name):<EOL><INDENT>os.remove(flt_name)<EOL><DEDENT><DEDENT>acs_destripe.clean(<EOL>blvtmp_name, suffix, stat=stat, maxiter=maxiter, sigrej=sigrej,<EOL>lower=lower, upper=upper, binwidth=binwidth,<EOL>mask1=scimask1, mask2=scimask2, dqbits=dqbits,<EOL>rpt_clean=rpt_clean, atol=atol, clobber=clobber, verbose=verbose)<EOL>blvtmpsfx = '<STR_LIT>'.format(suffix)<EOL>os.rename(inputfile.replace('<STR_LIT>', blvtmpsfx), blvtmp_name)<EOL>if is_subarray and cte_correct:<EOL><INDENT>fits.setval(blvtmp_name, '<STR_LIT>', value='<STR_LIT>')<EOL>ctecorr = '<STR_LIT>'<EOL><DEDENT>if cte_correct:<EOL><INDENT>if ctecorr == '<STR_LIT>':<EOL><INDENT>acscte.acscte(blvtmp_name)<EOL><DEDENT>else:<EOL><INDENT>LOG.warning(<EOL>"<STR_LIT>".format(ctecorr))<EOL>cte_correct = False<EOL><DEDENT><DEDENT>acs2d.acs2d(blvtmp_name)<EOL>if cte_correct:<EOL><INDENT>acs2d.acs2d(blctmp_name)<EOL><DEDENT>os.remove(blvtmp_name)<EOL>if cte_correct and os.path.isfile(blctmp_name):<EOL><INDENT>os.remove(blctmp_name)<EOL><DEDENT>info_str = '<STR_LIT>'.format(flt_name)<EOL>if cte_correct:<EOL><INDENT>info_str += '<STR_LIT>'.format(flc_name)<EOL><DEDENT>LOG.info(info_str)<EOL>
r"""Calibrate post-SM4 ACS/WFC exposure(s) and use
    standalone :ref:`acsdestripe`.

    This takes a RAW image and generates a FLT file containing
    its calibrated and destriped counterpart.
    If CTE correction is performed, FLC will also be present.

    Parameters
    ----------
    inputfile : str or list of str
        Input filenames in one of these formats:

            * a Python list of filenames
            * a partial filename with wildcards ('\*raw.fits')
            * filename of an ASN table ('j12345670_asn.fits')
            * an at-file (``@input``)

    suffix : str
        The string to use to add to each input file name to
        indicate an output product of ``acs_destripe``.
        This only affects the intermediate output file that will
        be automatically renamed to ``*blv_tmp.fits`` during the processing.

    stat : { 'pmode1', 'pmode2', 'mean', 'mode', 'median', 'midpt' } (Default = 'pmode1')
        Specifies the statistics to be used for computation of the
        background in image rows:

        * 'pmode1' - SEXTRACTOR-like mode estimate based on a
          modified `Pearson's rule <http://en.wikipedia.org/wiki/Nonparametric_skew#Pearson.27s_rule>`_:
          ``2.5*median-1.5*mean``;
        * 'pmode2' - mode estimate based on
          `Pearson's rule <http://en.wikipedia.org/wiki/Nonparametric_skew#Pearson.27s_rule>`_:
          ``3*median-2*mean``;
        * 'mean' - the mean of the distribution of the "good" pixels (after
          clipping, masking, etc.);
        * 'mode' - the mode of the distribution of the "good" pixels;
        * 'median' - the median of the distribution of the "good" pixels;
        * 'midpt' - estimate of the median of the distribution of the "good"
          pixels based on an algorithm similar to IRAF's `imagestats` task
          (``CDF(midpt)=1/2``).

        .. note::
            The midpoint and mode are computed in two passes through the
            image. In the first pass the standard deviation of the pixels
            is calculated and used with the *binwidth* parameter to compute
            the resolution of the data histogram. The midpoint is estimated
            by integrating the histogram and computing by interpolation
            the data value at which exactly half the pixels are below that
            data value and half are above it. The mode is computed by
            locating the maximum of the data histogram and fitting the peak
            by parabolic interpolation.

    maxiter : int
        This parameter controls the maximum number of iterations
        to perform when computing the statistics used to compute the
        row-by-row corrections.

    sigrej : float
        This parameters sets the sigma level for the rejection applied
        during each iteration of statistics computations for the
        row-by-row corrections.

    lower : float, None (Default = None)
        Lower limit of usable pixel values for computing the background.
        This value should be specified in the units of the input image(s).

    upper : float, None (Default = None)
        Upper limit of usable pixel values for computing the background.
        This value should be specified in the units of the input image(s).

    binwidth : float (Default = 0.1)
        Histogram's bin width, in sigma units, used to sample the
        distribution of pixel brightness values in order to compute the
        background statistics. This parameter is aplicable *only* to *stat*
        parameter values of `'mode'` or `'midpt'`.

    clobber : bool
        Specify whether or not to 'clobber' (delete then replace)
        previously generated products with the same names.

    scimask1 : str or list of str
        Mask images for *calibrated* ``SCI,1``, one for each input file.
        Pixels with zero values will be masked out, in addition to clipping.

    scimask2 : str or list of str
        Mask images for *calibrated* ``SCI,2``, one for each input file.
        Pixels with zero values will be masked out, in addition to clipping.
        This is not used for subarrays.

    dqbits : int, str, None (Default = None)
        Integer sum of all the DQ bit values from the input image's DQ array
        that should be considered "good" when building masks for de-striping
        computations. For example, if pixels in the DQ array can be
        combinations of 1, 2, 4, and 8 flags and one wants to consider
        DQ "defects" having flags 2 and 4 as being acceptable for de-striping
        computations, then `dqbits` should be set to 2+4=6. Then a DQ pixel
        having values 2,4, or 6 will be considered a good pixel, while a DQ
        pixel with a value, e.g., 1+2=3, 4+8=12, etc. will be flagged
        as a "bad" pixel.

        Alternatively, one can enter a comma- or '+'-separated list of
        integer bit flags that should be added to obtain the final
        "good" bits. For example, both ``4,8`` and ``4+8`` are equivalent to
        setting `dqbits` to 12.

        | Set `dqbits` to 0 to make *all* non-zero pixels in the DQ
          mask to be considered "bad" pixels, and the corresponding image
          pixels not to be used for de-striping computations.

        | Default value (`None`) will turn off the use of image's DQ array
          for de-striping computations.

        | In order to reverse the meaning of the `dqbits`
          parameter from indicating values of the "good" DQ flags
          to indicating the "bad" DQ flags, prepend '~' to the string
          value. For example, in order not to use pixels with
          DQ flags 4 and 8 for sky computations and to consider
          as "good" all other pixels (regardless of their DQ flag),
          set `dqbits` to ``~4+8``, or ``~4,8``. To obtain the
          same effect with an `int` input value (except for 0),
          enter -(4+8+1)=-9. Following this convention,
          a `dqbits` string value of ``'~0'`` would be equivalent to
          setting ``dqbits=None``.

        .. note::
            DQ masks (if used), *will be* combined with user masks specified
            in the `scimask1` and `scimask2` parameters (if any).

    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].

    cte_correct : bool
        Perform CTE correction.

    verbose : bool
        Print informational messages. Default = True.

    Raises
    ------
    ImportError
        ``stsci.tools`` not found.

    IOError
        Input file does not exist.

    ValueError
        Invalid header values or CALACS version.