Say, We define B a neighbor of A, then Euclidean distance of (B, A) is inferior to a threshold. The order between sequences is irrelevant, but this should define an order within a sequence (preferably). Order within a sequence, is not an order of distances, but the one forming the shortest path traversing the whole sequence.
The case such path doesn't exist, a weak order need to be set, like:
A -> B -> C,D,E -> F -> G
Of course for two sequences (communities), there is no pair of points of distance =< the threshold
I constructed a Cartesian product of all pairs and applied euclidean distance, points of distances less than threshold, are a two neighbors communities, still this is a specific case and I obviously want to let communities grow as far as the threshold let.
If you don't mind, this is heavy math for me, a piece of code attaining the specific case is like:
combinations =list(zip(res.min_lon, res.min_lat))[0:100] import itertools def euc(coord1, coord2): dist = sqrt((coord1-coord2)**2 + (coord1-coord2)**2) return dist distances =  for pair in itertools.product(combinations, repeat=2): distances.append(euc(*pair), pair)
Obviously, it doesn't do much. How to formalize this ? probably this is very basic problem in graph theory.