Spaces:
Runtime error
Runtime error
Create failapp.py
Browse files- failapp.py +53 -0
failapp.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import leafmap.foliumap as leafmap
|
3 |
+
|
4 |
+
def create_marker(bird):
|
5 |
+
species = bird['species']
|
6 |
+
lat = bird['lat']
|
7 |
+
lon = bird['lon']
|
8 |
+
start_month = bird['start_month']
|
9 |
+
end_month = bird['end_month']
|
10 |
+
popup_msg = f"{species}: {start_month} - {end_month}"
|
11 |
+
icon_text = f"{species} ({start_month} - {end_month})"
|
12 |
+
marker = leafmap.Marker(location=[lat, lon], popup=popup_msg)
|
13 |
+
marker.add_child(leafmap.Popup(icon_text))
|
14 |
+
return marker
|
15 |
+
|
16 |
+
def create_map(center, zoom, markers):
|
17 |
+
m = leafmap.Map(center=center, zoom=zoom)
|
18 |
+
for marker in markers:
|
19 |
+
marker.add_to(m)
|
20 |
+
return m
|
21 |
+
|
22 |
+
birds = [
|
23 |
+
{'species': 'Canada Goose', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'April'},
|
24 |
+
{'species': 'Mallard Duck', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'August', 'end_month': 'May'},
|
25 |
+
{'species': 'Wood Duck', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'March', 'end_month': 'November'},
|
26 |
+
{'species': 'Trumpeter Swan', 'lat': 45.0941, 'lon': -94.2392, 'start_month': 'October', 'end_month': 'April'},
|
27 |
+
{'species': 'Tundra Swan', 'lat': 44.9358, 'lon': -93.1553, 'start_month': 'November', 'end_month': 'April'},
|
28 |
+
{'species': 'Canvasback', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'September', 'end_month': 'May'},
|
29 |
+
{'species': 'Redhead', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'May'},
|
30 |
+
{'species': 'Greater Scaup', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'September', 'end_month': 'May'},
|
31 |
+
{'species': 'Lesser Scaup', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'May'},
|
32 |
+
{'species': 'Hooded Merganser', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'October', 'end_month': 'April'}
|
33 |
+
]
|
34 |
+
|
35 |
+
# Create list of markers for each bird species
|
36 |
+
markers = [create_marker(bird) for bird in birds]
|
37 |
+
|
38 |
+
# Define the center and zoom of the map
|
39 |
+
center = [44.9778, -93.2650]
|
40 |
+
zoom = 8
|
41 |
+
|
42 |
+
# Create the Streamlit app
|
43 |
+
st.title("Bird Migration Map")
|
44 |
+
month = st.slider("Select a month", 1, 12, 1)
|
45 |
+
|
46 |
+
# Filter the markers by the selected month
|
47 |
+
selected_markers = [marker for marker in markers if month >= list(calendar.month_abbr).index(marker['start_month'][:3]) and month <= list(calendar.month_abbr).index(marker['end_month'][:3])]
|
48 |
+
|
49 |
+
# Create the map with the filtered markers
|
50 |
+
m = create_map(center, zoom, selected_markers)
|
51 |
+
|
52 |
+
# Display the map on the Streamlit app
|
53 |
+
st.write(m)
|