Spaces:
Running
Running
castledan
commited on
Commit
Β·
62b4495
1
Parent(s):
226f63d
adjust config and layout files
Browse files- app/Home.py +13 -14
- app/pages/1_π_Flood_extent_analysis.py +10 -38
- app/pages/2_π_Documentation.py +22 -23
- app/src/config_parameters.py +18 -17
- app/src/{utils_layout.py β utils.py} +75 -12
- app/src/utils_ee.py +1 -1
- setup.cfg +2 -1
app/Home.py
CHANGED
@@ -1,10 +1,15 @@
|
|
1 |
"""Home page for Streamlit app."""
|
2 |
import streamlit as st
|
3 |
-
from src.config_parameters import
|
4 |
-
from src.
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# Page configuration
|
7 |
-
st.set_page_config(layout="wide", page_title=
|
8 |
|
9 |
# If app is deployed hide menu button
|
10 |
toggle_menu_button()
|
@@ -13,14 +18,8 @@ toggle_menu_button()
|
|
13 |
add_logo("app/img/MA-logo.png")
|
14 |
add_about()
|
15 |
|
16 |
-
# Set
|
17 |
-
|
18 |
-
"""
|
19 |
-
<style> p { font-size: %s; } </style>
|
20 |
-
"""
|
21 |
-
% config["docs_fontsize"],
|
22 |
-
unsafe_allow_html=True,
|
23 |
-
)
|
24 |
|
25 |
# Page title
|
26 |
st.markdown("# Home")
|
@@ -49,9 +48,9 @@ st.markdown(
|
|
49 |
only source of information for rescue response planning.
|
50 |
"""
|
51 |
% (
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
),
|
56 |
unsafe_allow_html=True,
|
57 |
)
|
|
|
1 |
"""Home page for Streamlit app."""
|
2 |
import streamlit as st
|
3 |
+
from src.config_parameters import params
|
4 |
+
from src.utils import (
|
5 |
+
add_about,
|
6 |
+
add_logo,
|
7 |
+
set_home_page_style,
|
8 |
+
toggle_menu_button,
|
9 |
+
)
|
10 |
|
11 |
# Page configuration
|
12 |
+
st.set_page_config(layout="wide", page_title=params["browser_title"])
|
13 |
|
14 |
# If app is deployed hide menu button
|
15 |
toggle_menu_button()
|
|
|
18 |
add_logo("app/img/MA-logo.png")
|
19 |
add_about()
|
20 |
|
21 |
+
# Set page style
|
22 |
+
set_home_page_style()
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Page title
|
25 |
st.markdown("# Home")
|
|
|
48 |
only source of information for rescue response planning.
|
49 |
"""
|
50 |
% (
|
51 |
+
params["url_sentinel_esa"],
|
52 |
+
params["url_unspider_tutorial"],
|
53 |
+
params["url_gee"],
|
54 |
),
|
55 |
unsafe_allow_html=True,
|
56 |
)
|
app/pages/1_π_Flood_extent_analysis.py
CHANGED
@@ -8,14 +8,19 @@ import requests
|
|
8 |
import streamlit as st
|
9 |
import streamlit_ext as ste
|
10 |
from folium.plugins import Draw, Geocoder, MiniMap
|
11 |
-
from src.config_parameters import
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
from src.utils_ee import ee_initialize
|
13 |
from src.utils_flood_analysis import derive_flood_extents
|
14 |
-
from src.utils_layout import add_about, add_logo, toggle_menu_button
|
15 |
from streamlit_folium import st_folium
|
16 |
|
17 |
# Page configuration
|
18 |
-
st.set_page_config(layout="wide", page_title=
|
19 |
|
20 |
# If app is deployed hide menu button
|
21 |
toggle_menu_button()
|
@@ -27,41 +32,8 @@ add_about()
|
|
27 |
# Page title
|
28 |
st.markdown("# Flood extent analysis")
|
29 |
|
30 |
-
# Set
|
31 |
-
|
32 |
-
"""
|
33 |
-
<style>
|
34 |
-
.streamlit-expanderHeader {
|
35 |
-
font-size: %s;
|
36 |
-
color: #000053;
|
37 |
-
}
|
38 |
-
.stDateInput > label {
|
39 |
-
font-size: %s;
|
40 |
-
}
|
41 |
-
.stSlider > label {
|
42 |
-
font-size: %s;
|
43 |
-
}
|
44 |
-
.stRadio > label {
|
45 |
-
font-size: %s;
|
46 |
-
}
|
47 |
-
.stButton > button {
|
48 |
-
font-size: %s;
|
49 |
-
font-weight: %s;
|
50 |
-
background-color: %s;
|
51 |
-
}
|
52 |
-
</style>
|
53 |
-
"""
|
54 |
-
% (
|
55 |
-
config["expander_header_fontsize"],
|
56 |
-
config["widget_header_fontsize"],
|
57 |
-
config["widget_header_fontsize"],
|
58 |
-
config["widget_header_fontsize"],
|
59 |
-
config["button_text_fontsize"],
|
60 |
-
config["button_text_fontweight"],
|
61 |
-
config["button_background_color"],
|
62 |
-
),
|
63 |
-
unsafe_allow_html=True,
|
64 |
-
)
|
65 |
|
66 |
# Initialise Google Earth Engine
|
67 |
ee_initialize()
|
|
|
8 |
import streamlit as st
|
9 |
import streamlit_ext as ste
|
10 |
from folium.plugins import Draw, Geocoder, MiniMap
|
11 |
+
from src.config_parameters import params
|
12 |
+
from src.utils import (
|
13 |
+
add_about,
|
14 |
+
add_logo,
|
15 |
+
set_tool_page_style,
|
16 |
+
toggle_menu_button,
|
17 |
+
)
|
18 |
from src.utils_ee import ee_initialize
|
19 |
from src.utils_flood_analysis import derive_flood_extents
|
|
|
20 |
from streamlit_folium import st_folium
|
21 |
|
22 |
# Page configuration
|
23 |
+
st.set_page_config(layout="wide", page_title=params["browser_title"])
|
24 |
|
25 |
# If app is deployed hide menu button
|
26 |
toggle_menu_button()
|
|
|
32 |
# Page title
|
33 |
st.markdown("# Flood extent analysis")
|
34 |
|
35 |
+
# Set page style
|
36 |
+
set_tool_page_style()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Initialise Google Earth Engine
|
39 |
ee_initialize()
|
app/pages/2_π_Documentation.py
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
"""Documentation page for Streamlit app."""
|
2 |
import streamlit as st
|
3 |
from PIL import Image
|
4 |
-
from src.config_parameters import
|
5 |
-
from src.
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Page configuration
|
8 |
-
st.set_page_config(layout="wide", page_title=
|
9 |
|
10 |
# If app is deployed hide menu button
|
11 |
toggle_menu_button()
|
@@ -14,14 +19,8 @@ toggle_menu_button()
|
|
14 |
add_logo("app/img/MA-logo.png")
|
15 |
add_about()
|
16 |
|
17 |
-
# Set
|
18 |
-
|
19 |
-
"""
|
20 |
-
<style> p { font-size: %s; } </style>
|
21 |
-
"""
|
22 |
-
% config["docs_fontsize"],
|
23 |
-
unsafe_allow_html=True,
|
24 |
-
)
|
25 |
|
26 |
# Page title
|
27 |
st.markdown("# Documentation")
|
@@ -51,10 +50,10 @@ st.markdown(
|
|
51 |
</ul>
|
52 |
"""
|
53 |
% (
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
),
|
59 |
unsafe_allow_html=True,
|
60 |
)
|
@@ -80,8 +79,8 @@ with col2:
|
|
80 |
</p>
|
81 |
"""
|
82 |
% (
|
83 |
-
|
84 |
-
|
85 |
),
|
86 |
unsafe_allow_html=True,
|
87 |
)
|
@@ -128,7 +127,7 @@ st.markdown(
|
|
128 |
|
129 |
# Add image satellite overview
|
130 |
st.image(
|
131 |
-
"%s" %
|
132 |
width=1000,
|
133 |
)
|
134 |
st.markdown(
|
@@ -138,7 +137,7 @@ st.markdown(
|
|
138 |
'%s'>source</a>).
|
139 |
</p>
|
140 |
"""
|
141 |
-
% (
|
142 |
unsafe_allow_html=True,
|
143 |
)
|
144 |
|
@@ -171,10 +170,10 @@ st.markdown(
|
|
171 |
<a href='%s'>1</a>, <a href='%s'>2</a><br>
|
172 |
"""
|
173 |
% (
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
),
|
179 |
unsafe_allow_html=True,
|
180 |
)
|
|
|
1 |
"""Documentation page for Streamlit app."""
|
2 |
import streamlit as st
|
3 |
from PIL import Image
|
4 |
+
from src.config_parameters import params
|
5 |
+
from src.utils import (
|
6 |
+
add_about,
|
7 |
+
add_logo,
|
8 |
+
set_doc_page_style,
|
9 |
+
toggle_menu_button,
|
10 |
+
)
|
11 |
|
12 |
# Page configuration
|
13 |
+
st.set_page_config(layout="wide", page_title=params["browser_title"])
|
14 |
|
15 |
# If app is deployed hide menu button
|
16 |
toggle_menu_button()
|
|
|
19 |
add_logo("app/img/MA-logo.png")
|
20 |
add_about()
|
21 |
|
22 |
+
# Set page style
|
23 |
+
set_doc_page_style()
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
# Page title
|
26 |
st.markdown("# Documentation")
|
|
|
50 |
</ul>
|
51 |
"""
|
52 |
% (
|
53 |
+
params["url_sentinel_dataset"],
|
54 |
+
params["url_gee"],
|
55 |
+
params["url_elevation_dataset"],
|
56 |
+
params["url_surface_water_dataset"],
|
57 |
),
|
58 |
unsafe_allow_html=True,
|
59 |
)
|
|
|
79 |
</p>
|
80 |
"""
|
81 |
% (
|
82 |
+
params["docs_caption_fontsize"],
|
83 |
+
params["url_unspider_tutorial_detail"],
|
84 |
),
|
85 |
unsafe_allow_html=True,
|
86 |
)
|
|
|
127 |
|
128 |
# Add image satellite overview
|
129 |
st.image(
|
130 |
+
"%s" % params["url_sentinel_img"],
|
131 |
width=1000,
|
132 |
)
|
133 |
st.markdown(
|
|
|
137 |
'%s'>source</a>).
|
138 |
</p>
|
139 |
"""
|
140 |
+
% (params["docs_caption_fontsize"], params["url_sentinel_img_location"]),
|
141 |
unsafe_allow_html=True,
|
142 |
)
|
143 |
|
|
|
170 |
<a href='%s'>1</a>, <a href='%s'>2</a><br>
|
171 |
"""
|
172 |
% (
|
173 |
+
params["url_unspider_tutorial"],
|
174 |
+
params["url_sentinel_esa"],
|
175 |
+
params["url_publication_1"],
|
176 |
+
params["url_publication_2"],
|
177 |
),
|
178 |
unsafe_allow_html=True,
|
179 |
)
|
app/src/config_parameters.py
CHANGED
@@ -1,23 +1,7 @@
|
|
1 |
"""Configuration file."""
|
2 |
-
|
3 |
# Title browser tab
|
4 |
"browser_title": "Flood mapping tool - MapAction",
|
5 |
-
# Sidebar
|
6 |
-
"MA_logo_width": "60%",
|
7 |
-
"MA_logo_background_position": "35% 10%",
|
8 |
-
"sidebar_header": "Flood Mapping Tool",
|
9 |
-
"sidebar_header_fontsize": "30px",
|
10 |
-
"sidebar_header_fontweight": "bold",
|
11 |
-
"about_box_background_color": "#dae7f4",
|
12 |
-
# Introduction and Documentation
|
13 |
-
"docs_fontsize": "1.2rem",
|
14 |
-
"docs_caption_fontsize": "1rem",
|
15 |
-
# Tool
|
16 |
-
"expander_header_fontsize": "23px",
|
17 |
-
"widget_header_fontsize": "18px",
|
18 |
-
"button_text_fontsize": "24px",
|
19 |
-
"button_text_fontweight": "bold",
|
20 |
-
"button_background_color": "#dae7f4",
|
21 |
# Data scientists involved
|
22 |
"data_scientists": {
|
23 |
"Piet": "pgerrits@mapaction.org",
|
@@ -72,4 +56,21 @@ config = {
|
|
72 |
"https://www.sciencedirect.com/science/article/abs/pii/"
|
73 |
"S0924271620301702"
|
74 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
}
|
|
|
1 |
"""Configuration file."""
|
2 |
+
params = {
|
3 |
# Title browser tab
|
4 |
"browser_title": "Flood mapping tool - MapAction",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
# Data scientists involved
|
6 |
"data_scientists": {
|
7 |
"Piet": "pgerrits@mapaction.org",
|
|
|
56 |
"https://www.sciencedirect.com/science/article/abs/pii/"
|
57 |
"S0924271620301702"
|
58 |
),
|
59 |
+
# Layout and styles
|
60 |
+
## Sidebar
|
61 |
+
"MA_logo_width": "60%",
|
62 |
+
"MA_logo_background_position": "35% 10%",
|
63 |
+
"sidebar_header": "Flood Mapping Tool",
|
64 |
+
"sidebar_header_fontsize": "30px",
|
65 |
+
"sidebar_header_fontweight": "bold",
|
66 |
+
"about_box_background_color": "#dae7f4",
|
67 |
+
## Introduction and Documentation pages
|
68 |
+
"docs_fontsize": "1.2rem",
|
69 |
+
"docs_caption_fontsize": "1rem",
|
70 |
+
## Tool page
|
71 |
+
"expander_header_fontsize": "23px",
|
72 |
+
"widget_header_fontsize": "18px",
|
73 |
+
"button_text_fontsize": "24px",
|
74 |
+
"button_text_fontweight": "bold",
|
75 |
+
"button_background_color": "#dae7f4",
|
76 |
}
|
app/src/{utils_layout.py β utils.py}
RENAMED
@@ -4,7 +4,7 @@ import os
|
|
4 |
from datetime import date
|
5 |
|
6 |
import streamlit as st
|
7 |
-
from src.config_parameters import
|
8 |
|
9 |
|
10 |
# Check if app is deployed
|
@@ -28,6 +28,69 @@ def toggle_menu_button():
|
|
28 |
)
|
29 |
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
# Sidebar
|
32 |
@st.cache(allow_output_mutation=True)
|
33 |
def get_base64_of_bin_file(png_file):
|
@@ -85,12 +148,12 @@ def build_markup_for_logo(
|
|
85 |
</style>
|
86 |
""" % (
|
87 |
binary_string,
|
88 |
-
|
89 |
-
|
90 |
"",
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
)
|
95 |
|
96 |
|
@@ -154,11 +217,11 @@ def add_about():
|
|
154 |
</div>
|
155 |
"""
|
156 |
% (
|
157 |
-
|
158 |
today,
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
),
|
163 |
unsafe_allow_html=True,
|
164 |
)
|
@@ -169,7 +232,7 @@ def add_about():
|
|
169 |
|
170 |
# Add data scientists and emails
|
171 |
contacts_text = ""
|
172 |
-
for ds, email in
|
173 |
contacts_text += ds + (
|
174 |
"<span style='float:right; margin-right: 3px;'>"
|
175 |
"<a href='mailto:%s'>%s</a></span><br>" % (email, email)
|
@@ -192,6 +255,6 @@ def add_about():
|
|
192 |
</p>
|
193 |
</div>
|
194 |
"""
|
195 |
-
% (
|
196 |
unsafe_allow_html=True,
|
197 |
)
|
|
|
4 |
from datetime import date
|
5 |
|
6 |
import streamlit as st
|
7 |
+
from src.config_parameters import params
|
8 |
|
9 |
|
10 |
# Check if app is deployed
|
|
|
28 |
)
|
29 |
|
30 |
|
31 |
+
# Home page
|
32 |
+
def set_home_page_style():
|
33 |
+
"""Set style home page."""
|
34 |
+
st.markdown(
|
35 |
+
"""
|
36 |
+
<style> p { font-size: %s; } </style>
|
37 |
+
"""
|
38 |
+
% params["docs_fontsize"],
|
39 |
+
unsafe_allow_html=True,
|
40 |
+
)
|
41 |
+
|
42 |
+
|
43 |
+
# Documentation page
|
44 |
+
def set_doc_page_style():
|
45 |
+
"""Set style documentation page."""
|
46 |
+
st.markdown(
|
47 |
+
"""
|
48 |
+
<style> p { font-size: %s; } </style>
|
49 |
+
"""
|
50 |
+
% params["docs_fontsize"],
|
51 |
+
unsafe_allow_html=True,
|
52 |
+
)
|
53 |
+
|
54 |
+
|
55 |
+
# Tool page
|
56 |
+
def set_tool_page_style():
|
57 |
+
"""Set style tool page."""
|
58 |
+
st.markdown(
|
59 |
+
"""
|
60 |
+
<style>
|
61 |
+
.streamlit-expanderHeader {
|
62 |
+
font-size: %s;
|
63 |
+
color: #000053;
|
64 |
+
}
|
65 |
+
.stDateInput > label {
|
66 |
+
font-size: %s;
|
67 |
+
}
|
68 |
+
.stSlider > label {
|
69 |
+
font-size: %s;
|
70 |
+
}
|
71 |
+
.stRadio > label {
|
72 |
+
font-size: %s;
|
73 |
+
}
|
74 |
+
.stButton > button {
|
75 |
+
font-size: %s;
|
76 |
+
font-weight: %s;
|
77 |
+
background-color: %s;
|
78 |
+
}
|
79 |
+
</style>
|
80 |
+
"""
|
81 |
+
% (
|
82 |
+
params["expander_header_fontsize"],
|
83 |
+
params["widget_header_fontsize"],
|
84 |
+
params["widget_header_fontsize"],
|
85 |
+
params["widget_header_fontsize"],
|
86 |
+
params["button_text_fontsize"],
|
87 |
+
params["button_text_fontweight"],
|
88 |
+
params["button_background_color"],
|
89 |
+
),
|
90 |
+
unsafe_allow_html=True,
|
91 |
+
)
|
92 |
+
|
93 |
+
|
94 |
# Sidebar
|
95 |
@st.cache(allow_output_mutation=True)
|
96 |
def get_base64_of_bin_file(png_file):
|
|
|
148 |
</style>
|
149 |
""" % (
|
150 |
binary_string,
|
151 |
+
params["MA_logo_background_position"],
|
152 |
+
params["MA_logo_width"],
|
153 |
"",
|
154 |
+
params["sidebar_header"],
|
155 |
+
params["sidebar_header_fontsize"],
|
156 |
+
params["sidebar_header_fontweight"],
|
157 |
)
|
158 |
|
159 |
|
|
|
217 |
</div>
|
218 |
"""
|
219 |
% (
|
220 |
+
params["about_box_background_color"],
|
221 |
today,
|
222 |
+
params["url_project_wiki"],
|
223 |
+
params["url_github_repo"],
|
224 |
+
params["url_data_science_wiki"],
|
225 |
),
|
226 |
unsafe_allow_html=True,
|
227 |
)
|
|
|
232 |
|
233 |
# Add data scientists and emails
|
234 |
contacts_text = ""
|
235 |
+
for ds, email in params["data_scientists"].items():
|
236 |
contacts_text += ds + (
|
237 |
"<span style='float:right; margin-right: 3px;'>"
|
238 |
"<a href='mailto:%s'>%s</a></span><br>" % (email, email)
|
|
|
255 |
</p>
|
256 |
</div>
|
257 |
"""
|
258 |
+
% (params["about_box_background_color"], contacts_text),
|
259 |
unsafe_allow_html=True,
|
260 |
)
|
app/src/utils_ee.py
CHANGED
@@ -3,7 +3,7 @@ import ee
|
|
3 |
import streamlit as st
|
4 |
from ee import oauth
|
5 |
from google.oauth2 import service_account
|
6 |
-
from src.
|
7 |
|
8 |
|
9 |
@st.experimental_memo
|
|
|
3 |
import streamlit as st
|
4 |
from ee import oauth
|
5 |
from google.oauth2 import service_account
|
6 |
+
from src.utils import is_app_on_streamlit
|
7 |
|
8 |
|
9 |
@st.experimental_memo
|
setup.cfg
CHANGED
@@ -2,5 +2,6 @@
|
|
2 |
extend-ignore =
|
3 |
SFS301 # Allow f-strings
|
4 |
T001 # Allow print statements
|
5 |
-
ISC001 # Allow
|
6 |
SFS101 # Allow percent operator in string
|
|
|
|
2 |
extend-ignore =
|
3 |
SFS301 # Allow f-strings
|
4 |
T001 # Allow print statements
|
5 |
+
ISC001 # Allow implictly concatenated string literals in one line
|
6 |
SFS101 # Allow percent operator in string
|
7 |
+
E266 # Allow more than one # for comments
|