cwadayi commited on
Commit
424e5fd
·
verified ·
1 Parent(s): de88d4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -22,6 +22,15 @@ try:
22
  except Exception:
23
  HAS_PYGMT = False
24
 
 
 
 
 
 
 
 
 
 
25
  # -----------------------------
26
  # 台北時區 (UTC+8)
27
  # -----------------------------
@@ -187,12 +196,10 @@ def plot_map_path(df):
187
  if df.empty:
188
  return None
189
 
190
- # 先清一下 NaN
191
  d = df.dropna(subset=["Lon", "Lat"]).copy()
192
  if d.empty:
193
  return None
194
 
195
- # 數值化
196
  d["Magnitude"] = pd.to_numeric(d["Magnitude"], errors="coerce").fillna(0).clip(lower=0)
197
  d["Depth_km"] = pd.to_numeric(d["Depth_km"], errors="coerce").fillna(0)
198
 
@@ -204,8 +211,9 @@ def plot_map_path(df):
204
  fig = pygmt.Figure()
205
  fig.coast(
206
  region=region, projection="M12c",
207
- land="lightgray", water="white",
208
- shorelines="0.5p,black", borders="1/0.6p,black",
 
209
  frame=["WSen", "xaf", "yaf"]
210
  )
211
  fig.plot(
@@ -220,7 +228,7 @@ def plot_map_path(df):
220
  fig.savefig(outpath, dpi=220)
221
  return outpath
222
 
223
- # --- Matplotlib 備援(自動範圍 + 簡易海岸線無法;以格線為主) ---
224
  region = _auto_region_from_df(d, pad=0.5)
225
  lon_min, lon_max, lat_min, lat_max = region
226
 
 
22
  except Exception:
23
  HAS_PYGMT = False
24
 
25
+ # ---- 自動抓取 PyGMT 所需的海岸線/國界資料(GSHHG/DCW) ----
26
+ if 'HAS_PYGMT' in globals() and HAS_PYGMT:
27
+ try:
28
+ pygmt.which("@gshhg", download=True)
29
+ pygmt.which("@dcw", download=True)
30
+ except Exception:
31
+ # 若下載失敗就靜默忽略,之後會走 matplotlib 備援
32
+ pass
33
+
34
  # -----------------------------
35
  # 台北時區 (UTC+8)
36
  # -----------------------------
 
196
  if df.empty:
197
  return None
198
 
 
199
  d = df.dropna(subset=["Lon", "Lat"]).copy()
200
  if d.empty:
201
  return None
202
 
 
203
  d["Magnitude"] = pd.to_numeric(d["Magnitude"], errors="coerce").fillna(0).clip(lower=0)
204
  d["Depth_km"] = pd.to_numeric(d["Depth_km"], errors="coerce").fillna(0)
205
 
 
211
  fig = pygmt.Figure()
212
  fig.coast(
213
  region=region, projection="M12c",
214
+ resolution="i", # 中解析度海岸線
215
+ land="lightgray", water="lightblue",
216
+ shorelines="0.8p,black", borders="1/0.6p,black",
217
  frame=["WSen", "xaf", "yaf"]
218
  )
219
  fig.plot(
 
228
  fig.savefig(outpath, dpi=220)
229
  return outpath
230
 
231
+ # --- Matplotlib 備援(自動範圍,無海岸線) ---
232
  region = _auto_region_from_df(d, pad=0.5)
233
  lon_min, lon_max, lat_min, lat_max = region
234