11# %%
22import json
33import os
4+ from glob import glob
45from typing import Dict
6+
57import fsspec
68import matplotlib .pyplot as plt
79import numpy as np
810import pandas as pd
11+ from args import parse_args
12+ from pyproj import Proj
13+ from scipy .sparse .csgraph import minimum_spanning_tree
14+ from scipy .spatial .distance import pdist , squareform
915from sklearn .cluster import DBSCAN
1016from tqdm import tqdm
11- from args import parse_args
12- from glob import glob
1317
1418
1519def associate (
@@ -20,6 +24,21 @@ def associate(
2024):
2125
2226 VPVS_RATIO = config ["VPVS_RATIO" ]
27+ VP = config ["VP" ]
28+
29+ proj = Proj (proj = "merc" , datum = "WGS84" , units = "km" )
30+ stations [["x_km" , "y_km" ]] = stations .apply (lambda x : pd .Series (proj (x .longitude , x .latitude )), axis = 1 )
31+
32+ # dist_matrix = squareform(pdist(stations[["x_km", "y_km"]].values))
33+ # mst = minimum_spanning_tree(dist_matrix)
34+ # dx = np.median(mst.data[mst.data > 0])
35+ # print(f"dx: {dx:.3f}")
36+ # eps_t = dx / VP * 2.0
37+ # eps_t = 6.0
38+ # eps_xy = eps_t * VP * 2 / (1.0 + VPVS_RATIO)
39+ # print(f"eps_t: {eps_t:.3f}, eps_xy: {eps_xy:.3f}")
40+ eps_xy = 30.0
41+ print (f"eps_xy: { eps_xy :.3f} " )
2342
2443 # %%
2544 t0 = min (events ["event_time" ].min (), picks ["phase_time" ].min ())
@@ -28,8 +47,13 @@ def associate(
2847 picks ["timestamp" ] = picks ["phase_time" ].apply (lambda x : (x - t0 ).total_seconds ())
2948
3049 # %%
31- # clustering = DBSCAN(eps=3, min_samples=3).fit(events[["timestamp", "x_s", "y_s"]])
32- clustering = DBSCAN (eps = 3 , min_samples = 3 ).fit (events [["timestamp" ]])
50+ events = events .merge (stations [["station_id" , "x_km" , "y_km" ]], on = "station_id" , how = "left" )
51+
52+ scaling = np .array ([1.0 , 1.0 / eps_xy , 1.0 / eps_xy ])
53+ clustering = DBSCAN (eps = 2.0 , min_samples = 4 ).fit (events [["timestamp" , "x_km" , "y_km" ]] * scaling )
54+ # clustering = DBSCAN(eps=2.0, min_samples=4).fit(events[["timestamp"]])
55+ # clustering = DBSCAN(eps=3.0, min_samples=3).fit(events[["timestamp"]])
56+ # clustering = DBSCAN(eps=1.0, min_samples=3).fit(events[["timestamp"]])
3357 events ["event_index" ] = clustering .labels_
3458 print (f"Number of associated events: { len (events ['event_index' ].unique ())} " )
3559
0 commit comments