docstr: Return pairs of worm centers that are deemed adjacent by distance
  
  i - i-centers of worms
  j - j-centers of worms
  a - angular orientation of worms
  
  Returns two vectors giving the indices of the first and second
  centers that are connected.
docstr_tok: ["Return","pairs","of","worm","centers","that","are","deemed","adjacent","by","distance","i","-","i-centers","of","worms","j","-","j-centers","of","worms","a","-","angular","orientation","of","worms","Returns","two","vectors","giving","the","indices","of","the","first","and","second","centers","that","are","connected","."]
code: def find_adjacent_by_distance(self, i, j, a):
      """Return pairs of worm centers that are deemed adjacent by distance
  
      i - i-centers of worms
      j - j-centers of worms
      a - angular orientation of worms
  
      Returns two vectors giving the indices of the first and second
      centers that are connected.
      """
      if len(i) < 2:
          return numpy.zeros(len(i), int), numpy.zeros(len(i), int)
      if self.wants_automatic_distance:
          space_distance = self.worm_width.value
          angle_distance = numpy.arctan2(
              self.worm_width.value, self.worm_length.value
          )
          angle_distance += numpy.pi / self.angle_count.value
      else:
          space_distance = self.space_distance.value
          angle_distance = self.angular_distance.value * numpy.pi / 180
      #
      # Sort by i and break the sorted vector into chunks where
      # consecutive locations are separated by more than space_distance
      #
      order = numpy.lexsort((a, j, i))
      i = i[order]
      j = j[order]
      a = a[order]
      breakpoint = numpy.hstack(
          ([False], i[1:] - i[:-1] > space_distance)
      )
      if numpy.all(~breakpoint):
          # No easy win - cross all with all
          first, second = numpy.mgrid[0 : len(i), 0 : len(i)]
      else:
          # The segment that each belongs to
          segment_number = numpy.cumsum(breakpoint)
          # The number of elements in each segment
          member_count = numpy.bincount(segment_number)
          # The index of the first element in the segment
          member_idx = numpy.hstack(
              ([0], numpy.cumsum(member_count[:-1]))
          )
          # The index of the first element, for every element in the segment
          segment_start = member_idx[segment_number]
          #
          # Develop the cross-products for each segment. Each segment has
          # member_count * member_count crosses.
          #
          # # of (first,second) pairs in each segment
          cross_size = member_count**2
          # Index in final array of first element of each segment
          segment_idx = numpy.cumsum(cross_size)
          # relative location of first "first"
          first_start_idx = numpy.cumsum(
              member_count[segment_number[:-1]]
          )
          first = numpy.zeros(segment_idx[-1], int)
          first[first_start_idx] = 1
          # The "firsts" array
          first = numpy.cumsum(first)
          first_start_idx = numpy.hstack(([0], first_start_idx))
          second = (
              numpy.arange(len(first))
              - first_start_idx[first]
              + segment_start[first]
          )
      mask = (
          numpy.abs(
              (i[first] - i[second]) ** 2 + (j[first] - j[second]) ** 2
          )
          <= space_distance**2
      ) & (
          (numpy.abs(a[first] - a[second]) <= angle_distance)
          | (a[first] + numpy.pi - a[second] <= angle_distance)
          | (a[second] + numpy.pi - a[first] <= angle_distance)
      )
      return order[first[mask]], order[second[mask]]
  
imports: import matplotlib.cm
  import numpy
  from cellprofiler_core.constants.measurement import COLTYPE_INTEGER, M_LOCATION_CENTER_X, M_LOCATION_CENTER_Y, M_NUMBER_OBJECT_NUMBER, FF_COUNT, COLTYPE_FLOAT, IMAGE, C_COUNT, C_LOCATION, C_NUMBER, FTR_CENTER_X, FTR_CENTER_Y, FTR_OBJECT_NUMBER
  from cellprofiler_core.measurement import Measurements
  from cellprofiler_core.module import Module
  from cellprofiler_core.object import Objects, ObjectSet
  from cellprofiler_core.preferences import get_default_colormap
  from cellprofiler_core.setting import Binary
  from cellprofiler_core.setting.subscriber import ImageSubscriber
  from cellprofiler_core.setting.text import LabelName, Integer, Float
  from centrosome.cpmorphology import all_connected_components
  from centrosome.cpmorphology import fixup_scipy_ndimage_result
  from centrosome.cpmorphology import get_line_pts
  from scipy.ndimage import binary_erosion, binary_fill_holes
  from scipy.ndimage import mean
label_desc: Use image node_id 10 for calling the IdentifyDeadWorms obj's underlying member method code with example usage: obj.find_adjacent_by_distance(i, j, a) and returns: order,  order, numpy,  numpy