def detsat(searchpattern, chips=[<NUM_LIT:1>, <NUM_LIT:4>], n_processes=<NUM_LIT:4>, sigma=<NUM_LIT>,<EOL>low_thresh=<NUM_LIT:0.1>, h_thresh=<NUM_LIT:0.5>, small_edge=<NUM_LIT>, line_len=<NUM_LIT:200>,<EOL>line_gap=<NUM_LIT>, percentile=(<NUM_LIT>, <NUM_LIT>), buf=<NUM_LIT:200>, plot=False,<EOL>verbose=True):
if not HAS_OPDEP:<EOL><INDENT>raise ImportError('<STR_LIT>')<EOL><DEDENT>if verbose:<EOL><INDENT>t_beg = time.time()<EOL><DEDENT>files = glob.glob(searchpattern)<EOL>n_files = len(files)<EOL>n_chips = len(chips)<EOL>n_tot = n_files * n_chips<EOL>n_cpu = multiprocessing.cpu_count()<EOL>results = {}<EOL>errors = {}<EOL>if verbose:<EOL><INDENT>print('<STR_LIT>'.format(n_files))<EOL><DEDENT>if n_files < <NUM_LIT:1> or n_chips < <NUM_LIT:1>:<EOL><INDENT>return results, errors<EOL><DEDENT>if n_tot < n_processes:<EOL><INDENT>n_processes = n_tot<EOL><DEDENT>if n_processes > n_cpu:<EOL><INDENT>n_processes = n_cpu<EOL><DEDENT>if n_processes == <NUM_LIT:1>:<EOL><INDENT>for fil in files:<EOL><INDENT>for chip in chips:<EOL><INDENT>if verbose:<EOL><INDENT>print('<STR_LIT>'.format(fil, chip))<EOL><DEDENT>key = (fil, chip)<EOL>try:<EOL><INDENT>result = _detsat_one(<EOL>fil, chip, sigma=sigma,<EOL>low_thresh=low_thresh, h_thresh=h_thresh,<EOL>small_edge=small_edge, line_len=line_len,<EOL>line_gap=line_gap, percentile=percentile, buf=buf,<EOL>plot=plot, verbose=verbose)<EOL><DEDENT>except Exception as e:<EOL><INDENT>errmsg = '<STR_LIT>'.format(type(e), str(e))<EOL>errors[key] = errmsg<EOL>if verbose:<EOL><INDENT>print(errmsg)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>results[key] = result<EOL><DEDENT><DEDENT><DEDENT>if verbose:<EOL><INDENT>print()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if verbose:<EOL><INDENT>print('<STR_LIT>'.format(n_processes))<EOL><DEDENT>work_queue = Queue()<EOL>done_queue = Queue()<EOL>processes = []<EOL>for fil in files:<EOL><INDENT>for chip in chips:<EOL><INDENT>work_queue.put((fil, chip))<EOL><DEDENT><DEDENT>for w in range(n_processes):<EOL><INDENT>p = Process(<EOL>target=_satdet_worker, args=(work_queue, done_queue), kwargs={<EOL>'<STR_LIT>': sigma, '<STR_LIT>': low_thresh,<EOL>'<STR_LIT>': h_thresh, '<STR_LIT>': small_edge,<EOL>'<STR_LIT>': line_len, '<STR_LIT>': line_gap,<EOL>'<STR_LIT>': percentile, '<STR_LIT>': buf})<EOL>p.start()<EOL>processes.append(p)<EOL>work_queue.put('<STR_LIT>')<EOL><DEDENT>for p in processes:<EOL><INDENT>p.join()<EOL><DEDENT>done_queue.put('<STR_LIT>')<EOL>for status in iter(done_queue.get, '<STR_LIT>'):<EOL><INDENT>key = (status[<NUM_LIT:1>], status[<NUM_LIT:2>])<EOL>if status[<NUM_LIT:0>]:  <EOL><INDENT>results[key] = status[<NUM_LIT:3>]<EOL><DEDENT>else:  <EOL><INDENT>errors[key] = status[<NUM_LIT:3>]<EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>if len(results) > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>for key in sorted(results):<EOL><INDENT>print('<STR_LIT>'.format(<EOL>key[<NUM_LIT:0>], key[<NUM_LIT:1>], len(results[key])))<EOL><DEDENT>if len(errors) > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>for key in sorted(errors):<EOL><INDENT>print('<STR_LIT>'.format(key[<NUM_LIT:0>], key[<NUM_LIT:1>]))<EOL><DEDENT><DEDENT><DEDENT>if verbose:<EOL><INDENT>t_end = time.time()<EOL>print('<STR_LIT>'.format(t_end - t_beg))<EOL><DEDENT>return results, errors<EOL>
Find satellite trails in the given images and extensions.
    The trails are calculated using Probabilistic Hough Transform.

    .. note::

        The trail endpoints found here are crude approximations.
        Use :func:`make_mask` to create the actual DQ mask for the trail(s)
        of interest.

    Parameters
    ----------
    searchpattern : str
        Search pattern for input FITS images, as accepted by
        :py:func:`glob.glob`.

    chips : list
        List of extensions for science data, as accepted by
        ``astropy.io.fits``.
        The default values of ``[1, 4]`` are tailored for ACS/WFC.

    n_processes : int
        Number of processes for multiprocessing, which is only useful
        if you are processing a lot of images or extensions.
        If 1 is given, no multiprocessing is done.

    sigma : float, optional
        The size of a Gaussian filter to use before edge detection.
        The default is 2, which is good for almost all images.

    low_thresh : float, optional
        The lower threshold for hysteresis linking of edge pieces.
        This should be between 0 and 1, and less than ``h_thresh``.

    h_thresh : float, optional
        The upper threshold for hysteresis linking of edge pieces.
        This should be between 0 and 1, and greater than ``low_thresh``.

    small_edge : int, optional
        Size of perimeter of small objects to remove in edge image.
        This significantly reduces noise before doing Hough Transform.
        If it is set too high, you will remove the edge of the
        satellite you are trying to find.

    line_len : int, optional
        Minimum line length for Probabilistic Hough Transform to fit.

    line_gap : int, optional
        The largest gap in points allowed for the Probabilistic
        Hough Transform.

    percentile : tuple of float, optional
        The percent boundaries to scale the image to before
        creating edge image.

    buf : int, optional
        How close to the edge of the image the satellite trail has to
        be to be considered a trail.

    plot : bool, optional
        Make plots of edge image, Hough space transformation, and
        rescaled image. This is only applicable if ``n_processes=1``.

    verbose : bool, optional
        Print extra information to the terminal, mostly for debugging.
        In multiprocessing mode, info from individual process is not printed.

    Returns
    -------
    results : dict
        Dictionary mapping ``(filename, ext)`` to an array of endpoints of
        line segments in the format of ``[[x0, y0], [x1, y1]]`` (if found) or
        an empty array (if not). These are the segments that have been
        identified as making up part of a satellite trail.

    errors : dict
        Dictionary mapping ``(filename, ext)`` to the error message explaining
        why processing failed.

    Raises
    ------
    ImportError
        Missing scipy or skimage>=0.11 packages.