nodes: 0, module; 1, function_definition; 2, function_name:index_pix_in_pixels; 3, parameters; 4, block; 5, identifier:pix; 6, identifier:pixels; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, comment:# ADW: Not really safe to set index = -1 (accesses last entry);; 11, comment:# -np.inf would be better, but breaks other code...; 12, comment:# ADW: Are the pixels always sorted? Is there a quick way to check?; 13, if_statement; 14, comment:# Assumes that 'pixels' is pre-sorted, otherwise...???; 15, expression_statement; 16, if_statement; 17, return_statement; 18, identifier:sort; 19, False; 20, identifier:outside; 21, unary_operator; 22, comment:"""
      Find the indices of a set of pixels into another set of pixels.
      !!! ASSUMES SORTED PIXELS !!!
  
      Parameters:
      -----------
      pix    : set of search pixels
      pixels : set of reference pixels
    
      Returns:
      --------
      index : index into the reference pixels
      """; 23, identifier:sort; 24, block; 25, assignment; 26, call; 27, block; 28, else_clause; 29, identifier:index; 30, integer:1; 31, expression_statement; 32, identifier:index; 33, call; 34, attribute; 35, argument_list; 36, if_statement; 37, comment:# Find objects that are outside the pixels; 38, block; 39, assignment; 40, attribute; 41, argument_list; 42, identifier:np; 43, identifier:isscalar; 44, identifier:index; 45, not_operator; 46, block; 47, expression_statement; 48, identifier:pixels; 49, call; 50, identifier:np; 51, identifier:searchsorted; 52, identifier:pixels; 53, identifier:pix; 54, call; 55, expression_statement; 56, assignment; 57, attribute; 58, argument_list; 59, attribute; 60, argument_list; 61, assignment; 62, subscript; 63, identifier:outside; 64, identifier:np; 65, identifier:sort; 66, identifier:pixels; 67, call; 68, identifier:any; 69, identifier:index; 70, identifier:outside; 71, identifier:index; 72, unary_operator; 73, attribute; 74, argument_list; 75, call; 76, identifier:np; 77, identifier:in1d; 78, identifier:pix; 79, identifier:pixels; 80, attribute; 81, argument_list; 82, identifier:np; 83, identifier:in1d; 84, identifier:pix; 85, identifier:pixels
code: def index_pix_in_pixels(pix,pixels,sort=False,outside=-1):
      """
      Find the indices of a set of pixels into another set of pixels.
      !!! ASSUMES SORTED PIXELS !!!
  
      Parameters:
      -----------
      pix    : set of search pixels
      pixels : set of reference pixels
    
      Returns:
      --------
      index : index into the reference pixels
      """
      # ADW: Not really safe to set index = -1 (accesses last entry); 
      # -np.inf would be better, but breaks other code...
  
      # ADW: Are the pixels always sorted? Is there a quick way to check?
      if sort: pixels = np.sort(pixels)
  
      # Assumes that 'pixels' is pre-sorted, otherwise...???
      index = np.searchsorted(pixels,pix)
      if np.isscalar(index):
          if not np.in1d(pix,pixels).any(): index = outside
      else:
          # Find objects that are outside the pixels
          index[~np.in1d(pix,pixels)] = outside
      return index