Ordering points to identify the clustering structure (OPTICS) is an algorithm for finding density-based clusters in spatial data.
For example:
def cluster(order, distance, points, threshold):
clusters = [[]]
points = sorted(zip(order, distance, points))
splits = ((v > threshold, p) for i,v,p in points)
for iscluster, point in splits:
if iscluster: clusters[-1].append(point)
elif len(clusters[-1]) > 0: clusters.append([])
return clusters
rd, cd, order = optics(points, 4)
print cluster(order, rd, points, 38.0)
Hope this answer helps.