def _get_clusters_spatial(s, neighbors):
 r = np.ones(s.shape, dtype=bool)
 clusters = list()
 next_ind = (0 if (s.size > 0) else None)
 while (next_ind is not None):
  t_inds = [next_ind]
  r[next_ind] = False
  icount = 1
  while (icount <= len(t_inds)):
   ind = t_inds[(icount - 1)]
   buddies = np.where(r)[0]
   buddies = buddies[np.in1d(s[buddies], neighbors[s[ind]], assume_unique=True)]
   t_inds += buddies.tolist()
   r[buddies] = False
   icount += 1
  next_ind = np.argmax(r)
  if (next_ind == 0):
   next_ind = None
  clusters.append(s[t_inds])
 return clusters

def _get_clusters_spatial ( s , neighbors ) : r = np . ones ( s . shape , dtype = bool ) clusters = list ( ) next_ind = ( 0 if ( s . size > 0 ) else None ) while ( next_ind is not None ) : t_inds = [ next_ind ] r [ next_ind ] = False icount = 1 while ( icount <= len ( t_inds ) ) : ind = t_inds [ ( icount - 1 ) ] buddies = np . where ( r ) [ 0 ] buddies = buddies [ np . in1d ( s [ buddies ] , neighbors [ s [ ind ] ] , assume_unique = True ) ] t_inds += buddies . tolist ( ) r [ buddies ] = False icount += 1 next_ind = np . argmax ( r ) if ( next_ind == 0 ) : next_ind = None clusters . append ( s [ t_inds ] ) return clusters
form spatial clusters using neighbor lists .