Skip to content

Commit 8de306f

Browse files
committed
update station term for california
1 parent 0208470 commit 8de306f

File tree

2 files changed

+207
-42
lines changed

2 files changed

+207
-42
lines changed

examples/california/plotting.py

Lines changed: 177 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def plotting(stations, figure_path, config, picks, events_old, locations, statio
3333
im = ax[0, 1].scatter(
3434
stations["x_km"],
3535
stations["y_km"],
36-
c=stations["station_term"],
36+
c=stations["station_term_time_p"],
3737
cmap="viridis_r",
3838
s=100,
3939
marker="^",
@@ -43,7 +43,7 @@ def plotting(stations, figure_path, config, picks, events_old, locations, statio
4343
ax[0, 1].set_ylim([ymin, ymax])
4444
cbar = fig.colorbar(im, ax=ax[0, 1])
4545
cbar.set_label("Residual (s)")
46-
ax[0, 1].set_title(f"Station term: {np.mean(np.abs(stations['station_term'].values)):.4f} s")
46+
ax[0, 1].set_title(f"Station term (P): {np.mean(np.abs(stations['station_term_time_p'].values)):.4f} s")
4747

4848
im = ax[1, 0].scatter(
4949
locations["x_km"],
@@ -265,14 +265,21 @@ def plotting_ransac(stations, figure_path, config, picks, events_init, events, s
265265
plt.savefig(os.path.join(figure_path, f"error{suffix}.png"), bbox_inches="tight", dpi=300)
266266
plt.close(fig)
267267

268-
xmin, xmax = config["xlim_km"]
269-
ymin, ymax = config["ylim_km"]
270-
zmin, zmax = config["zlim_km"]
271-
vmin, vmax = config["zlim_km"]
268+
# xmin, xmax = config["xlim_km"]
269+
# ymin, ymax = config["ylim_km"]
270+
# zmin, zmax = config["zlim_km"]
271+
# vmin, vmax = config["zlim_km"]
272+
xmin = events["x_km"].min()
273+
xmax = events["x_km"].max()
274+
ymin = events["y_km"].min()
275+
ymax = events["y_km"].max()
276+
zmin = events["z_km"].min()
277+
zmax = events["z_km"].max()
278+
vmin, vmax = zmin, zmax
272279
events = events.sort_values("time", ascending=True)
273280
s = max(0.1, min(10, 5000 / len(events)))
274281
alpha = 0.8
275-
fig, ax = plt.subplots(2, 3, figsize=(18, 8), gridspec_kw={"height_ratios": [2, 1]})
282+
fig, ax = plt.subplots(2, 4, figsize=(25, 8), gridspec_kw={"height_ratios": [2, 1]})
276283
# fig, ax = plt.subplots(2, 3, figsize=(15, 8), gridspec_kw={"height_ratios": [2, 1]})
277284
im = ax[0, 0].scatter(
278285
events["x_km"],
@@ -299,7 +306,7 @@ def plotting_ransac(stations, figure_path, config, picks, events_init, events, s
299306
im = ax[0, 1].scatter(
300307
stations["x_km"],
301308
stations["y_km"],
302-
c=stations["station_term_time"],
309+
c=stations["station_term_time_p"],
303310
cmap="viridis_r",
304311
s=100,
305312
marker="^",
@@ -312,12 +319,12 @@ def plotting_ransac(stations, figure_path, config, picks, events_init, events, s
312319
ax[0, 1].set_ylabel("Y (km)")
313320
cbar = fig.colorbar(im, ax=ax[0, 1])
314321
cbar.set_label("Residual (s)")
315-
ax[0, 1].set_title(f"Station term: {np.mean(np.abs(stations['station_term_time'].values)):.4f} s")
322+
ax[0, 1].set_title(f"Station term (P): {np.mean(np.abs(stations['station_term_time_p'].values)):.4f} s")
316323

317324
im = ax[0, 2].scatter(
318325
stations["x_km"],
319326
stations["y_km"],
320-
c=stations["station_term_amplitude"],
327+
c=stations["station_term_time_s"],
321328
cmap="viridis_r",
322329
s=100,
323330
marker="^",
@@ -329,8 +336,26 @@ def plotting_ransac(stations, figure_path, config, picks, events_init, events, s
329336
ax[0, 2].set_xlabel("X (km)")
330337
ax[0, 2].set_ylabel("Y (km)")
331338
cbar = fig.colorbar(im, ax=ax[0, 2])
339+
cbar.set_label("Residual (s)")
340+
ax[0, 2].set_title(f"Station term (S): {np.mean(np.abs(stations['station_term_time_s'].values)):.4f} s")
341+
342+
im = ax[0, 3].scatter(
343+
stations["x_km"],
344+
stations["y_km"],
345+
c=stations["station_term_amplitude"],
346+
cmap="viridis_r",
347+
s=100,
348+
marker="^",
349+
alpha=alpha,
350+
)
351+
ax[0, 3].set_aspect("equal", "box")
352+
ax[0, 3].set_xlim([xmin, xmax])
353+
ax[0, 3].set_ylim([ymin, ymax])
354+
ax[0, 3].set_xlabel("X (km)")
355+
ax[0, 3].set_ylabel("Y (km)")
356+
cbar = fig.colorbar(im, ax=ax[0, 3])
332357
cbar.set_label("Residual (log10 cm/s)")
333-
ax[0, 2].set_title(f"Station term: {np.mean(np.abs(stations['station_term_amplitude'].values)):.4f} s")
358+
ax[0, 3].set_title(f"Station term: {np.mean(np.abs(stations['station_term_amplitude'].values)):.4f} (log10 cm/s)")
334359

335360
## Separate P and S station term
336361
# im = ax[0, 1].scatter(
@@ -402,5 +427,146 @@ def plotting_ransac(stations, figure_path, config, picks, events_init, events, s
402427
# ax[1, 1].set_ylabel("Depth (km)")
403428
cbar = fig.colorbar(im, ax=ax[1, 1])
404429
cbar.set_label("Depth (km)")
430+
431+
if "magnitude" in events.columns:
432+
im = ax[1, 2].hist(events["magnitude"], bins=30, edgecolor="white")
433+
ax[1, 2].set_yscale("log")
434+
ax[1, 2].set_xlabel("Magnitude")
435+
ax[1, 2].set_ylabel("Count")
436+
405437
plt.savefig(os.path.join(figure_path, f"location{suffix}.png"), bbox_inches="tight", dpi=300)
406438
plt.close(fig)
439+
440+
441+
# %%
442+
def plotting_dd(events, stations, config, figure_path, events_old, suffix=""):
443+
444+
xmin, xmax = config["xlim_km"]
445+
ymin, ymax = config["ylim_km"]
446+
zmin, zmax = config["zlim_km"]
447+
vmin, vmax = zmin, zmax
448+
449+
s = max(0.1, min(10, 5000 / len(events)))
450+
alpha = 0.8
451+
452+
fig, ax = plt.subplots(3, 2, figsize=(10, 10), gridspec_kw={"height_ratios": [2, 1, 1]})
453+
im = ax[0, 0].scatter(
454+
events_old["x_km"],
455+
events_old["y_km"],
456+
c=events_old["z_km"],
457+
cmap="viridis_r",
458+
s=s,
459+
marker="o",
460+
vmin=vmin,
461+
vmax=vmax,
462+
alpha=alpha,
463+
linewidth=0.0,
464+
)
465+
ax[0, 0].set_xlim([xmin, xmax])
466+
ax[0, 0].set_ylim([ymin, ymax])
467+
cbar = fig.colorbar(im, ax=ax[0, 0])
468+
cbar.set_label("Depth (km)")
469+
ax[0, 0].set_title(f"ADLoc: {len(events_old)} events")
470+
471+
im = ax[0, 1].scatter(
472+
events["x_km"],
473+
events["y_km"],
474+
c=events["z_km"],
475+
cmap="viridis_r",
476+
s=s,
477+
marker="o",
478+
vmin=vmin,
479+
vmax=vmax,
480+
alpha=alpha,
481+
linewidth=0.0,
482+
)
483+
ax[0, 1].set_xlim([xmin, xmax])
484+
ax[0, 1].set_ylim([ymin, ymax])
485+
cbar = fig.colorbar(im, ax=ax[0, 1])
486+
cbar.set_label("Depth (km)")
487+
ax[0, 1].set_title(f"ADLoc DD: {len(events)} events")
488+
489+
# im = ax[1, 0].scatter(
490+
# events_new["x_km"],
491+
# events_new["z_km"],
492+
# c=events_new["z_km"],
493+
# cmap="viridis_r",
494+
# s=1,
495+
# marker="o",
496+
# vmin=vmin,
497+
# vmax=vmax,
498+
# )
499+
# ax[1, 0].set_xlim([xmin, xmax])
500+
# ax[1, 0].set_ylim([zmax, zmin])
501+
# cbar = fig.colorbar(im, ax=ax[1, 0])
502+
# cbar.set_label("Depth (km)")
503+
504+
im = ax[1, 0].scatter(
505+
events_old["x_km"],
506+
events_old["z_km"],
507+
c=events_old["z_km"],
508+
cmap="viridis_r",
509+
s=s,
510+
marker="o",
511+
vmin=vmin,
512+
vmax=vmax,
513+
alpha=alpha,
514+
linewidth=0.0,
515+
)
516+
ax[1, 0].set_xlim([xmin, xmax])
517+
ax[1, 0].set_ylim([zmax, zmin])
518+
cbar = fig.colorbar(im, ax=ax[1, 0])
519+
cbar.set_label("Depth (km)")
520+
521+
im = ax[1, 1].scatter(
522+
events["x_km"],
523+
events["z_km"],
524+
c=events["z_km"],
525+
cmap="viridis_r",
526+
s=s,
527+
marker="o",
528+
vmin=vmin,
529+
vmax=vmax,
530+
alpha=alpha,
531+
linewidth=0.0,
532+
)
533+
ax[1, 1].set_xlim([xmin, xmax])
534+
ax[1, 1].set_ylim([zmax, zmin])
535+
cbar = fig.colorbar(im, ax=ax[1, 1])
536+
cbar.set_label("Depth (km)")
537+
538+
im = ax[2, 0].scatter(
539+
events_old["y_km"],
540+
events_old["z_km"],
541+
c=events_old["z_km"],
542+
cmap="viridis_r",
543+
s=s,
544+
marker="o",
545+
vmin=vmin,
546+
vmax=vmax,
547+
alpha=alpha,
548+
linewidth=0.0,
549+
)
550+
ax[2, 0].set_xlim([ymin, ymax])
551+
ax[2, 0].set_ylim([zmax, zmin])
552+
cbar = fig.colorbar(im, ax=ax[2, 0])
553+
cbar.set_label("Depth (km)")
554+
555+
im = ax[2, 1].scatter(
556+
events["y_km"],
557+
events["z_km"],
558+
c=events["z_km"],
559+
cmap="viridis_r",
560+
s=s,
561+
marker="o",
562+
vmin=vmin,
563+
vmax=vmax,
564+
alpha=alpha,
565+
linewidth=0.0,
566+
)
567+
ax[2, 1].set_xlim([ymin, ymax])
568+
ax[2, 1].set_ylim([zmax, zmin])
569+
cbar = fig.colorbar(im, ax=ax[2, 1])
570+
cbar.set_label("Depth (km)")
571+
572+
plt.savefig(os.path.join(figure_path, f"location{suffix}.png"), bbox_inches="tight", dpi=300)

examples/california/run_adloc.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def run_adloc(
4040
jday = int(jday.split(".")[1])
4141

4242
# %%
43-
data_path = f"{region}/gamma_bo_debug/{year:04d}"
43+
data_path = f"{region}/gamma_bo/{year:04d}"
4444
result_path = f"{region}/adloc/{year:04d}"
4545
if not os.path.exists(f"{root_path}/{result_path}"):
4646
os.makedirs(f"{root_path}/{result_path}")
@@ -110,8 +110,10 @@ def run_adloc(
110110

111111
# %%
112112
stations["depth_km"] = -stations["elevation_m"] / 1000
113-
if "station_term_time" not in stations.columns:
114-
stations["station_term_time"] = 0.0
113+
if "station_term_time_p" not in stations.columns:
114+
stations["station_term_time_p"] = 0.0
115+
if "station_term_time_s" not in stations.columns:
116+
stations["station_term_time_s"] = 0.0
115117
if "station_term_amplitude" not in stations.columns:
116118
stations["station_term_amplitude"] = 0.0
117119
stations[["x_km", "y_km"]] = stations.apply(
@@ -229,16 +231,15 @@ def run_adloc(
229231
# suffix=f"_ransac_sst_{iter}",
230232
# )
231233

232-
stations["station_term"] = 0.0
233-
plotting(
234-
stations,
235-
f"{root_path}/{figure_path}",
236-
config,
237-
picks,
238-
events_init,
239-
events_init,
240-
suffix=f"_ransac_sst_init",
241-
)
234+
# plotting(
235+
# stations,
236+
# f"{root_path}/{figure_path}",
237+
# config,
238+
# picks,
239+
# events_init,
240+
# events_init,
241+
# suffix=f"_ransac_sst_init",
242+
# )
242243

243244
for iter in range(MAX_SST_ITER):
244245
if iter == 0:
@@ -257,7 +258,8 @@ def run_adloc(
257258
config["min_score"] = 0.5
258259
config["min_p_picks"] = 0 # for filtering
259260
config["min_s_picks"] = 0 # for filtering
260-
stations["station_term_time"] = 0.0 # no station term
261+
stations["station_term_time_p"] = 0.0 # no station term
262+
stations["station_term_time_s"] = 0.0 # no station term
261263
# picks, events = invert_location_iter(picks, stations, config, estimator, events_init=events_init, iter=iter)
262264
if iter == 0:
263265
picks, events = invert_location(picks, stations, config, estimator, events_init=events_init, iter=iter)
@@ -268,31 +270,28 @@ def run_adloc(
268270
)
269271
# station_term = picks[picks["mask"] == 1.0].groupby("idx_sta").agg({"residual_time": "mean"}).reset_index()
270272
station_term_time = (
271-
picks[picks["mask"] == 1.0].groupby("idx_sta").agg({"residual_time": "mean"}).reset_index()
273+
picks[picks["mask"] == 1.0]
274+
.groupby(["idx_sta", "phase_type"])
275+
.agg({"residual_time": "mean"})
276+
.reset_index()
272277
)
278+
station_term_time.set_index("idx_sta", inplace=True)
273279
station_term_amp = (
274280
picks[picks["mask"] == 1.0].groupby("idx_sta").agg({"residual_amplitude": "mean"}).reset_index()
275281
)
276-
stations["station_term_time"] += (
277-
stations["idx_sta"].map(station_term_time.set_index("idx_sta")["residual_time"]).fillna(0)
282+
stations["station_term_time_p"] += (
283+
stations["idx_sta"]
284+
.map(station_term_time[station_term_time["phase_type"] == 0]["residual_time"])
285+
.fillna(0)
286+
)
287+
stations["station_term_time_s"] += (
288+
stations["idx_sta"]
289+
.map(station_term_time[station_term_time["phase_type"] == 1]["residual_time"])
290+
.fillna(0)
278291
)
279292
stations["station_term_amplitude"] += (
280293
stations["idx_sta"].map(station_term_amp.set_index("idx_sta")["residual_amplitude"]).fillna(0)
281294
)
282-
## Separate P and S station term
283-
# station_term = (
284-
# picks[picks["mask"] == 1.0].groupby(["idx_sta", "phase_type"]).agg({"residual": "mean"}).reset_index()
285-
# )
286-
# stations["station_term_p"] = (
287-
# stations["idx_sta"]
288-
# .map(station_term[station_term["phase_type"] == 0].set_index("idx_sta")["residual"])
289-
# .fillna(0)
290-
# )
291-
# stations["station_term_s"] = (
292-
# stations["idx_sta"]
293-
# .map(station_term[station_term["phase_type"] == 1].set_index("idx_sta")["residual"])
294-
# .fillna(0)
295-
# )
296295

297296
# plotting_ransac(
298297
# stations,

0 commit comments

Comments
 (0)