filtered_data_gmt.txt (100.0 KB)
this is the file.
import numpy as np
import pygmt
fig = pygmt.Figure()
# CPT (adjust to your depth/magnitude range if needed)
pygmt.makecpt(cmap="red,green,blue", series="0/300/10", output="quakes.cpt")
# --------------------
# 1) MAP PANEL
# --------------------
fig.coast(
region=[127.6, 134.4, 30, 34.4],
projection="M4i",
frame=["xa1g1", "ya1g1", '+t"Kyushu"'],
land="lightbrown",
shorelines="0.25p",
)
fig.basemap(
map_scale="jBR+w200k+o0.5c/0.5c+f"
)
fig.plot(
data="filtered_data_gmt.txt",
style="c0.15c",
pen="faint",
cmap="quakes.cpt",
)
# --------------------
# 2) AUTO PROFILE LINE (PCA, NO EXTENSION) + PROJECT
# --------------------
xy = np.loadtxt("filtered_data_gmt.txt", usecols=(0, 1), skiprows=1)
lon = xy[:, 0]
lat = xy[:, 1]
X = np.column_stack([lon, lat])
X0 = X - X.mean(axis=0)
C = np.cov(X0.T)
eigvals, eigvecs = np.linalg.eig(C)
v = eigvecs[:, np.argmax(eigvals)]
# Keep direction consistent
if v[0] < 0:
v = -v
t = X0 @ v
tmin, tmax = t.min(), t.max()
# A and B exactly at data limits (NO extension)
A = X.mean(axis=0) + tmin * v
B = X.mean(axis=0) + tmax * v
# Plot the profile line in BLACK
fig.plot(
x=[A[0], B[0]],
y=[A[1], B[1]],
pen="2p,black",
)
# Project earthquakes onto the profile
pygmt.project(
data="filtered_data_gmt.txt",
unit=True,
center=[float(A[0]), float(A[1])],
endpoint=[float(B[0]), float(B[1])],
convention="pz",
width=[-100, 100],
outfile="cross.dat",
output_type="file",
)
# --------------------
# 3) CROSS-SECTION PANEL
# --------------------
fig.shift_origin(yshift="-8c")
fig.basemap(
projection="X10c/-6c",
region=[0, 80, 0, 50],
frame=[
'xafg10+l"Distance (km)"',
'yafg10+l"Depth (km)"',
"WSen",
],
)
fig.plot(
data="cross.dat",
style="c0.2c",
pen="0.5p,black",
fill="red",
)
# --------------------
# 4) OUTPUT
# --------------------
fig.savefig("kyushu_cross_section.pdf")
fig.show()