Spaces:
Running
Running
upgraded to python3.12, uv and latest package versions
Browse files- .gitignore +2 -0
- README.md +2 -4
- app/Home.py +4 -5
- app/pages/1_π_Flood_extent_analysis.py +5 -6
- app/pages/2_π_Documentation.py +0 -3
- app/src/config_parameters.py +0 -2
- app/src/gfm.py +2 -2
- app/src/utils.py +0 -82
- pyproject.toml +14 -6
- requirements.txt +0 -9
- setup.cfg +0 -15
- uv.lock +0 -0
.gitignore
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
.env
|
|
|
|
|
2 |
|
3 |
# Byte-compiled / optimized / DLL files
|
4 |
__pycache__/
|
|
|
1 |
.env
|
2 |
+
/output/*
|
3 |
+
!/output/.gitkeep
|
4 |
|
5 |
# Byte-compiled / optimized / DLL files
|
6 |
__pycache__/
|
README.md
CHANGED
@@ -5,13 +5,11 @@
|
|
5 |
To run the app you will need a (free) GFM account. To get one register at https://portal.gfm.eodc.eu/login . Once you have an account create a file `.env` with the content of `.env_template` where you will need to fill out your GFM username and password. The `.env` file will be gitignored.
|
6 |
|
7 |
### Python
|
8 |
-
|
|
|
9 |
```
|
10 |
-
pip install -r requirements.txt
|
11 |
streamlit run app/Home.py
|
12 |
```
|
13 |
-
For now its kept on python 3.10 like original Mapaction app and packages have not yet been updated.
|
14 |
-
Just create venv and pip install requirements. Then `streamlit run app/Home.py`
|
15 |
|
16 |
## Project
|
17 |
TODO: Add more complete documentation.
|
|
|
5 |
To run the app you will need a (free) GFM account. To get one register at https://portal.gfm.eodc.eu/login . Once you have an account create a file `.env` with the content of `.env_template` where you will need to fill out your GFM username and password. The `.env` file will be gitignored.
|
6 |
|
7 |
### Python
|
8 |
+
Project is using python 3.12. Install requirements from `pyproject.toml` in your preferred way. We suggest using `uv`, see [here](https://docs.astral.sh/uv/getting-started/installation/) for installation instructions. Once installed your can run `uv sync` to create a `.venv` folder. Activate the `.venv` and then run the line below to run the app:
|
9 |
+
|
10 |
```
|
|
|
11 |
streamlit run app/Home.py
|
12 |
```
|
|
|
|
|
13 |
|
14 |
## Project
|
15 |
TODO: Add more complete documentation.
|
app/Home.py
CHANGED
@@ -2,21 +2,20 @@
|
|
2 |
|
3 |
import streamlit as st
|
4 |
from src.config_parameters import params
|
|
|
|
|
|
|
|
|
5 |
from src.utils import (
|
6 |
add_about,
|
7 |
-
add_logo,
|
8 |
set_home_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()
|
17 |
|
18 |
# Create sidebar
|
19 |
-
add_logo("app/img/MA-logo.png")
|
20 |
add_about()
|
21 |
|
22 |
# Set page style
|
|
|
2 |
|
3 |
import streamlit as st
|
4 |
from src.config_parameters import params
|
5 |
+
|
6 |
+
# Page configuration
|
7 |
+
st.set_page_config(layout="wide", page_title=params["browser_title"])
|
8 |
+
|
9 |
from src.utils import (
|
10 |
add_about,
|
|
|
11 |
set_home_page_style,
|
12 |
toggle_menu_button,
|
13 |
)
|
14 |
|
|
|
|
|
|
|
15 |
# If app is deployed hide menu button
|
16 |
toggle_menu_button()
|
17 |
|
18 |
# Create sidebar
|
|
|
19 |
add_about()
|
20 |
|
21 |
# Set page style
|
app/pages/1_π_Flood_extent_analysis.py
CHANGED
@@ -7,7 +7,6 @@ from src.config_parameters import params
|
|
7 |
from src.gfm import download_stuff, visualise_stuff
|
8 |
from src.utils import (
|
9 |
add_about,
|
10 |
-
add_logo,
|
11 |
set_tool_page_style,
|
12 |
toggle_menu_button,
|
13 |
)
|
@@ -20,7 +19,6 @@ st.set_page_config(layout="wide", page_title=params["browser_title"])
|
|
20 |
toggle_menu_button()
|
21 |
|
22 |
# Create sidebar
|
23 |
-
add_logo("app/img/MA-logo.png")
|
24 |
add_about()
|
25 |
|
26 |
# Page title
|
@@ -55,7 +53,6 @@ with col1:
|
|
55 |
location=[52.205276, 0.119167],
|
56 |
zoom_start=3,
|
57 |
control_scale=True,
|
58 |
-
# crs='EPSG4326'
|
59 |
)
|
60 |
# Add drawing tools to map
|
61 |
Draw(
|
@@ -74,7 +71,7 @@ with col1:
|
|
74 |
# Add minimap to map
|
75 |
MiniMap().add_to(Map)
|
76 |
# Export map to Streamlit
|
77 |
-
|
78 |
with col2:
|
79 |
# Add collapsable container for image dates
|
80 |
with st.expander("Choose Image Dates"):
|
@@ -97,7 +94,9 @@ with col2:
|
|
97 |
# Introduce date validation
|
98 |
check_dates = start_date <= end_date
|
99 |
# Introduce drawing validation (a polygon needs to exist)
|
100 |
-
check_drawing =
|
|
|
|
|
101 |
# What happens when button is clicked on?
|
102 |
if submitted:
|
103 |
with col2:
|
@@ -111,7 +110,7 @@ if submitted:
|
|
111 |
# Add output for computation
|
112 |
with st.spinner("Computing... Please wait..."):
|
113 |
# Extract coordinates from drawn polygon
|
114 |
-
coords =
|
115 |
print(f"Coords: {coords}")
|
116 |
# Create geometry from coordinates
|
117 |
download_stuff(coords)
|
|
|
7 |
from src.gfm import download_stuff, visualise_stuff
|
8 |
from src.utils import (
|
9 |
add_about,
|
|
|
10 |
set_tool_page_style,
|
11 |
toggle_menu_button,
|
12 |
)
|
|
|
19 |
toggle_menu_button()
|
20 |
|
21 |
# Create sidebar
|
|
|
22 |
add_about()
|
23 |
|
24 |
# Page title
|
|
|
53 |
location=[52.205276, 0.119167],
|
54 |
zoom_start=3,
|
55 |
control_scale=True,
|
|
|
56 |
)
|
57 |
# Add drawing tools to map
|
58 |
Draw(
|
|
|
71 |
# Add minimap to map
|
72 |
MiniMap().add_to(Map)
|
73 |
# Export map to Streamlit
|
74 |
+
input_map = st_folium(Map, width=800, height=600)
|
75 |
with col2:
|
76 |
# Add collapsable container for image dates
|
77 |
with st.expander("Choose Image Dates"):
|
|
|
94 |
# Introduce date validation
|
95 |
check_dates = start_date <= end_date
|
96 |
# Introduce drawing validation (a polygon needs to exist)
|
97 |
+
check_drawing = (
|
98 |
+
input_map["all_drawings"] != [] and input_map["all_drawings"] is not None
|
99 |
+
)
|
100 |
# What happens when button is clicked on?
|
101 |
if submitted:
|
102 |
with col2:
|
|
|
110 |
# Add output for computation
|
111 |
with st.spinner("Computing... Please wait..."):
|
112 |
# Extract coordinates from drawn polygon
|
113 |
+
coords = input_map["all_drawings"][-1]["geometry"]["coordinates"][0]
|
114 |
print(f"Coords: {coords}")
|
115 |
# Create geometry from coordinates
|
116 |
download_stuff(coords)
|
app/pages/2_π_Documentation.py
CHANGED
@@ -1,11 +1,9 @@
|
|
1 |
"""Documentation page for Streamlit app."""
|
2 |
|
3 |
import streamlit as st
|
4 |
-
from PIL import Image
|
5 |
from src.config_parameters import params
|
6 |
from src.utils import (
|
7 |
add_about,
|
8 |
-
add_logo,
|
9 |
set_doc_page_style,
|
10 |
toggle_menu_button,
|
11 |
)
|
@@ -17,7 +15,6 @@ st.set_page_config(layout="wide", page_title=params["browser_title"])
|
|
17 |
toggle_menu_button()
|
18 |
|
19 |
# Create sidebar
|
20 |
-
add_logo("app/img/MA-logo.png")
|
21 |
add_about()
|
22 |
|
23 |
# Set page style
|
|
|
1 |
"""Documentation page for Streamlit app."""
|
2 |
|
3 |
import streamlit as st
|
|
|
4 |
from src.config_parameters import params
|
5 |
from src.utils import (
|
6 |
add_about,
|
|
|
7 |
set_doc_page_style,
|
8 |
toggle_menu_button,
|
9 |
)
|
|
|
15 |
toggle_menu_button()
|
16 |
|
17 |
# Create sidebar
|
|
|
18 |
add_about()
|
19 |
|
20 |
# Set page style
|
app/src/config_parameters.py
CHANGED
@@ -21,8 +21,6 @@ params = {
|
|
21 |
),
|
22 |
# Layout and styles
|
23 |
## Sidebar
|
24 |
-
"MA_logo_width": "60%",
|
25 |
-
"MA_logo_background_position": "35% 10%",
|
26 |
"sidebar_header": "Flood Mapping Tool",
|
27 |
"sidebar_header_fontsize": "30px",
|
28 |
"sidebar_header_fontweight": "bold",
|
|
|
21 |
),
|
22 |
# Layout and styles
|
23 |
## Sidebar
|
|
|
|
|
24 |
"sidebar_header": "Flood Mapping Tool",
|
25 |
"sidebar_header_fontsize": "30px",
|
26 |
"sidebar_header_fontweight": "bold",
|
app/src/gfm.py
CHANGED
@@ -66,8 +66,8 @@ def download_stuff(coordinates):
|
|
66 |
for f in Path("./output").glob("*"):
|
67 |
f.unlink()
|
68 |
r = requests.get(download_link)
|
69 |
-
|
70 |
-
|
71 |
|
72 |
|
73 |
def visualise_stuff():
|
|
|
66 |
for f in Path("./output").glob("*"):
|
67 |
f.unlink()
|
68 |
r = requests.get(download_link)
|
69 |
+
with zipfile.ZipFile(io.BytesIO(r.content)) as z:
|
70 |
+
z.extractall(str(Path("./output")))
|
71 |
|
72 |
|
73 |
def visualise_stuff():
|
app/src/utils.py
CHANGED
@@ -94,88 +94,6 @@ def set_tool_page_style():
|
|
94 |
|
95 |
|
96 |
# Sidebar
|
97 |
-
@st.cache(allow_output_mutation=True)
|
98 |
-
def get_base64_of_bin_file(png_file):
|
99 |
-
"""
|
100 |
-
Get base64 from image file.
|
101 |
-
|
102 |
-
Inputs:
|
103 |
-
png_file (str): image filename
|
104 |
-
|
105 |
-
Returns:
|
106 |
-
str: encoded ASCII file
|
107 |
-
"""
|
108 |
-
with open(png_file, "rb") as f:
|
109 |
-
data = f.read()
|
110 |
-
return base64.b64encode(data).decode()
|
111 |
-
|
112 |
-
|
113 |
-
def build_markup_for_logo(
|
114 |
-
png_file,
|
115 |
-
):
|
116 |
-
"""
|
117 |
-
Create full string for navigation bar, including logo and title.
|
118 |
-
|
119 |
-
Inputs:
|
120 |
-
png_file (str): image filename
|
121 |
-
background_position (str): position logo
|
122 |
-
image_width (str): width logo
|
123 |
-
image_height (str): height logo
|
124 |
-
|
125 |
-
Returns
|
126 |
-
str: full string with logo and title for sidebar
|
127 |
-
"""
|
128 |
-
binary_string = get_base64_of_bin_file(png_file)
|
129 |
-
return """
|
130 |
-
<style>
|
131 |
-
[data-testid="stSidebarNav"] {
|
132 |
-
background-image: url("data:image/png;base64,%s");
|
133 |
-
background-repeat: no-repeat;
|
134 |
-
padding-top: 50px;
|
135 |
-
padding-bottom: 10px;
|
136 |
-
background-position: %s;
|
137 |
-
background-size: %s %s;
|
138 |
-
}
|
139 |
-
[data-testid="stSidebarNav"]::before {
|
140 |
-
content: "%s";
|
141 |
-
margin-left: 20px;
|
142 |
-
margin-top: 20px;
|
143 |
-
margin-bottom: 20px;
|
144 |
-
font-size: %s;
|
145 |
-
font-weight: %s;
|
146 |
-
position: relative;
|
147 |
-
text-align: center;
|
148 |
-
top: 85px;
|
149 |
-
}
|
150 |
-
</style>
|
151 |
-
""" % (
|
152 |
-
binary_string,
|
153 |
-
params["MA_logo_background_position"],
|
154 |
-
params["MA_logo_width"],
|
155 |
-
"",
|
156 |
-
params["sidebar_header"],
|
157 |
-
params["sidebar_header_fontsize"],
|
158 |
-
params["sidebar_header_fontweight"],
|
159 |
-
)
|
160 |
-
|
161 |
-
|
162 |
-
def add_logo(png_file):
|
163 |
-
"""
|
164 |
-
Add logo to sidebar.
|
165 |
-
|
166 |
-
Inputs:
|
167 |
-
png_file (str): image filename
|
168 |
-
Returns:
|
169 |
-
None
|
170 |
-
"""
|
171 |
-
logo_markup = build_markup_for_logo(png_file)
|
172 |
-
# st.sidebar.title("ciao")
|
173 |
-
st.markdown(
|
174 |
-
logo_markup,
|
175 |
-
unsafe_allow_html=True,
|
176 |
-
)
|
177 |
-
|
178 |
-
|
179 |
def add_about():
|
180 |
"""
|
181 |
Add about and contacts to sidebar.
|
|
|
94 |
|
95 |
|
96 |
# Sidebar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
def add_about():
|
98 |
"""
|
99 |
Add about and contacts to sidebar.
|
pyproject.toml
CHANGED
@@ -1,6 +1,14 @@
|
|
1 |
-
[
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
name = "flood-mapping-gfm"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = "A streamlit app to map gfm flood forecasts"
|
5 |
+
readme = "README.md"
|
6 |
+
requires-python = ">=3.12"
|
7 |
+
dependencies = [
|
8 |
+
"requests>=2.32.3",
|
9 |
+
"geopandas>=1.0.1",
|
10 |
+
"folium>=0.19.4",
|
11 |
+
"python-dotenv==1.0.1",
|
12 |
+
"streamlit>=1.41.1",
|
13 |
+
"streamlit-folium>=0.24.0",
|
14 |
+
]
|
requirements.txt
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
earthengine-api==0.1.331
|
2 |
-
folium==0.13.0
|
3 |
-
geemap==0.17.2
|
4 |
-
streamlit==1.14.1
|
5 |
-
streamlit_ext==0.1.4
|
6 |
-
streamlit-folium==0.7.0
|
7 |
-
pre-commit==2.18.1
|
8 |
-
altair<5
|
9 |
-
python-dotenv==1.0.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setup.cfg
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
[flake8]
|
2 |
-
max-pos-args = 3
|
3 |
-
ignore =
|
4 |
-
# Allow f-strings
|
5 |
-
SFS301,
|
6 |
-
# Allow print statements
|
7 |
-
T001,
|
8 |
-
# Allow implictly concatenated string literals in one line
|
9 |
-
ISC001,
|
10 |
-
# Allow percent operator in string
|
11 |
-
SFS101,
|
12 |
-
# Allow more than one # for comments
|
13 |
-
E266,
|
14 |
-
# Allow line break before binary operator
|
15 |
-
W503
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uv.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|