-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaps.py
95 lines (75 loc) · 3.21 KB
/
maps.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
import pandas as pd # library for data analsysis
import json # library to handle JSON files
from geopy.geocoders import Nominatim # convert an address into latitude and longitude values
import requests # library to handle requests
import numpy as np
import folium # map rendering library
import streamlit as st
from streamlit_folium import folium_static
from get_data import get_data
#------------------------------------------------
load = get_data()
data_all = load[0]
data_geo = json.load(open('ncdc-covid19-states.geojson'))
dicts = {"Confirmed":'CONFIRMED',
"Active": 'ACTIVE',
"Discharged": 'DISCHARGED',
"Deaths": 'DEATHS'}
def center():
address = 'Nigeria'
geolocator = Nominatim(user_agent="id_explorer")
location = geolocator.geocode(address)
latitude = location.latitude
longitude = location.longitude
return latitude, longitude
def threshold(data):
threshold_scale = np.linspace(data_all[dicts[data]].min(),
data_all[dicts[data]].max(),
10, dtype=float)
threshold_scale = threshold_scale.tolist() # change the numpy array to a list
threshold_scale[-1] = threshold_scale[-1]
return threshold_scale
def show_maps(data, threshold_scale, color, arg):
maps= folium.Choropleth(
geo_data = data_geo,
data = data_all,
columns=['STATE',dicts[data]],
key_on='feature.properties.STATE',
threshold_scale=threshold_scale,
fill_color=color,
fill_opacity=1,
width='60%', height='60%',
line_opacity=0.9,
legend_name=dicts[data],
highlight=True,
reset=True).add_to(arg)
folium.LayerControl().add_to(arg)
maps.geojson.add_child(folium.features.GeoJsonTooltip(fields=['STATE',data],
aliases=['STATE: ', dicts[data]],
labels=True))
return folium_static(arg)
def show_maps_general(threshold_scale, color, arg):
maps= folium.Choropleth(
geo_data = data_geo,
data = data_all,
columns=['STATE',dicts["Confirmed"]],
key_on='feature.properties.STATE',
threshold_scale=threshold_scale,
fill_color=color,
fill_opacity=1,
width='30%', height='30%',
line_opacity=0.9,
legend_name=dicts["Confirmed"],
highlight=True,
reset=True).add_to(arg)
folium.LayerControl().add_to(arg)
maps.geojson.add_child(folium.features.GeoJsonTooltip(fields=['STATE',"Confirmed", 'Deaths', 'Active'],
aliases=['STATE: ', dicts["Confirmed"],dicts['Deaths'],dicts['Active']],
labels=True))
folium_static(arg)
def json_features():
for idx in range(37):
data_geo['features'][idx]['properties']['Confirmed'] = int(data_all['CONFIRMED'][idx])
data_geo['features'][idx]['properties']['Active'] = int(data_all['ACTIVE'][idx])
data_geo['features'][idx]['properties']['Discharged'] = int(data_all['DISCHARGED'][idx])
data_geo['features'][idx]['properties']['Deaths'] = float(data_all['DEATHS'][idx])