Spaces:
Runtime error
Runtime error
Commit ·
f202901
1
Parent(s): ef96627
docs: update map visualization for earthquake data with improved marker sizes and layout adjustments
Browse files
app.py
CHANGED
|
@@ -751,11 +751,11 @@ def create_input_station_map(selected_stations, epicenter_lat, epicenter_lon):
|
|
| 751 |
fig = go.Figure()
|
| 752 |
|
| 753 |
# 添加所有測站(灰色小點)
|
| 754 |
-
fig.add_trace(go.
|
| 755 |
lat=all_stations_lat,
|
| 756 |
lon=all_stations_lon,
|
| 757 |
mode='markers',
|
| 758 |
-
marker=dict(size=
|
| 759 |
text=all_stations_text,
|
| 760 |
hovertemplate='%{text}<extra></extra>',
|
| 761 |
name=f'所有測站 ({len(all_stations_lat)} 個)',
|
|
@@ -764,7 +764,7 @@ def create_input_station_map(selected_stations, epicenter_lat, epicenter_lon):
|
|
| 764 |
|
| 765 |
# 添加選中測站 - 前 5 近(綠色)
|
| 766 |
if selected_group1_lat:
|
| 767 |
-
fig.add_trace(go.
|
| 768 |
lat=selected_group1_lat,
|
| 769 |
lon=selected_group1_lon,
|
| 770 |
mode='markers',
|
|
@@ -777,7 +777,7 @@ def create_input_station_map(selected_stations, epicenter_lat, epicenter_lon):
|
|
| 777 |
|
| 778 |
# 添加選中測站 - 6-15 近(藍色)
|
| 779 |
if selected_group2_lat:
|
| 780 |
-
fig.add_trace(go.
|
| 781 |
lat=selected_group2_lat,
|
| 782 |
lon=selected_group2_lon,
|
| 783 |
mode='markers',
|
|
@@ -790,7 +790,7 @@ def create_input_station_map(selected_stations, epicenter_lat, epicenter_lon):
|
|
| 790 |
|
| 791 |
# 添加選中測站 - 16-25 近(橘色)
|
| 792 |
if selected_group3_lat:
|
| 793 |
-
fig.add_trace(go.
|
| 794 |
lat=selected_group3_lat,
|
| 795 |
lon=selected_group3_lon,
|
| 796 |
mode='markers',
|
|
@@ -801,31 +801,39 @@ def create_input_station_map(selected_stations, epicenter_lat, epicenter_lon):
|
|
| 801 |
showlegend=True
|
| 802 |
))
|
| 803 |
|
| 804 |
-
# 添加震央(紅色
|
| 805 |
-
fig.add_trace(go.
|
| 806 |
lat=[epicenter_lat],
|
| 807 |
lon=[epicenter_lon],
|
| 808 |
mode='markers',
|
| 809 |
-
marker=dict(size=
|
| 810 |
text=[f'震央<br>({epicenter_lat:.3f}, {epicenter_lon:.3f})'],
|
| 811 |
hovertemplate='%{text}<extra></extra>',
|
| 812 |
name='震央',
|
| 813 |
showlegend=True
|
| 814 |
))
|
| 815 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 816 |
# 設置地圖佈局
|
| 817 |
fig.update_layout(
|
| 818 |
-
|
| 819 |
style="open-street-map",
|
| 820 |
center=dict(lat=epicenter_lat, lon=epicenter_lon),
|
| 821 |
-
zoom=
|
| 822 |
),
|
| 823 |
-
height=
|
| 824 |
margin=dict(l=0, r=0, t=0, b=0),
|
| 825 |
showlegend=True,
|
| 826 |
legend=dict(
|
| 827 |
yanchor="top",
|
| 828 |
-
y=0.
|
| 829 |
xanchor="left",
|
| 830 |
x=0.01,
|
| 831 |
bgcolor="rgba(255, 255, 255, 0.8)"
|
|
@@ -964,8 +972,8 @@ def create_intensity_map(pga_list, target_names, epicenter_lat=None, epicenter_l
|
|
| 964 |
intensity_labels = ["0", "1", "2", "3", "4", "5-", "5+", "6-", "6+", "7"]
|
| 965 |
for intensity_level in range(10):
|
| 966 |
group = intensity_groups[intensity_level]
|
| 967 |
-
if group['lat']: #
|
| 968 |
-
fig.add_trace(go.
|
| 969 |
lat=group['lat'],
|
| 970 |
lon=group['lon'],
|
| 971 |
mode='markers',
|
|
@@ -979,23 +987,46 @@ def create_intensity_map(pga_list, target_names, epicenter_lat=None, epicenter_l
|
|
| 979 |
name=f'震度 {intensity_labels[intensity_level]}',
|
| 980 |
showlegend=True
|
| 981 |
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 982 |
|
| 983 |
-
# 如果有震央位置,標記震央
|
| 984 |
if epicenter_lat and epicenter_lon:
|
| 985 |
-
fig.add_trace(go.
|
| 986 |
lat=[epicenter_lat],
|
| 987 |
lon=[epicenter_lon],
|
| 988 |
mode='markers',
|
| 989 |
-
marker=dict(size=
|
| 990 |
text=[f'震央<br>({epicenter_lat:.3f}, {epicenter_lon:.3f})'],
|
| 991 |
hovertemplate='%{text}<extra></extra>',
|
| 992 |
name='震央',
|
| 993 |
showlegend=True
|
| 994 |
))
|
| 995 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 996 |
# 設置地圖佈局
|
| 997 |
fig.update_layout(
|
| 998 |
-
|
| 999 |
style="open-street-map",
|
| 1000 |
center=dict(lat=23.5,
|
| 1001 |
lon=121),
|
|
@@ -1006,7 +1037,7 @@ def create_intensity_map(pga_list, target_names, epicenter_lat=None, epicenter_l
|
|
| 1006 |
showlegend=True,
|
| 1007 |
legend=dict(
|
| 1008 |
yanchor="top",
|
| 1009 |
-
y=0.
|
| 1010 |
xanchor="left",
|
| 1011 |
x=0.01,
|
| 1012 |
bgcolor="rgba(255, 255, 255, 0.8)"
|
|
|
|
| 751 |
fig = go.Figure()
|
| 752 |
|
| 753 |
# 添加所有測站(灰色小點)
|
| 754 |
+
fig.add_trace(go.Scattermap(
|
| 755 |
lat=all_stations_lat,
|
| 756 |
lon=all_stations_lon,
|
| 757 |
mode='markers',
|
| 758 |
+
marker=dict(size=6, color='gray', opacity=0.6),
|
| 759 |
text=all_stations_text,
|
| 760 |
hovertemplate='%{text}<extra></extra>',
|
| 761 |
name=f'所有測站 ({len(all_stations_lat)} 個)',
|
|
|
|
| 764 |
|
| 765 |
# 添加選中測站 - 前 5 近(綠色)
|
| 766 |
if selected_group1_lat:
|
| 767 |
+
fig.add_trace(go.Scattermap(
|
| 768 |
lat=selected_group1_lat,
|
| 769 |
lon=selected_group1_lon,
|
| 770 |
mode='markers',
|
|
|
|
| 777 |
|
| 778 |
# 添加選中測站 - 6-15 近(藍色)
|
| 779 |
if selected_group2_lat:
|
| 780 |
+
fig.add_trace(go.Scattermap(
|
| 781 |
lat=selected_group2_lat,
|
| 782 |
lon=selected_group2_lon,
|
| 783 |
mode='markers',
|
|
|
|
| 790 |
|
| 791 |
# 添加選中測站 - 16-25 近(橘色)
|
| 792 |
if selected_group3_lat:
|
| 793 |
+
fig.add_trace(go.Scattermap(
|
| 794 |
lat=selected_group3_lat,
|
| 795 |
lon=selected_group3_lon,
|
| 796 |
mode='markers',
|
|
|
|
| 801 |
showlegend=True
|
| 802 |
))
|
| 803 |
|
| 804 |
+
# 添加震央(紅色大點)
|
| 805 |
+
fig.add_trace(go.Scattermap(
|
| 806 |
lat=[epicenter_lat],
|
| 807 |
lon=[epicenter_lon],
|
| 808 |
mode='markers',
|
| 809 |
+
marker=dict(size=25, color='red'),
|
| 810 |
text=[f'震央<br>({epicenter_lat:.3f}, {epicenter_lon:.3f})'],
|
| 811 |
hovertemplate='%{text}<extra></extra>',
|
| 812 |
name='震央',
|
| 813 |
showlegend=True
|
| 814 |
))
|
| 815 |
|
| 816 |
+
fig.add_trace(go.Scattermap(
|
| 817 |
+
lat=[epicenter_lat],
|
| 818 |
+
lon=[epicenter_lon],
|
| 819 |
+
mode='markers',
|
| 820 |
+
marker=dict(size=10, color='white'),
|
| 821 |
+
showlegend=False
|
| 822 |
+
))
|
| 823 |
+
|
| 824 |
# 設置地圖佈局
|
| 825 |
fig.update_layout(
|
| 826 |
+
map=dict(
|
| 827 |
style="open-street-map",
|
| 828 |
center=dict(lat=epicenter_lat, lon=epicenter_lon),
|
| 829 |
+
zoom=8
|
| 830 |
),
|
| 831 |
+
height=500, # 設置固定高度以適應 Gradio 容器
|
| 832 |
margin=dict(l=0, r=0, t=0, b=0),
|
| 833 |
showlegend=True,
|
| 834 |
legend=dict(
|
| 835 |
yanchor="top",
|
| 836 |
+
y=0.95,
|
| 837 |
xanchor="left",
|
| 838 |
x=0.01,
|
| 839 |
bgcolor="rgba(255, 255, 255, 0.8)"
|
|
|
|
| 972 |
intensity_labels = ["0", "1", "2", "3", "4", "5-", "5+", "6-", "6+", "7"]
|
| 973 |
for intensity_level in range(10):
|
| 974 |
group = intensity_groups[intensity_level]
|
| 975 |
+
if group['lat']: # 有資料的震度等級
|
| 976 |
+
fig.add_trace(go.Scattermap(
|
| 977 |
lat=group['lat'],
|
| 978 |
lon=group['lon'],
|
| 979 |
mode='markers',
|
|
|
|
| 987 |
name=f'震度 {intensity_labels[intensity_level]}',
|
| 988 |
showlegend=True
|
| 989 |
))
|
| 990 |
+
else:
|
| 991 |
+
# 沒有資料的震度等級:添加隱形標記只為了顯示圖例
|
| 992 |
+
fig.add_trace(go.Scattermap(
|
| 993 |
+
lat=[None],
|
| 994 |
+
lon=[None],
|
| 995 |
+
mode='markers',
|
| 996 |
+
marker=dict(
|
| 997 |
+
size=14,
|
| 998 |
+
color=group['color'],
|
| 999 |
+
opacity=0.8
|
| 1000 |
+
),
|
| 1001 |
+
name=f'震度 {intensity_labels[intensity_level]}',
|
| 1002 |
+
showlegend=True,
|
| 1003 |
+
hoverinfo='skip'
|
| 1004 |
+
))
|
| 1005 |
|
| 1006 |
+
# 如果有震央位置,標記震央(紅色大點)
|
| 1007 |
if epicenter_lat and epicenter_lon:
|
| 1008 |
+
fig.add_trace(go.Scattermap(
|
| 1009 |
lat=[epicenter_lat],
|
| 1010 |
lon=[epicenter_lon],
|
| 1011 |
mode='markers',
|
| 1012 |
+
marker=dict(size=25, color='red'),
|
| 1013 |
text=[f'震央<br>({epicenter_lat:.3f}, {epicenter_lon:.3f})'],
|
| 1014 |
hovertemplate='%{text}<extra></extra>',
|
| 1015 |
name='震央',
|
| 1016 |
showlegend=True
|
| 1017 |
))
|
| 1018 |
|
| 1019 |
+
fig.add_trace(go.Scattermap(
|
| 1020 |
+
lat=[epicenter_lat],
|
| 1021 |
+
lon=[epicenter_lon],
|
| 1022 |
+
mode='markers',
|
| 1023 |
+
marker=dict(size=10, color='white'),
|
| 1024 |
+
showlegend=False
|
| 1025 |
+
))
|
| 1026 |
+
|
| 1027 |
# 設置地圖佈局
|
| 1028 |
fig.update_layout(
|
| 1029 |
+
map=dict(
|
| 1030 |
style="open-street-map",
|
| 1031 |
center=dict(lat=23.5,
|
| 1032 |
lon=121),
|
|
|
|
| 1037 |
showlegend=True,
|
| 1038 |
legend=dict(
|
| 1039 |
yanchor="top",
|
| 1040 |
+
y=0.95,
|
| 1041 |
xanchor="left",
|
| 1042 |
x=0.01,
|
| 1043 |
bgcolor="rgba(255, 255, 255, 0.8)"
|