def space_cluster(catalog, d_thresh, show=True):
<EOL>dist_mat = dist_mat_km(catalog)<EOL>dist_vec = squareform(dist_mat)<EOL>Z = linkage(dist_vec, method='<STR_LIT>')<EOL>indices = fcluster(Z, t=d_thresh, criterion='<STR_LIT>')<EOL>group_ids = list(set(indices))<EOL>indices = [(indices[i], i) for i in range(len(indices))]<EOL>if show:<EOL><INDENT>dendrogram(Z, color_threshold=d_thresh,<EOL>distance_sort='<STR_LIT>')<EOL>plt.show()<EOL><DEDENT>indices.sort(key=lambda tup: tup[<NUM_LIT:0>])<EOL>groups = []<EOL>for group_id in group_ids:<EOL><INDENT>group = Catalog()<EOL>for ind in indices:<EOL><INDENT>if ind[<NUM_LIT:0>] == group_id:<EOL><INDENT>group.append(catalog[ind[<NUM_LIT:1>]])<EOL><DEDENT>elif ind[<NUM_LIT:0>] > group_id:<EOL><INDENT>groups.append(group)<EOL>break<EOL><DEDENT><DEDENT><DEDENT>groups.append(group)<EOL>return groups<EOL>
Cluster a catalog by distance only.

Will compute the matrix of physical distances between events and utilize
the :mod:`scipy.clustering.hierarchy` module to perform the clustering.

:type catalog: obspy.core.event.Catalog
:param catalog: Catalog of events to clustered
:type d_thresh: float
:param d_thresh: Maximum inter-event distance threshold

:returns: list of :class:`obspy.core.event.Catalog` objects
:rtype: list

>>> from eqcorrscan.utils.clustering import space_cluster
>>> from obspy.clients.fdsn import Client
>>> from obspy import UTCDateTime
>>> client = Client("NCEDC")
>>> starttime = UTCDateTime("2002-01-01")
>>> endtime = UTCDateTime("2002-02-01")
>>> cat = client.get_events(starttime=starttime, endtime=endtime,
...                         minmagnitude=2)
>>> groups = space_cluster(catalog=cat, d_thresh=2, show=False)

>>> from eqcorrscan.utils.clustering import space_cluster
>>> from obspy.clients.fdsn import Client
>>> from obspy import UTCDateTime
>>> client = Client("https://earthquake.usgs.gov")
>>> starttime = UTCDateTime("2002-01-01")
>>> endtime = UTCDateTime("2002-02-01")
>>> cat = client.get_events(starttime=starttime, endtime=endtime,
...                         minmagnitude=6)
>>> groups = space_cluster(catalog=cat, d_thresh=1000, show=False)