-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.py
172 lines (148 loc) · 6.29 KB
/
map.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
"""
Part 2: Visual Representation of the Forest Fires in US (Map) (2010 - 2015)
Objective: In this part the forest fires data of 10 years
has been shrink down to just 5 years which from 2010 to 2015 of the US.
The map opens up in the browser with some features:
- Ability to Zoom in and out
- Ability to move around the map.
- Each marker on the US map provides basic insights of the forest fires.
- Ability to change the map's layout
- Ability to change heat map layers
This file is Copyright (c) 2020 Ansh Malhotra, Armaan Mann, Leya Abubaker, Gabriel Pais
"""
# Importing Packages
import os
import webbrowser
import folium
import pandas as pd
from folium import plugins
from main import read_file_map
############################################################################################
# make_map below generates the map of the whole world.
# Only the US within the map has borders.
# Markers are placed depending on the corresponding latitude and longitudes.
# Each marker contains some information of the forest fire.
############################################################################################
def make_map() -> None:
"""
Generate a map of US with forest fires from years 2010 to 2015.
"""
# Extracting the data using the function above
fire_data = read_file_map('FireData5yrs.csv')
# Creating a data frame
container = pd.DataFrame({
'lon': fire_data['Longitude'],
'lat': fire_data['Latitude'],
'Size': fire_data['Fire Size'],
'Veg': fire_data["Vegetation"],
'FMag': fire_data["Fire Magnitude"],
'Wind': fire_data['Wind Contained'],
'Humid': fire_data['Humid Contained'],
'remote': fire_data['Remoteness'],
'link': fire_data['Links'],
'time': fire_data['Time']
})
# Creates the Map
m = folium.Map(location=[39.525501, -102.163384], zoom_start=3, prefer_canvas=True, tiles='Stamen Terrain')
# Overlay of the US
outline_us = os.path.join('overlay.json')
# Creating a Marker Cluster
cluster = folium.plugins.MarkerCluster(name="Markers").add_to(m)
heatmap = pd.read_csv('FireData5yrs.csv')
# Adding a heat map:
folium.Choropleth(
geo_data=outline_us,
data=heatmap,
columns=['state', 'Vegetation'],
name='Fire Magnitude',
key_on='feature.id',
fill_color='YlGn',
fill_opacity=0.5,
line_opacity=0.5,
legend_name='Fire Magnitude',
highlight=True).add_to(m)
folium.Choropleth(
geo_data=outline_us,
data=heatmap,
columns=['state', "fire_mag"],
name='Vegetation',
key_on='feature.id',
fill_color='RdPu',
fill_opacity=0.5,
line_opacity=0.5,
legend_name='Vegetation',
highlight=True).add_to(m)
folium.Choropleth(
geo_data=outline_us,
data=heatmap,
columns=['state', "Hum_cont"],
name='Humidity',
key_on='feature.id',
fill_color='YlOrRd',
fill_opacity=0.5,
line_opacity=0.5,
legend_name='Humidity',
highlight=True).add_to(m)
folium.Choropleth(
geo_data=outline_us,
data=heatmap,
columns=['state', "Wind_cont"],
name='Wind',
key_on='feature.id',
fill_color='PuBuGn',
fill_opacity=0.5,
line_opacity=0.5,
legend_name='Wind',
highlight=True).add_to(m)
# Iterating through the data and at each iteration adding its value.
# It creates the marker and the popup with these information inside the popup.
for i in range(0, len(container)):
info_size = '<strong> Fire Size </strong>:' + container.iloc[i]['Size'] + 'g/mi'
info_veg = '<strong> Vegetation </strong>:' + container.iloc[i]['Veg']
info_mag = '<strong> Fire Magnitude </strong>:' + container.iloc[i]['FMag']
info_wind = '<strong> Wind Contained </strong>:' + container.iloc[i]['Wind']
info_humid = '<strong> Humidity Contained </strong>:' + container.iloc[i]['Humid']
info_remote = '<strong> Remoteness </strong>:' + container.iloc[i]['remote']
info_link = container.iloc[i]['link']
info_time = '<strong> Year </strong>:' + container.iloc[i]['time']
info_all = info_mag + '<br>' + info_time + '<br>' + info_veg + '<br>' + info_wind + '<br>' + \
info_humid + '<br>' + info_remote + '<br>' + info_size + '<br>' + \
'<a href=' + info_link + ' > [More Details] </ a >'
(folium.Marker([container.iloc[i]['lat'], container.iloc[i]['lon']],
popup=folium.Popup(info_all, max_width=280, min_width=280),
icon=folium.Icon(color='red', icon='fa-fire', prefix='fa'),
tooltip='Click For More Information').add_to(cluster))
# Add the outline to map
folium.GeoJson(outline_us, name='America').add_to(m)
# Adding a Mini Map
mini = plugins.MiniMap(toggle_display=True)
m.add_child(mini)
# plugins.ScrollZoomToggler().add_to(m)
plugins.Fullscreen(position='topright').add_to(m)
# Adding More types of maps
folium.TileLayer('OpenStreetMap').add_to(m)
folium.TileLayer('Stamen Watercolor').add_to(m)
folium.TileLayer('Stamen Terrain').add_to(m)
folium.TileLayer('CartoDB positron').add_to(m)
folium.TileLayer('CartoDB dark_matter').add_to(m)
folium.LayerControl().add_to(m)
# Saves the Map
m.save('m.html')
# Opens the Webpage
webbrowser.open('m.html')
if __name__ == '__main__':
import python_ta
python_ta.check_all(config={
'allowed-io': ['graph_data', 'main', 'read_file_2'],
'extra-imports': ['python_ta.contracts', 'csv', 'datetime',
'plotly.graph_objects', 'plotly.subplots', 'numpy',
'matplotlib.pyplot', 'folium', 'pandas', 'os', 'webbrowser', 'main',
'read_file_2'],
'max-line-length': 150,
'max-args': 6,
'max-locals': 25,
'disable': ['R1705', 'E9989'],
})
import python_ta.contracts
python_ta.contracts.DEBUG_CONTRACTS = True
python_ta.contracts.check_all_contracts()