jimmy60504 commited on
Commit
c56b1d8
·
1 Parent(s): 82f78ef

refactor: improve code readability and formatting in app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -20
app.py CHANGED
@@ -225,7 +225,8 @@ def generate_earthquake_alert_report(pga_list, target_names, event_name, duratio
225
  county_intensity[county] = intensity_label
226
  else:
227
  # 保留較高的震度
228
- if convert_intensity(intensity_label) > convert_intensity(county_intensity[county]):
 
229
  county_intensity[county] = intensity_label
230
 
231
  # 生成報告
@@ -649,7 +650,7 @@ def create_intensity_map(
649
  mode="markers",
650
  marker=dict(
651
  size=8,
652
- color="rgba(128, 128, 128, 0.3)", # 半透明灰色
653
  ),
654
  text=input_station_texts,
655
  hovertemplate="%{text}<extra></extra>",
@@ -942,7 +943,9 @@ def step3_predict_intensity(cached_waveforms, cached_station_info, cached_statio
942
  )
943
 
944
  # 生成警報文字報告 (duration from waveform length: 3000 samples / 100 Hz = 30 seconds)
945
- duration = cached_waveforms[0].shape[0] / 100 if cached_waveforms is not None and len(cached_waveforms) > 0 else 30
 
 
946
  alert_report = generate_earthquake_alert_report(
947
  pga_list, target_names, event_name, duration
948
  )
@@ -968,11 +971,9 @@ with gr.Blocks(title="TTSAM 震度預測系統", fill_height=True) as demo:
968
  gr.Markdown("## 使用說明")
969
  gr.Markdown(
970
  """
971
- - **選擇地震事件**:自動載入測站並執行預測
972
- - **調整時間滑桿**:即時更新波形與震度預測
973
-
974
- 系統會自動選擇距離震央最近的 25 個測站,並快取資料避免重複讀檔。
975
- """
976
  )
977
  with gr.Column(scale=1):
978
  event_dropdown = gr.Dropdown(
@@ -998,19 +999,14 @@ with gr.Blocks(title="TTSAM 震度預測系統", fill_height=True) as demo:
998
 
999
  # ========== 下層:合併地圖 vs 實際觀測 ==========
1000
  with gr.Row():
1001
- # 實際觀測震度圖
1002
-
1003
- # 合併後的地圖(輸入測站 + 預測震度)
1004
- with gr.Column(scale=1):
1005
- predicted_intensity_map = gr.Plot(label="合併地圖")
1006
 
1007
- with gr.Column(scale=1):
1008
- observed_intensity_image = gr.Image(
1009
- label="實際觀測震度",
1010
- type="filepath",
1011
- value=load_observed_intensity_image(
1012
- list(earthquake_metadata.keys())[0]),
1013
- )
1014
 
1015
  # ========== 隱藏的 State 變數(用於快取中間結果)==========
1016
  cached_stream = gr.State(None) # ObsPy Stream object
 
225
  county_intensity[county] = intensity_label
226
  else:
227
  # 保留較高的震度
228
+ if convert_intensity(intensity_label) > convert_intensity(
229
+ county_intensity[county]):
230
  county_intensity[county] = intensity_label
231
 
232
  # 生成報告
 
650
  mode="markers",
651
  marker=dict(
652
  size=8,
653
+ color="rgba(128, 128, 128, 0.7)", # 半透明灰色
654
  ),
655
  text=input_station_texts,
656
  hovertemplate="%{text}<extra></extra>",
 
943
  )
944
 
945
  # 生成警報文字報告 (duration from waveform length: 3000 samples / 100 Hz = 30 seconds)
946
+ duration = cached_waveforms[0].shape[
947
+ 0] / 100 if cached_waveforms is not None and len(
948
+ cached_waveforms) > 0 else 30
949
  alert_report = generate_earthquake_alert_report(
950
  pga_list, target_names, event_name, duration
951
  )
 
971
  gr.Markdown("## 使用說明")
972
  gr.Markdown(
973
  """
974
+ - **選擇地震事件**:自動載入測站並執行預測
975
+ - **調整時間滑桿**:即時更新波形與震度預測
976
+ """
 
 
977
  )
978
  with gr.Column(scale=1):
979
  event_dropdown = gr.Dropdown(
 
999
 
1000
  # ========== 下層:合併地圖 vs 實際觀測 ==========
1001
  with gr.Row():
1002
+ predicted_intensity_map = gr.Plot(label="合併地圖")
 
 
 
 
1003
 
1004
+ observed_intensity_image = gr.Image(
1005
+ label="實際觀測震度",
1006
+ type="filepath",
1007
+ value=load_observed_intensity_image(
1008
+ list(earthquake_metadata.keys())[0]),
1009
+ )
 
1010
 
1011
  # ========== 隱藏的 State 變數(用於快取中間結果)==========
1012
  cached_stream = gr.State(None) # ObsPy Stream object