Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,87 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
|
4 |
-
from folium.plugins import MarkerCluster
|
5 |
-
# from folium import folium_static
|
6 |
import pandas as pd
|
|
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
{"name": "Reykjavik", "lat": 64.1265, "lon": -21.8174},
|
11 |
-
{"name": "Akureyri", "lat": 65.6885, "lon": -18.1262},
|
12 |
-
{"name": "Vik", "lat": 63.4194, "lon": -19.0096},
|
13 |
-
{"name": "Hofn", "lat": 64.2539, "lon": -15.2082},
|
14 |
-
{"name": "Husavik", "lat": 66.0449, "lon": -17.3382},
|
15 |
-
{"name": "Grundarfjordur", "lat": 64.9226, "lon": -23.2543},
|
16 |
-
{"name": "Egilsstadir", "lat": 65.2669, "lon": -14.3948},
|
17 |
-
{"name": "Seydisfjordur", "lat": 65.2592, "lon": -14.0101},
|
18 |
-
{"name": "Isafjordur", "lat": 66.0750, "lon": -23.1266},
|
19 |
-
{"name": "Kirkjufell", "lat": 64.9426, "lon": -23.3061},
|
20 |
-
]
|
21 |
-
|
22 |
-
# Function to display the map
|
23 |
-
def display_map(locations, lat, lon):
|
24 |
-
# Create a folium map centered in Iceland
|
25 |
-
iceland_map = folium.Map(location=[lat, lon], zoom_start=6)
|
26 |
-
|
27 |
-
# Create a marker cluster group
|
28 |
-
marker_cluster = MarkerCluster().add_to(iceland_map)
|
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 |
-
st.
|
58 |
-
|
59 |
-
References:
|
60 |
-
- [Folium documentation](https://python-visualization.github.io/folium/)
|
61 |
-
- [Streamlit documentation](https://docs.streamlit.io/)
|
62 |
-
- [Dask documentation](https://dask.org/)
|
63 |
-
- [Top 10 locations](https://www.guidetoiceland.is/best-of-iceland/top-10-places-to-see-the-northern-lights)
|
64 |
-
"""
|
65 |
-
)
|
|
|
1 |
import streamlit as st
|
2 |
+
import altair as alt
|
3 |
+
from vega_datasets import data
|
|
|
|
|
4 |
import pandas as pd
|
5 |
+
import pydeck as pdk
|
6 |
|
7 |
+
# Define the data source for the map
|
8 |
+
iceland_geojson = "https://raw.githubusercontent.com/deldersveld/topojson/master/countries/iceland/iceland-counties.json"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
# Define the mythological cities with their respective latitude and longitude
|
11 |
+
cities = {
|
12 |
+
"Asgard": [64.7938, -17.3413],
|
13 |
+
"Helheim": [63.8278, -21.1865],
|
14 |
+
"Jotunheim": [64.8441, -19.1669],
|
15 |
+
"Midgard": [63.9863, -22.6210],
|
16 |
+
"Muspellheim": [65.3201, -16.4235],
|
17 |
+
"Nidavellir": [64.9011, -18.0580],
|
18 |
+
"Svartalfheim": [64.0114, -21.4504],
|
19 |
+
"Valhalla": [63.7267, -19.6133],
|
20 |
+
"Vanaheim": [64.7381, -17.4497],
|
21 |
+
"Yggdrasil": [64.8999, -19.0044]
|
22 |
+
}
|
23 |
|
24 |
+
# Define the colors to use for each city marker
|
25 |
+
colors = {
|
26 |
+
"Asgard": [255, 0, 0],
|
27 |
+
"Helheim": [255, 255, 0],
|
28 |
+
"Jotunheim": [0, 0, 255],
|
29 |
+
"Midgard": [0, 255, 0],
|
30 |
+
"Muspellheim": [255, 153, 0],
|
31 |
+
"Nidavellir": [153, 0, 255],
|
32 |
+
"Svartalfheim": [0, 255, 255],
|
33 |
+
"Valhalla": [255, 0, 255],
|
34 |
+
"Vanaheim": [153, 255, 0],
|
35 |
+
"Yggdrasil": [255, 255, 255]
|
36 |
+
}
|
37 |
|
38 |
+
# Define the Streamlit app layout
|
39 |
+
st.set_page_config(layout="wide")
|
40 |
+
st.title("Mythological Cities in Iceland")
|
41 |
+
st.sidebar.title("Select a City to View the Northern Lights From")
|
42 |
+
selected_city = st.sidebar.selectbox("", sorted(cities.keys()))
|
43 |
|
44 |
+
# Load the Icelandic county boundaries and prepare the data for the 3D map
|
45 |
+
iceland_data = alt.topo_feature(iceland_geojson, "iceland-counties")
|
46 |
+
iceland_df = pd.DataFrame(iceland_data["features"])
|
47 |
|
48 |
+
# Create the 3D map with Deck.gl and Altair
|
49 |
+
view_state = pdk.ViewState(latitude=64.9, longitude=-18.5, zoom=5, pitch=40)
|
50 |
+
layers = [
|
51 |
+
pdk.Layer(
|
52 |
+
"PolygonLayer",
|
53 |
+
data=iceland_data,
|
54 |
+
get_polygon="coordinates",
|
55 |
+
filled=True,
|
56 |
+
extruded=True,
|
57 |
+
get_elevation="properties.avg_elevation",
|
58 |
+
elevation_scale=1000,
|
59 |
+
get_fill_color=[200, 200, 200, 200]
|
60 |
+
),
|
61 |
+
pdk.Layer(
|
62 |
+
"ScatterplotLayer",
|
63 |
+
data=pd.DataFrame({"latitude": [cities[selected_city][0]], "longitude": [cities[selected_city][1]]}),
|
64 |
+
get_position="[longitude, latitude]",
|
65 |
+
get_color=colors[selected_city],
|
66 |
+
get_radius=20000
|
67 |
+
)
|
68 |
+
]
|
69 |
|
70 |
+
r = pdk.Deck(layers=layers, initial_view_state=view_state)
|
71 |
+
altair_chart = alt.Chart(iceland_df).mark_geoshape(
|
72 |
+
stroke="black",
|
73 |
+
strokeWidth=0.5
|
74 |
+
).encode(
|
75 |
+
color=alt.Color("properties.avg_elevation:Q", scale=alt.Scale(scheme="viridis")),
|
76 |
+
tooltip=[alt.Tooltip("properties.name", title="County"), alt.Tooltip("properties.avg_elevation:Q", title="Elevation (m)")]
|
77 |
+
).transform_lookup(
|
78 |
+
lookup="id",
|
79 |
+
from_=alt.LookupData(iceland_data, "id", ["properties.avg_elevation", "properties.name"])
|
80 |
+
).properties(
|
81 |
+
width=900,
|
82 |
+
height=600
|
83 |
+
).interactive()
|
84 |
|
85 |
+
Display the 3D map and the Altair chart
|
86 |
+
st.pydeck_chart(r)
|
87 |
+
st.altair_chart(altair_chart)
|
|
|
|
|
|
|
|
|
|
|
|
|
|