Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ except Exception:
|
|
| 16 |
HAS_TABULATE = False
|
| 17 |
|
| 18 |
try:
|
| 19 |
-
import numpy as np
|
| 20 |
import pygmt
|
| 21 |
HAS_PYGMT = True
|
| 22 |
except Exception:
|
|
@@ -122,7 +122,7 @@ def parse_ea0015(obj):
|
|
| 122 |
"Lat": _to_float(lat_raw),
|
| 123 |
"Lon": _to_float(lon_raw),
|
| 124 |
"Depth_km": _to_float(depth),
|
| 125 |
-
"Magnitude": _to_float(
|
| 126 |
"Location": loc,
|
| 127 |
"ReportURL": url,
|
| 128 |
})
|
|
@@ -145,9 +145,9 @@ def _save_fig_to_tmp(fig, suffix=".png", dpi=180):
|
|
| 145 |
def plot_trend_path(df):
|
| 146 |
if df.empty:
|
| 147 |
return None
|
| 148 |
-
|
| 149 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 150 |
-
ax.scatter(df["OriginTime"],
|
| 151 |
ax.set_xlabel("Origin Time (Taipei)")
|
| 152 |
ax.set_ylabel("Magnitude")
|
| 153 |
ax.grid(True, linestyle="--", alpha=0.4)
|
|
@@ -177,7 +177,6 @@ def plot_map_path(df):
|
|
| 177 |
shorelines="0.5p,black", borders="1/0.6p,black",
|
| 178 |
frame=["WSen", "xaf", "yaf"]
|
| 179 |
)
|
| 180 |
-
# 變動大小:使用 sizes 參數(單位 cm),色彩以 depth
|
| 181 |
fig.plot(
|
| 182 |
x=d["Lon"].to_list(), y=d["Lat"].to_list(),
|
| 183 |
style="cc", sizes=size_cm.to_list(),
|
|
@@ -197,14 +196,15 @@ def plot_map_path(df):
|
|
| 197 |
ax.set_xlim(lon_min, lon_max)
|
| 198 |
ax.set_ylim(lat_min, lat_max)
|
| 199 |
|
| 200 |
-
|
| 201 |
-
s = (
|
| 202 |
depth = pd.to_numeric(df["Depth_km"], errors="coerce")
|
| 203 |
|
| 204 |
sc = ax.scatter(df["Lon"], df["Lat"], s=s, c=depth, alpha=0.85, edgecolor="black")
|
| 205 |
cb = plt.colorbar(sc, ax=ax, fraction=0.046, pad=0.04)
|
| 206 |
cb.set_label("Depth (km)")
|
| 207 |
-
ax.set_xlabel("Longitude (°E)")
|
|
|
|
| 208 |
ax.set_title("Epicenters in Taiwan Region (119–123E, 21–26N)")
|
| 209 |
ax.grid(True, linestyle="--", alpha=0.3)
|
| 210 |
return _save_fig_to_tmp(fig)
|
|
|
|
| 16 |
HAS_TABULATE = False
|
| 17 |
|
| 18 |
try:
|
| 19 |
+
import numpy as np # noqa: F401
|
| 20 |
import pygmt
|
| 21 |
HAS_PYGMT = True
|
| 22 |
except Exception:
|
|
|
|
| 122 |
"Lat": _to_float(lat_raw),
|
| 123 |
"Lon": _to_float(lon_raw),
|
| 124 |
"Depth_km": _to_float(depth),
|
| 125 |
+
"Magnitude": _to_float(mag), # ← 修正:用 mag,不是 m
|
| 126 |
"Location": loc,
|
| 127 |
"ReportURL": url,
|
| 128 |
})
|
|
|
|
| 145 |
def plot_trend_path(df):
|
| 146 |
if df.empty:
|
| 147 |
return None
|
| 148 |
+
mag = pd.to_numeric(df["Magnitude"], errors="coerce")
|
| 149 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 150 |
+
ax.scatter(df["OriginTime"], mag)
|
| 151 |
ax.set_xlabel("Origin Time (Taipei)")
|
| 152 |
ax.set_ylabel("Magnitude")
|
| 153 |
ax.grid(True, linestyle="--", alpha=0.4)
|
|
|
|
| 177 |
shorelines="0.5p,black", borders="1/0.6p,black",
|
| 178 |
frame=["WSen", "xaf", "yaf"]
|
| 179 |
)
|
|
|
|
| 180 |
fig.plot(
|
| 181 |
x=d["Lon"].to_list(), y=d["Lat"].to_list(),
|
| 182 |
style="cc", sizes=size_cm.to_list(),
|
|
|
|
| 196 |
ax.set_xlim(lon_min, lon_max)
|
| 197 |
ax.set_ylim(lat_min, lat_max)
|
| 198 |
|
| 199 |
+
mag = pd.to_numeric(df["Magnitude"], errors="coerce").fillna(0).clip(lower=0)
|
| 200 |
+
s = (mag + 2) ** 3
|
| 201 |
depth = pd.to_numeric(df["Depth_km"], errors="coerce")
|
| 202 |
|
| 203 |
sc = ax.scatter(df["Lon"], df["Lat"], s=s, c=depth, alpha=0.85, edgecolor="black")
|
| 204 |
cb = plt.colorbar(sc, ax=ax, fraction=0.046, pad=0.04)
|
| 205 |
cb.set_label("Depth (km)")
|
| 206 |
+
ax.set_xlabel("Longitude (°E)")
|
| 207 |
+
ax.set_ylabel("Latitude (°N)")
|
| 208 |
ax.set_title("Epicenters in Taiwan Region (119–123E, 21–26N)")
|
| 209 |
ax.grid(True, linestyle="--", alpha=0.3)
|
| 210 |
return _save_fig_to_tmp(fig)
|