Skip to content

Commit b4fec1f

Browse files
committed
improve phasenet_plus clustering, but not ideal
1 parent 41fece2 commit b4fec1f

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

scripts/run_adloc.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ def run_adloc(
4444

4545
# %%
4646
data_path = f"{root_path}/{region}/gamma"
47-
picks_file = os.path.join(data_path, f"gamma_picks.csv")
48-
events_file = os.path.join(data_path, f"gamma_events.csv")
47+
picks_file = f"{data_path}/gamma_picks.csv"
48+
events_file = f"{data_path}/gamma_events.csv"
49+
# picks_file = f"{root_path}/{region}/gamma_plus/gamma_picks.csv"
50+
# events_file = f"{root_path}/{region}/gamma_plus/gamma_events.csv"
4951
# picks_file = f"{root_path}/{region}/phasenet_plus/phasenet_plus_picks_associated.csv"
5052
# events_file = f"{root_path}/{region}/phasenet_plus/phasenet_plus_events_associated.csv"
5153

@@ -186,6 +188,9 @@ def run_adloc(
186188
picks = picks.merge(events[["event_index", "idx_eve"]], on="event_index")
187189
picks = picks.merge(stations[["station_id", "idx_sta"]], on="station_id")
188190

191+
print(f"Number of picks: {len(picks)}")
192+
print(f"Number of events: {len(events)}")
193+
189194
# %%
190195
estimator = ADLoc(config, stations=stations[["x_km", "y_km", "z_km"]].values, eikonal=config["eikonal"])
191196

scripts/run_event_association.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# %%
22
import json
33
import os
4+
from glob import glob
45
from typing import Dict
6+
57
import fsspec
68
import matplotlib.pyplot as plt
79
import numpy as np
810
import 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
915
from sklearn.cluster import DBSCAN
1016
from tqdm import tqdm
11-
from args import parse_args
12-
from glob import glob
1317

1418

1519
def 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

scripts/run_gamma.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,26 @@ def run_gamma(
2626

2727
# %%
2828
data_path = f"{region}/phasenet"
29+
# data_path = f"{region}/phasenet_plus"
2930
result_path = f"{region}/gamma"
3031
if not os.path.exists(f"{root_path}/{result_path}"):
3132
os.makedirs(f"{root_path}/{result_path}")
3233

3334
# %%
3435
station_json = f"{region}/obspy/stations.json"
35-
if picks_csv is None:
36-
picks_csv = f"{data_path}/phasenet_picks_{node_rank:03d}_{num_nodes:03d}.csv"
37-
gamma_events_csv = f"{result_path}/gamma_events_{node_rank:03d}_{num_nodes:03d}.csv"
38-
gamma_picks_csv = f"{result_path}/gamma_picks_{node_rank:03d}_{num_nodes:03d}.csv"
36+
# if picks_csv is None:
37+
picks_csv = f"{data_path}/phasenet_picks.csv"
38+
# picks_csv = f"{data_path}/phasenet_plus_picks.csv"
39+
gamma_events_csv = f"{result_path}/gamma_events.csv"
40+
gamma_picks_csv = f"{result_path}/gamma_picks.csv"
3941

4042
# %%
4143
## read picks
4244
if protocol == "file":
4345
picks = pd.read_csv(f"{root_path}/{picks_csv}")
4446
else:
4547
picks = pd.read_csv(f"{protocol}://{bucket}/{picks_csv}")
48+
picks.drop(columns=["event_index"], inplace=True, errors="ignore")
4649
picks["id"] = picks["station_id"]
4750
picks["timestamp"] = picks["phase_time"]
4851
if "phase_amp" in picks.columns:
@@ -126,6 +129,8 @@ def run_gamma(
126129
for k, v in config.items():
127130
print(f"{k}: {v}")
128131

132+
print(f"Number of picks: {len(picks)}")
133+
129134
# %%
130135
event_idx0 = 0 ## current earthquake index
131136
assignments = []

scripts/run_phasenet_plus.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def run_phasenet(
125125
)
126126
picks = pd.read_csv(f"{root_path}/{region}/phasenet_plus/picks_phasenet_plus.csv", parse_dates=["phase_time"])
127127
events, picks = associate(picks, events, stations, config)
128+
print(f"Number of picks: {len(picks):,}")
129+
print(f"Number of associated events: {len(events['event_index'].unique()):,}")
128130
events.to_csv(f"{root_path}/{region}/phasenet_plus/phasenet_plus_events_associated.csv", index=False)
129131
picks.to_csv(f"{root_path}/{region}/phasenet_plus/phasenet_plus_picks_associated.csv", index=False)
130132

0 commit comments

Comments
 (0)