original_docstring: 
      Find sources in an image by convolving the image with the input
      kernel and selecting connected pixels above a given threshold.
  
      Parameters
      ----------
      data : array_like
          The 2D array of the image.
  
      threshold : float
          The absolute image value above which to select sources.  Note
          that this threshold is not the same threshold input to
          ``daofind`` or ``irafstarfind``.  It should be multiplied by the
          kernel relerr.
  
      kernel : `_FindObjKernel`
          The convolution kernel.  The dimensions should match those of
          the cutouts.  The kernel should be normalized to zero sum.
  
      exclude_border : bool, optional
          Set to `True` to exclude sources found within half the size of
          the convolution kernel from the image borders.  The default is
          `False`, which is the mode used by `DAOFIND`_ and `starfind`_.
  
      local_peaks : bool, optional
          Set to `True` to exactly match the `DAOFIND`_ method of finding
          local peaks.  If `False`, then only one peak per thresholded
          segment will be used.
  
      Returns
      -------
      objects : list of `_ImgCutout`
          A list of `_ImgCutout` objects containing the image cutout for
          each source.
  
  
      .. _DAOFIND: http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?daofind
      .. _starfind: http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?starfind
      
docstring: Find sources in an image by convolving the image with the input
  kernel and selecting connected pixels above a given threshold.
  
  Parameters
  
  data : array_like
  The 2D array of the image.
  
  threshold : float
  The absolute image value above which to select sources.
  
  kernel : `_FindObjKernel`
  The convolution kernel.  The dimensions should match those of
  the cutouts.  The kernel should be normalized to zero sum.
  
  exclude_border : bool, optional
  Set to `True` to exclude sources found within half the size of
  the convolution kernel from the image borders.
  
  local_peaks : bool, optional
  Set to `True` to exactly match the `DAOFIND`_ method of finding
  local peaks.  If `False`, then only one peak per thresholded
  segment will be used.
  
  Returns
  
  objects : list of `_ImgCutout`
  A list of `_ImgCutout` objects containing the image cutout for
  each source.
  
  
