-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
364 lines (285 loc) · 15.4 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
import altair as alt
import datetime
import folium
import geopandas as gpd
import geopy
import json
import base64
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
import osmnx as ox
import pandas as pd
import plotly_express as px
import plotly.io as pio
import plotly.offline as pyo
import requests
import seaborn as sns
import streamlit as st
import psycopg2
from folium.features import DivIcon
from googletrans import Translator
from PIL import Image
from shapely.geometry import Point, LineString
from spacy import displacy
from spacy_streamlit import visualize_ner
from streamlit_folium import folium_static
from folium.plugins import MarkerCluster
from branca.element import Figure
from streamlit_folium import folium_static
from geopy.geocoders import Nominatim
ox.config(use_cache=True, log_console=True)
pyo.init_notebook_mode(connected=True)
st.set_page_config(
page_title="Nakagawa - Safest Path during Natural Disasters",
layout="wide",
initial_sidebar_state="expanded",
)
st.set_option('deprecation.showPyplotGlobalUse', False)
st.markdown(
"""
<style>
.css-hby737, .css-17eq0hr, .css-qbe2hs {
background-color: #154360 !important;
color: black !important;
}
div[role="radiogroup"] {
color:black !important;
margin-left:8%;
}
div[data-baseweb="select"] > div {
color: black;
}
div[data-baseweb="base-input"] > div {
background-color: #aab7b8 !important;
color: black;
}
.st-cb, .st-bq, .st-aj, .st-c0{
color: black !important;
}
.st-bs, .st-ez, .st-eq, .st-ep, .st-bd, .st-e2, .st-ea, .st-g9, .st-g8, .st-dh, .st-c0 {
color: black !important;
}
.st-fg, .st-fi {
background-color: #c6703b !important;
color: black !important;
}
.st-g0 {
border-bottom-color: #c6703b !important;
}
.st-fz {
border-top-color: #c6703b !important;
}
.st-fy {
border-right-color: #c6703b !important;
}
.st-fx {
border-left-color: #c6703b !important;
}
</style>
""",
unsafe_allow_html=True
)
st.sidebar.markdown('<h1 style="margin-left:8%; color:#FA8072">Nakagawa - Safest Path during Natural Disasters </h1>', unsafe_allow_html=True)
add_selectbox = st.sidebar.radio(
"",
("Home", "About", "Features", "Safest Path", "Visualizations", "Conclusion", "Team")
)
if add_selectbox == 'Home':
LOGO_IMAGE = "omdena_japan_logo.jpg"
st.markdown(
"""
<style>
.container {
display: flex;
}
.logo-text {
font-weight:700 !important;
font-size:50px !important;
color: #f9a01b !important;
padding-top: 75px !important;
}
.logo-img {
float:right;
}
</style>
""",
unsafe_allow_html=True
)
st.markdown(
f"""
<div class="container">
<img class="logo-img" src="data:image/jpg;base64,{base64.b64encode(open(LOGO_IMAGE, "rb").read()).decode()}">
</div>
""",
unsafe_allow_html=True
)
st.subheader('PROBLEM STATEMENT')
st.markdown('Natural Disasters are problems in Japan, with risk of earthquakes, floods and tsunamis. Japan has well-developed \
disaster response systems, but densely populated cities and narrow roads make managing the response difficult. By giving \
individuals information about the safest ways from their homes and places of work, it will increase their awareness of \
the surrounding area and improve their preparedness.', unsafe_allow_html=True)
elif add_selectbox == 'About':
st.subheader('ABOUT THE PROJECT')
st.markdown('<h4>Project Goals</h4>', unsafe_allow_html=True)
st.markdown('• collect satellite images and identify road characteristics', unsafe_allow_html=True)
st.markdown('• build a model for scoring the roads in terms of their suitability for use in emergency', unsafe_allow_html=True)
st.markdown('• build a pathfinding model from A to B, combining it with road characteristics', unsafe_allow_html=True)
st.markdown('• suggest safest path from A to B', unsafe_allow_html=True)
st.markdown('• publish interactive dashboards to display road characteristics and safest paths', unsafe_allow_html=True)
st.markdown('• arrange demonstration and publicise to local audiences', unsafe_allow_html=True)
st.markdown('<h4>Location Choosen</h4>', unsafe_allow_html=True)
st.markdown('We had choosen "Nakagawa-Ku as our region of interest, which comes under Aichi prefecture of Nagoya City. It comes under Chubu region and \
is the 4th densely populated city in Japan with high risk prone to disasters.',
unsafe_allow_html=True)
st.markdown('<h4>Developments Made</h4>', unsafe_allow_html=True)
st.markdown('• We had designed a model collecting data about the local roads from satellite images, classify them and indicate the safest \
route to be taken from point A to point B and an interactive dashboard to display the safest route in a map.',
unsafe_allow_html=True)
st.markdown('• By making individuals aware, it will improve their preparedness and it can be used within families to prepare disaster \
response plans, depending on their circumstances. To be used by individuals, families and groups, and foreign residents who may \
not understand local information. Further development will be covering more geographical areas and publicising on a local level.'
, unsafe_allow_html=True)
elif add_selectbox == 'Features':
st.subheader('PROJECT ENDORSEMENTS')
st.markdown('• Safest route path to take at occurences of japan disasters', unsafe_allow_html=True)
st.markdown('• Locates shelters in Nakagawa Ward - Earthquakes, Tsunamis and Floods', unsafe_allow_html=True)
st.markdown('• Visualizations to Check and Differentiate Parameters across the Nakagawa Ward', unsafe_allow_html=True)
elif add_selectbox == 'Safest Path':
st.subheader('FIND THE SAFEST PATH')
current_location = st.text_input('Designated Location:')
if st.button('Search'):
api_token = "pk.eyJ1IjoicHJhdGhpbWFrYWRhcmkiLCJhIjoiY2t6MmxlaDVvMXAxaDJ2cWtrM3BzMGZuMCJ9.m5BXW9QUs914PCaWkepfHA"
def create_graph(loc, dist, transport_mode, loc_type="address"):
"""Transport mode = ‘walk’, ‘bike’, ‘drive’, ‘drive_service’, ‘all’, ‘all_private’, ‘none’"""
if loc_type == "address":
G = ox.graph_from_address(loc, dist=dist, network_type=transport_mode)
elif loc_type == "points":
G = ox.graph_from_point(loc, dist=dist, network_type=transport_mode )
return G
G = create_graph("Nakagawa, Nagoya, Japan", 2500, "drive")
ox.plot_graph(G)
G = ox.add_edge_speeds(G) #Impute
G = ox.add_edge_travel_times(G) #Travel time
# start = (57.715495, 12.004210)
# end = (57.707166, 11.978388)
start = (35.1394307, 136.8565519)
end = (35.1301611, 136.8697751)
start_node = ox.get_nearest_node(G, start)
end_node = ox.get_nearest_node(G, end)# Calculate the shortest path
route = nx.shortest_path(G, start_node, end_node, weight='travel_time')
#Plot the route and street networks
ox.plot_graph_route(G, route, route_linewidth=6, node_size=0, bgcolor='k')
node_start = []
node_end = []
X_to = []
Y_to = []
X_from = []
Y_from = []
length = []
travel_time = []
for u, v in zip(route[:-1], route[1:]):
node_start.append(u)
node_end.append(v)
length.append(round(G.edges[(u, v, 0)]['length']))
travel_time.append(round(G.edges[(u, v, 0)]['travel_time']))
X_from.append(G.nodes[u]['x'])
Y_from.append(G.nodes[u]['y'])
X_to.append(G.nodes[v]['x'])
Y_to.append(G.nodes[v]['y'])
df = pd.DataFrame(list(zip(node_start, node_end, X_from, Y_from, X_to, Y_to, length, travel_time)),
columns =["node_start", "node_end", "X_from", "Y_from", "X_to", "Y_to", "length",
"travel_time"])
def create_line_gdf(df):
gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.X_from, df.Y_from))
gdf["geometry_to"] = [Point(xy) for xy in zip(gdf.X_to, gdf.Y_to)]
gdf['line'] = gdf.apply(lambda row: LineString([row['geometry_to'], row['geometry']]), axis=1)
line_gdf = gdf[["node_start","node_end","length","travel_time", "line"]].set_geometry('line')
return line_gdf
line_gdf = create_line_gdf(df)
start = df[df["node_start"] == start_node]
end = df[df["node_end"] == end_node]
fig = px.scatter_mapbox(df, lon= "X_from", lat="Y_from", zoom=12, width=1000, height=800)
fig.update_layout(font_size=16, title={'xanchor': 'center','yanchor': 'top', 'y':0.9, 'x':0.5,},
title_font_size = 24, mapbox_accesstoken=api_token,
mapbox_style = "mapbox://styles/strym/ckhd00st61aum19noz9h8y8kw")
fig.update_traces(marker=dict(size=6))
st.write(fig)
fig = px.scatter_mapbox(df, lon= "X_from", lat="Y_from",
zoom=13, width=1000, height=800, animation_frame=df.index, mapbox_style="dark")
fig.data[0].marker = dict(size = 12, color="black")
fig.add_trace(px.scatter_mapbox(start, lon= "X_from", lat="Y_from").data[0])
fig.data[1].marker = dict(size = 15, color="red")
fig.add_trace(px.scatter_mapbox(end, lon= "X_from", lat="Y_from").data[0])
fig.data[2].marker = dict(size = 15, color="green")
fig.add_trace(px.line_mapbox(df, lon= "X_from", lat="Y_from").data[0])
fig.update_layout(font_size=16, title={'xanchor': 'center','yanchor': 'top', 'y':0.9, 'x':0.5,},
title_font_size = 24, mapbox_accesstoken=api_token)
st.write(fig)
fig2=Figure(width=550,height=350)
m2=folium.Map(location=[35.139288, 136.8128218], zoom_start=3)
fig2.add_child(m2)
folium.TileLayer('Stamen Terrain').add_to(m2)
folium.TileLayer('Stamen Toner').add_to(m2)
folium.TileLayer('Stamen Water Color').add_to(m2)
folium.TileLayer('cartodbpositron').add_to(m2)
folium.TileLayer('cartodbdark_matter').add_to(m2)
folium.LayerControl().add_to(m2)
df = pd.read_csv('nakagawa_shelters.csv')
df['lon'] = pd.to_numeric(df.lon, errors='coerce')
df['lat'] = pd.to_numeric(df.lat, errors='coerce')# drop rows with missing lat and lon
df.dropna(subset=['lat', 'lon'], inplace=True)# convert from string to int
from streamlit_keplergl import keplergl_static
from keplergl import KeplerGl
map_1 = KeplerGl(height=800)
map_1.add_data(data=df, name="shelters")
keplergl_static(map_1)
elif add_selectbox == 'Visualizations':
st.subheader('PROJECT VISUALIZATIONS')
st.markdown('<h4>Japan Earthquake Zoning Areas</h4>', unsafe_allow_html=True)
st.image("Japan_Earthquakes_Zoning.png", width=650)
st.markdown('<h4>Nakagawa Shelter Maps</h4>', unsafe_allow_html=True)
st.image("Nakagawa_Shelter_Maps.png", width=650)
st.markdown('<h4>Nakagawa Building Density Score</h4>', unsafe_allow_html=True)
st.image("nakagawa_graph_building_density_risk.jpg", width=650)
st.markdown('<h4>Nakagawa Earthquake Risk Score</h4>', unsafe_allow_html=True)
st.image("nakagawa_graph_earthquake_risk.jpg", width=650)
elif add_selectbox == 'Conclusion':
st.subheader('TECH STACK')
st.markdown('• Data Gathering - Shelter Details, Latitude, Longitude, Ward Type.', unsafe_allow_html=True)
st.markdown('• Data Preparation - Merging all the Details, Configuring, Evaluating and Converting it into Readable Format.', unsafe_allow_html=True)
st.markdown('• Risk Classification - Japan Earthquake Zoning Areas, Nakagawa Evacuation Shelters, Risk Factors of Earthquake and Building Density', unsafe_allow_html=True)
st.markdown('• Path Finding Algorithms - Python, Jupyter Notebook (Earthquake Risk Score, Building Density Risk Score, Distance Risk Score and Combined Risk Score.', unsafe_allow_html=True)
st.markdown('• Dashboard - Streamlit.', unsafe_allow_html=True)
st.subheader('PROJECT SUMMARY')
st.markdown('• Gathering the data about the Shelters (Earthquake, Tsunami and Flood) on Nakagawa Ward with various parameters needed to calculate risk factor and safest path.', unsafe_allow_html=True)
st.markdown('• Preparing and pre-processing the data for it to read and determine the risk classification and path finding appropriately.', unsafe_allow_html=True)
st.markdown('• Check up, configure and evaluate with the risk factors based on distance, building density and earthquake considerations.', unsafe_allow_html=True)
st.markdown('• Devising the safest path using algorithms that gives out the best possible route to take up during emergencies.', unsafe_allow_html=True)
st.markdown('• Deploying Safest Path Integrated Web App on Streamlit.', unsafe_allow_html=True)
st.subheader('CONCLUSION')
st.markdown('An Interactive WebApp to devise safest path in Nakagawa-Ku region, Japan during natural disasters like Earthquakes, Tsunamis and Floods that helps in prioritizing the citizens safety in risk prone zones.', unsafe_allow_html=True)
elif add_selectbox == 'Team':
st.subheader('COLLABORATORS')
st.markdown('<a href="https://www.linkedin.com/in/avinash-mahech/">Avinash Mahech</a>',
unsafe_allow_html=True)
st.markdown('<a href="https://www.linkedin.com/in/prathima-kadari/">Prathima Kadari</a>',
unsafe_allow_html=True)
st.markdown('<a href="https://www.linkedin.com/in/armielyn-obinguar-9229561b0/">Armielyn Obinguar</a>',
unsafe_allow_html=True)
st.markdown('<a href="https://www.linkedin.com/in/deepali-bidwai/">Deepali Bidwai</a>',
unsafe_allow_html=True)
st.markdown('<a href="https://www.linkedin.com/in/shalini-gj-6a006712/">Shalini GJ</a>',
unsafe_allow_html=True)
st.markdown('<a href="https://www.linkedin.com/in/rhey-ann-magcalas-47541490/">Rhey Ann Magcalas</a>',
unsafe_allow_html=True)
st.markdown('<a href="https://www.linkedin.com/in/pawan-roy123">Pawan Roy Choudhury</a>',
unsafe_allow_html=True)
st.markdown('<a href="https://www.linkedin.com/in/ahmedgaal/">Ahmed Gaal</a>',
unsafe_allow_html=True)
st.markdown('<a href="https://www.linkedin.com/in/mkmanolova/">Monika Manolova</a>',
unsafe_allow_html=True)
st.markdown('<a href="https://www.linkedin.com/in/abdulbaaqi/">Abdul Baaqi</a>',
unsafe_allow_html=True)
st.subheader('PROJECT MANAGER')
st.markdown('<a href="https://www.linkedin.com/in/galina-naydenova-msc-fhea-b89856196/">Galina Naydenova</a>', unsafe_allow_html=True)