chen commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from matplotlib.patches import Circle
|
|
| 7 |
def calculate_gravity_anomalies(mountain_height, subsurface_density, subsurface_position):
|
| 8 |
"""
|
| 9 |
根據地形和地下異常體,計算並繪製重力異常曲線。
|
|
|
|
| 10 |
"""
|
| 11 |
# 1. 建立空間座標 (模擬一條 100 公里的測線)
|
| 12 |
x = np.linspace(-50, 50, 500)
|
|
@@ -32,38 +33,38 @@ def calculate_gravity_anomalies(mountain_height, subsurface_density, subsurface_
|
|
| 32 |
# FAA = BA + BC
|
| 33 |
free_air_anomaly = bouguer_anomaly + bouguer_correction
|
| 34 |
|
| 35 |
-
# --- Matplotlib 繪圖 ---
|
| 36 |
fig, ax1 = plt.subplots(figsize=(12, 8))
|
| 37 |
|
| 38 |
# 設定主 Y 軸 (重力異常)
|
| 39 |
-
ax1.set_xlabel('
|
| 40 |
-
ax1.set_ylabel('
|
| 41 |
ax1.tick_params(axis='y', labelcolor='tab:red')
|
| 42 |
ax1.grid(True, linestyle='--', alpha=0.6)
|
| 43 |
|
| 44 |
# 繪製重力曲線
|
| 45 |
-
ax1.plot(x, free_air_anomaly, 'b--', label='
|
| 46 |
-
ax1.plot(x, bouguer_anomaly, 'r-', label='
|
| 47 |
ax1.legend(loc='upper left', fontsize=12)
|
| 48 |
ax1.set_ylim(-35, 85) # 固定 Y 軸範圍以便比較
|
| 49 |
|
| 50 |
# 設定次 Y 軸 (地形/深度)
|
| 51 |
ax2 = ax1.twinx()
|
| 52 |
-
ax2.set_ylabel('
|
| 53 |
ax2.tick_params(axis='y', labelcolor='tab:green')
|
| 54 |
|
| 55 |
# 繪製地形
|
| 56 |
-
ax2.fill_between(x, 0, topography, color='saddlebrown', alpha=0.4, label='
|
| 57 |
|
| 58 |
# 繪製地下異常體
|
| 59 |
subsurface_depth = -200 # 固定深度
|
| 60 |
body_color = 'darkred' if subsurface_density >= 0 else 'darkblue'
|
| 61 |
body_alpha = min(1.0, 0.2 + abs(subsurface_density)/50.0) # 密度越大顏色越深
|
| 62 |
-
circle = Circle((subsurface_position, subsurface_depth), radius=body_width*0.8, color=body_color, alpha=body_alpha
|
| 63 |
ax2.add_patch(circle)
|
| 64 |
ax2.set_ylim(-500, 1500) # 固定地形/深度軸範圍
|
| 65 |
|
| 66 |
-
fig.suptitle('
|
| 67 |
plt.tight_layout(rect=[0, 0.03, 1, 0.95]) # 調整佈局以容納標題
|
| 68 |
|
| 69 |
# 關閉 matplotlib 的自動顯示,將 figure 物件交給 Gradio 處理
|
|
@@ -71,7 +72,7 @@ def calculate_gravity_anomalies(mountain_height, subsurface_density, subsurface_
|
|
| 71 |
|
| 72 |
return fig
|
| 73 |
|
| 74 |
-
# --- Gradio 介面設定 ---
|
| 75 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 76 |
gr.Markdown(
|
| 77 |
"""
|
|
@@ -79,8 +80,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 79 |
歡迎來到重力探勘互動實驗室!在這裡,你可以親手操作變數,理解地球物理學家如何「看透」地表。
|
| 80 |
|
| 81 |
### 操作指南:
|
| 82 |
-
1. **調整「山脈高度」滑桿:** 觀察藍色虛線 (
|
| 83 |
-
2. **調整「地下異常體密度」與「位置」:** 觀察紅色實線 (
|
| 84 |
|
| 85 |
**核心思想:** 布格校正的目的,就是從充滿地形雜訊的「自由空間重力異常」中,減去地形的影響,得到能真正反映地下密度的「布格異常」。
|
| 86 |
"""
|
|
|
|
| 7 |
def calculate_gravity_anomalies(mountain_height, subsurface_density, subsurface_position):
|
| 8 |
"""
|
| 9 |
根據地形和地下異常體,計算並繪製重力異常曲線。
|
| 10 |
+
(All plot labels are in English to prevent font issues on cloud platforms.)
|
| 11 |
"""
|
| 12 |
# 1. 建立空間座標 (模擬一條 100 公里的測線)
|
| 13 |
x = np.linspace(-50, 50, 500)
|
|
|
|
| 33 |
# FAA = BA + BC
|
| 34 |
free_air_anomaly = bouguer_anomaly + bouguer_correction
|
| 35 |
|
| 36 |
+
# --- Matplotlib 繪圖 (English Labels) ---
|
| 37 |
fig, ax1 = plt.subplots(figsize=(12, 8))
|
| 38 |
|
| 39 |
# 設定主 Y 軸 (重力異常)
|
| 40 |
+
ax1.set_xlabel('Profile Position (km)', fontsize=14)
|
| 41 |
+
ax1.set_ylabel('Gravity Anomaly (mGal)', color='tab:red', fontsize=14)
|
| 42 |
ax1.tick_params(axis='y', labelcolor='tab:red')
|
| 43 |
ax1.grid(True, linestyle='--', alpha=0.6)
|
| 44 |
|
| 45 |
# 繪製重力曲線
|
| 46 |
+
ax1.plot(x, free_air_anomaly, 'b--', label='Free-air Anomaly ($\Delta g_{fa}$)', linewidth=2)
|
| 47 |
+
ax1.plot(x, bouguer_anomaly, 'r-', label='Bouguer Anomaly ($\Delta g_{B}$)', linewidth=3, alpha=0.9)
|
| 48 |
ax1.legend(loc='upper left', fontsize=12)
|
| 49 |
ax1.set_ylim(-35, 85) # 固定 Y 軸範圍以便比較
|
| 50 |
|
| 51 |
# 設定次 Y 軸 (地形/深度)
|
| 52 |
ax2 = ax1.twinx()
|
| 53 |
+
ax2.set_ylabel('Elevation / Depth (m)', color='tab:green', fontsize=14)
|
| 54 |
ax2.tick_params(axis='y', labelcolor='tab:green')
|
| 55 |
|
| 56 |
# 繪製地形
|
| 57 |
+
ax2.fill_between(x, 0, topography, color='saddlebrown', alpha=0.4, label='Topography')
|
| 58 |
|
| 59 |
# 繪製地下異常體
|
| 60 |
subsurface_depth = -200 # 固定深度
|
| 61 |
body_color = 'darkred' if subsurface_density >= 0 else 'darkblue'
|
| 62 |
body_alpha = min(1.0, 0.2 + abs(subsurface_density)/50.0) # 密度越大顏色越深
|
| 63 |
+
circle = Circle((subsurface_position, subsurface_depth), radius=body_width*0.8, color=body_color, alpha=body_alpha)
|
| 64 |
ax2.add_patch(circle)
|
| 65 |
ax2.set_ylim(-500, 1500) # 固定地形/深度軸範圍
|
| 66 |
|
| 67 |
+
fig.suptitle('Interactive Bouguer Anomaly Lab', fontsize=20, weight='bold')
|
| 68 |
plt.tight_layout(rect=[0, 0.03, 1, 0.95]) # 調整佈局以容納標題
|
| 69 |
|
| 70 |
# 關閉 matplotlib 的自動顯示,將 figure 物件交給 Gradio 處理
|
|
|
|
| 72 |
|
| 73 |
return fig
|
| 74 |
|
| 75 |
+
# --- Gradio 介面設定 (UI remains in Chinese) ---
|
| 76 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 77 |
gr.Markdown(
|
| 78 |
"""
|
|
|
|
| 80 |
歡迎來到重力探勘互動實驗室!在這裡,你可以親手操作變數,理解地球物理學家如何「看透」地表。
|
| 81 |
|
| 82 |
### 操作指南:
|
| 83 |
+
1. **調整「山脈高度」滑桿:** 觀察藍色虛線 (Free-air Anomaly) 如何緊緊跟隨地形變化。
|
| 84 |
+
2. **調整「地下異常體密度」與「位置」:** 觀察紅色實線 (Bouguer Anomaly) 如何只反映地下物質的變化,幾乎不受地表高山的影響。
|
| 85 |
|
| 86 |
**核心思想:** 布格校正的目的,就是從充滿地形雜訊的「自由空間重力異常」中,減去地形的影響,得到能真正反映地下密度的「布格異常」。
|
| 87 |
"""
|