-
Notifications
You must be signed in to change notification settings - Fork 0
/
eonat_dashboard.py
188 lines (171 loc) Β· 7.46 KB
/
eonat_dashboard.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
import folium
import requests
import streamlit as st
from streamlit_lottie import st_lottie
from streamlit_folium import folium_static
hide_streamlit_style = """
<style>
div[data-testid="stToolbar"] {
visibility: hidden;
height: 0%;
position: fixed;
}
div[data-testid="stDecoration"] {
visibility: hidden;
height: 0%;
position: fixed;
}
div[data-testid="stStatusWidget"] {
visibility: hidden;
height: 0%;
position: fixed;
}
#MainMenu {
visibility: hidden;
height: 0%;
}
header {
visibility: hidden;
height: 0%;
}
footer {
visibility: hidden;
height: 0%;
}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
# Bootstrap import
st.markdown('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">', unsafe_allow_html=True)
# Navbar
st.markdown("""
<nav class="navbar fixed-top navbar-expand-lg navbar-dark" style="padding-left:400px;">
<a class="navbar-brand" href="https://share.streamlit.io/morgan-techy/nasaapi/init/eonat_dashboard.py" target="_blank">EONAT VISUAL</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link disabled" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/RayanGAtech/Earth-Observatory-Natural-Event-Visualization" target="_blank">Github</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://twitter.com/RayanG_A" target="_blank">Twitter</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.linkedin.com/in/rayan-g-abukelab-18ab2914a/" target="_blank">Linkedin</a>
</li>
</ul>
</div>
</nav>
""", unsafe_allow_html=True)
def lottie(url):
r = requests.get(url)
if r.status_code != 200:
return None
return r.json()
# Header text
st.markdown("<h1 style='text-align: center; color: white;'>Earth Observatory Natural Event Visualization</h1>", unsafe_allow_html=True)
# Earth animation
l = lottie('https://assets9.lottiefiles.com/packages/lf20_blfn1jwy.json')
st_lottie(l, height=300, key='earth_map')
# Sidebar to hold the side page features and text
with st.sidebar:
# Slider to allow display an event on a particular day on the map
slider = st.slider('Day Range:', 0, 365)
st.write('You are searching in the last:', slider, 'days')
# API url to get the data from NASA API
url1 = f'https://eonet.gsfc.nasa.gov/api/v3/events?days={slider}'
# Request the data
r = requests.get(url1)
# Convert the data to JSON format and call the events categories
p_r = r.json()
events = p_r['events']
# Create a map object
m = folium.Map(location=[15, 16], tiles="Cartodbdark_matter", zoom_start=2, min_zoom=2, max_bounds=True)
# Volcano events function
def volcano():
for count in range(len(events)):
for i in p_r['events'][count]['geometry']:
cord_A = i['coordinates'][1]
cord_B = i['coordinates'][0]
date = i['date']
for j in p_r['events'][count]['categories']:
event_type = j['title']
if event_type == 'Volcanoes':
# Global tooltip
tooltip = 'click for more info'
type = p_r['events'][count]['title']
# Create markers
folium.Marker([cord_A, cord_B], popup=folium.Popup(f'<strong>{type}<br>{date}<\strong>', max_width=150, min_width=150), tooltip=tooltip, icon=folium.features.CustomIcon(icon_image='icon/volcano.png', icon_size=(20, 20))).add_to(m)
# Wildfire events function
def wildfire():
for count in range(len(events)):
for i in p_r['events'][count]['geometry']:
cord_A = i['coordinates'][1]
cord_B = i['coordinates'][0]
date = i['date']
for j in p_r['events'][count]['categories']:
event_type = j['title']
if event_type == 'Wildfires':
# Global tooltip
tooltip = 'click for more info'
type = p_r['events'][count]['title']
# Create markers
folium.Marker([cord_A, cord_B], popup=folium.Popup(f'<strong>{type}<br>{date}<\strong>', max_width=150, min_width=150), tooltip=tooltip, icon=folium.features.CustomIcon(icon_image='icon/fire-solid.png', icon_size=(20, 20))).add_to(m)
# Iceberg events function
def iceberg():
for count in range(len(events)):
for i in p_r['events'][count]['geometry']:
cord_A = i['coordinates'][1]
cord_B = i['coordinates'][0]
date = i['date']
for j in p_r['events'][count]['categories']:
event_type = j['title']
if event_type == 'Sea and Lake Ice':
# Global tooltip
tooltip = 'click for more info'
type = p_r['events'][count]['title']
# Create markers
folium.Marker([cord_A, cord_B], popup=folium.Popup(f'<strong>{type}<br>{date}<\strong>', max_width=150, min_width=150), tooltip=tooltip, icon=folium.features.CustomIcon(icon_image='icon/iceberg.png', icon_size=(20, 20))).add_to(m)
# Sidebar to hold the side page features and text
with st.sidebar:
genre = st.radio(
"Please select an event:",
('All', 'volcano', 'wildfire', 'iceberg'))
if genre == 'volcano':
# Call the function
volcano()
elif genre == 'wildfire':
# Call the function
wildfire()
elif genre == 'iceberg':
# Call the function
iceberg()
else:
volcano()
wildfire()
iceberg()
# Display map
folium_static(m)
# Text
st.info('Credit: Created by @Morgan_techy ([Rayan G. A.](https://www.linkedin.com/in/rayan-g-abukelab-18ab2914a/))')
st.info('Used API: https://eonet.gsfc.nasa.gov/api/v3/events')
# Hide Streamlit style
hide_st_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
</style>
"""
st.markdown(hide_st_style, unsafe_allow_html=True)
# JS import
st.markdown("""
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
""", unsafe_allow_html=True)