docstring_tokens: Find sources in an image by convolving the image with the input kernel and selecting connected pixels above a given threshold . Parameters data : array_like The 2D array of the image . threshold : float The absolute image value above which to select sources . kernel : ` _FindObjKernel ` The convolution kernel . The dimensions should match those of the cutouts . The kernel should be normalized to zero sum . exclude_border : bool optional Set to ` True ` to exclude sources found within half the size of the convolution kernel from the image borders . local_peaks : bool optional Set to ` True ` to exactly match the ` DAOFIND ` _ method of finding local peaks . If ` False ` then only one peak per thresholded segment will be used . Returns objects : list of ` _ImgCutout ` A list of ` _ImgCutout ` objects containing the image cutout for each source .
code: def _findobjs(data, threshold, kernel, min_separation=None,
                exclude_border=False, local_peaks=True):
      """
      Find sources in an image by convolving the image with the input
      kernel and selecting connected pixels above a given threshold.
  
      Parameters
      ----------
      data : array_like
          The 2D array of the image.
  
      threshold : float
          The absolute image value above which to select sources.  Note
          that this threshold is not the same threshold input to
          ``daofind`` or ``irafstarfind``.  It should be multiplied by the
          kernel relerr.
  
      kernel : `_FindObjKernel`
          The convolution kernel.  The dimensions should match those of
          the cutouts.  The kernel should be normalized to zero sum.
  
      exclude_border : bool, optional
          Set to `True` to exclude sources found within half the size of
          the convolution kernel from the image borders.  The default is
          `False`, which is the mode used by `DAOFIND`_ and `starfind`_.
  
      local_peaks : bool, optional
          Set to `True` to exactly match the `DAOFIND`_ method of finding
          local peaks.  If `False`, then only one peak per thresholded
          segment will be used.
  
      Returns
      -------
      objects : list of `_ImgCutout`
          A list of `_ImgCutout` objects containing the image cutout for
          each source.
  
  
      .. _DAOFIND: http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?daofind
      .. _starfind: http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?starfind
      """
  
      from scipy import ndimage
  
      x_kernradius = kernel.kern.shape[1] // 2
      y_kernradius = kernel.kern.shape[0] // 2
  
      if not exclude_border:
          # create a larger image padded by zeros
          ysize = int(data.shape[0] + (2. * y_kernradius))
          xsize = int(data.shape[1] + (2. * x_kernradius))
          data_padded = np.zeros((ysize, xsize))
          data_padded[y_kernradius:y_kernradius + data.shape[0],
                      x_kernradius:x_kernradius + data.shape[1]] = data
          data = data_padded
  
      convolved_data = filter_data(data, kernel.kern, mode='constant',
                                   fill_value=0.0, check_normalization=False)
  
      if not exclude_border:
          # keep border=0 in convolved data
          convolved_data[:y_kernradius, :] = 0.
          convolved_data[-y_kernradius:, :] = 0.
          convolved_data[:, :x_kernradius] = 0.
          convolved_data[:, -x_kernradius:] = 0.
  
      selem = ndimage.generate_binary_structure(2, 2)
      object_labels, nobjects = ndimage.label(convolved_data > threshold,
                                              structure=selem)
      objects = []
      if nobjects == 0:
          return objects
  
      # find object peaks in the convolved data
      if local_peaks:
          # footprint overrides min_separation in find_peaks
          if min_separation is None:   # daofind
              footprint = kernel.mask.astype(np.bool)
          else:
              from skimage.morphology import disk
              footprint = disk(min_separation)
          tbl = find_peaks(convolved_data, threshold, footprint=footprint)
          coords = np.transpose([tbl['y_peak'], tbl['x_peak']])
      else:
          object_slices = ndimage.find_objects(object_labels)
          coords = []
          for object_slice in object_slices:
              # thresholded_object is not the same size as the kernel
              thresholded_object = convolved_data[object_slice]
              ypeak, xpeak = np.unravel_index(thresholded_object.argmax(),
                                              thresholded_object.shape)
              xpeak += object_slice[1].start
              ypeak += object_slice[0].start
              coords.append((ypeak, xpeak))
  
      for (ypeak, xpeak) in coords:
          # now extract the object from the data, centered on the peak
          # pixel in the convolved image, with the same size as the kernel
          x0 = xpeak - x_kernradius
          x1 = xpeak + x_kernradius + 1
          y0 = ypeak - y_kernradius
          y1 = ypeak + y_kernradius + 1
          if x0 < 0 or x1 > data.shape[1]:
              continue    # pragma: no cover (isolated continue is never tested)
          if y0 < 0 or y1 > data.shape[0]:
              continue    # pragma: no cover (isolated continue is never tested)
          object_data = data[y0:y1, x0:x1]
          object_convolved_data = convolved_data[y0:y1, x0:x1].copy()
          if not exclude_border:
              # correct for image padding
              x0 -= x_kernradius
              y0 -= y_kernradius
          imgcutout = _ImgCutout(object_data, object_convolved_data, x0, y0)
          objects.append(imgcutout)
      return objects
code_tokens: def _findobjs ( data , threshold , kernel , min_separation = None , exclude_border = False , local_peaks = True ) : from scipy import ndimage x_kernradius = kernel . kern . shape [ 1 ] // 2 y_kernradius = kernel . kern . shape [ 0 ] // 2 if not exclude_border : ysize = int ( data . shape [ 0 ] + ( 2. * y_kernradius ) ) xsize = int ( data . shape [ 1 ] + ( 2. * x_kernradius ) ) data_padded = np . zeros ( ( ysize , xsize ) ) data_padded [ y_kernradius : y_kernradius + data . shape [ 0 ] , x_kernradius : x_kernradius + data . shape [ 1 ] ] = data data = data_padded convolved_data = filter_data ( data , kernel . kern , mode = 'constant' , fill_value = 0.0 , check_normalization = False ) if not exclude_border : convolved_data [ : y_kernradius , : ] = 0. convolved_data [ - y_kernradius : , : ] = 0. convolved_data [ : , : x_kernradius ] = 0. convolved_data [ : , - x_kernradius : ] = 0. selem = ndimage . generate_binary_structure ( 2 , 2 ) object_labels , nobjects = ndimage . label ( convolved_data > threshold , structure = selem ) objects = [ ] if nobjects == 0 : return objects if local_peaks : if min_separation is None : footprint = kernel . mask . astype ( np . bool ) else : from skimage . morphology import disk footprint = disk ( min_separation ) tbl = find_peaks ( convolved_data , threshold , footprint = footprint ) coords = np . transpose ( [ tbl [ 'y_peak' ] , tbl [ 'x_peak' ] ] ) else : object_slices = ndimage . find_objects ( object_labels ) coords = [ ] for object_slice in object_slices : thresholded_object = convolved_data [ object_slice ] ypeak , xpeak = np . unravel_index ( thresholded_object . argmax ( ) , thresholded_object . shape ) xpeak += object_slice [ 1 ] . start ypeak += object_slice [ 0 ] . start coords . append ( ( ypeak , xpeak ) ) for ( ypeak , xpeak ) in coords : x0 = xpeak - x_kernradius x1 = xpeak + x_kernradius + 1 y0 = ypeak - y_kernradius y1 = ypeak + y_kernradius + 1 if x0 < 0 or x1 > data . shape [ 1 ] : continue if y0 < 0 or y1 > data . shape [ 0 ] : continue object_data = data [ y0 : y1 , x0 : x1 ] object_convolved_data = convolved_data [ y0 : y1 , x0 : x1 ] . copy ( ) if not exclude_border : x0 -= x_kernradius y0 -= y_kernradius imgcutout = _ImgCutout ( object_data , object_convolved_data , x0 , y0 ) objects . append ( imgcutout ) return objects
short_docstring: Find sources in an image by convolving the image with the input
  kernel and selecting connected pixels above a given threshold.
short_docstring_tokens: Find sources in an image by convolving the image with the input kernel and selecting connected pixels above a given threshold .
comment: """
      Find sources in an image by convolving the image with the input
      kernel and selecting connected pixels above a given threshold.
  
      Parameters
      ----------
      data : array_like
          The 2D array of the image.
  
      threshold : float
          The absolute image value above which to select sources.  Note
          that this threshold is not the same threshold input to
          ``daofind`` or ``irafstarfind``.  It should be multiplied by the
          kernel relerr.
  
      kernel : `_FindObjKernel`
          The convolution kernel.  The dimensions should match those of
          the cutouts.  The kernel should be normalized to zero sum.
  
      exclude_border : bool, optional
          Set to `True` to exclude sources found within half the size of
          the convolution kernel from the image borders.  The default is
          `False`, which is the mode used by `DAOFIND`_ and `starfind`_.
  
      local_peaks : bool, optional
          Set to `True` to exactly match the `DAOFIND`_ method of finding
          local peaks.  If `False`, then only one peak per thresholded
          segment will be used.
  
      Returns
      -------
      objects : list of `_ImgCutout`
          A list of `_ImgCutout` objects containing the image cutout for
          each source.
  
  
      .. _DAOFIND: http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?daofind
      .. _starfind: http://stsdas.stsci.edu/cgi-bin/gethelp.cgi?starfind
      """$SEP$# create a larger image padded by zeros$SEP$# keep border=0 in convolved data$SEP$# find object peaks in the convolved data$SEP$# footprint overrides min_separation in find_peaks$SEP$# daofind$SEP$# thresholded_object is not the same size as the kernel$SEP$# now extract the object from the data, centered on the peak$SEP$# pixel in the convolved image, with the same size as the kernel$SEP$# pragma: no cover (isolated continue is never tested)$SEP$# pragma: no cover (isolated continue is never tested)$SEP$# correct for image padding