Spaces:
Sleeping
Sleeping
File size: 11,028 Bytes
0ab0788 | 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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | import streamlit as st
from app.utils.map_utils import plot_map
from app.utils.legends_utils import get_stat_unit
from app.pipelines.import_data import pipeline_data
from app.pipelines.import_config import pipeline_config
from app.pipelines.import_map import pipeline_map
from app.pipelines.import_scatter import pipeline_scatter
from app.utils.show_info import show_info_data, show_info_metric
st.set_page_config(layout="wide", page_title="Analyse interactive des précipitations en France (1959–2022)", page_icon="🌧️")
st.markdown("""
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600&display=swap" rel="stylesheet">
""", unsafe_allow_html=True)
st.markdown("""
<style>
* {
font-size: 10px !important;
}
/* Responsive layout des colonnes */
@media screen and (max-width: 1000px) {
.element-container:has(> .stColumn) {
display: flex;
flex-wrap: wrap;
}
.element-container:has(> .stColumn) .stColumn {
width: 48% !important;
min-width: 48% !important;
}
}
@media screen and (max-width: 600px) {
.element-container:has(> .stColumn) .stColumn {
width: 100% !important;
min-width: 100% !important;
}
}
</style>
""", unsafe_allow_html=True)
css = """
<style>
/* -------------------- VARIABLES GLOBALES -------------------- */
:root{
--primary:#5A7BFF;
--primary-light:#8FA0FF;
--accent:#FF7A59;
--bg:rgba(245,247,250,0.65);
--card:rgba(255,255,255,0.35);
--text:#1F2D3D;
--text-light:#6B7C93;
--radius:18px;
--shadow:0 12px 28px rgba(0,0,0,.12);
--blur:18px;
--font:"Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
/* -------------------- RESET & BODY -------------------- */
html, body, [class*="stAppViewContainer"]{
font-family: var(--font) !important;
color: var(--text);
}
body{
background: linear-gradient(135deg,#EEF2FF 0%,#FDFBFF 60%,#F0F4FF 100%) fixed !important;
}
/* Conteneur principal */
.block-container{
padding-top: 2.5rem !important;
padding-bottom: 3rem !important;
max-width: 98%;
}
/* -------------------- EN-TÊTES -------------------- */
h1,h2,h3,h4{
font-weight: 600 !important;
letter-spacing: -0.01em;
color: var(--text);
}
h1{
font-size: 2.1rem !important;
margin-bottom: 1.2rem;
}
/* -------------------- CARTES / WIDGETS -------------------- */
section.main > div{
backdrop-filter: blur(var(--blur));
background: var(--card);
border-radius: var(--radius);
box-shadow: var(--shadow);
padding: 1.5rem 1.8rem;
}
/* -------------------- LABELS DES WIDGETS -------------------- */
.css-10trblm, .stSlider label, .stSelectbox label, .stNumberInput label, .stMultiSelect label{
font-size: 0.88rem !important;
font-weight: 500 !important;
color: var(--text-light) !important;
margin-bottom: .4rem !important;
text-transform: uppercase;
letter-spacing: .04em;
}
/* -------------------- SELECTBOX -------------------- */
.stSelectbox > div div[data-baseweb="select"]{
background: rgba(255,255,255,0.55);
border-radius: var(--radius) !important;
border: 1px solid rgba(0,0,0,.05);
box-shadow: inset 0 2px 4px rgba(0,0,0,.04);
}
.stSelectbox > div div[data-baseweb="select"]:hover{
border-color: var(--primary-light);
}
.stSelectbox svg{
stroke: var(--primary) !important;
}
/* -------------------- SLIDER -------------------- */
[data-testid="stSlider"] > div{
padding-top: .6rem;
}
[data-testid="stSlider"] [data-testid="stThumbValue"]{
background: var(--primary);
color: #fff;
border-radius: 10px;
padding: 2px 8px;
font-size: .75rem;
box-shadow: var(--shadow);
}
[data-testid="stSlider"] [data-testid="stTickBar"]{
background: rgba(0,0,0,.08);
}
[data-testid="stSlider"] [data-testid="stTrack"]{
background: rgba(0,0,0,.12);
}
[data-testid="stSlider"] [data-testid="stTrack"] > div{
background: var(--primary);
}
/* -------------------- INPUT NUMBER / TEXT -------------------- */
.stNumberInput input, .stTextInput input{
background: rgba(255,255,255,0.6) !important;
border-radius: var(--radius) !important;
border: 1px solid rgba(0,0,0,.05) !important;
box-shadow: inset 0 2px 4px rgba(0,0,0,.05) !important;
}
/* -------------------- BOUTON -------------------- */
.stButton>button{
background: var(--primary) !important;
color: #fff !important;
border: none !important;
border-radius: var(--radius) !important;
padding: .65rem 1.4rem !important;
font-weight: 600 !important;
letter-spacing: .02em;
transition: all .22s ease;
box-shadow: 0 8px 18px rgba(90,123,255,.28);
}
.stButton>button:hover{
background: var(--primary-light) !important;
transform: translateY(-2px) !important;
box-shadow: 0 12px 24px rgba(90,123,255,.32);
}
.stButton>button:active{
transform: translateY(0) scale(.98) !important;
}
/* Petit bouton (col6) */
[class*="stColumn"]:nth-child(7) .stButton>button{
padding: .55rem .9rem !important;
font-size: .85rem !important;
}
/* -------------------- TOOLTIPS -------------------- */
[data-baseweb="tooltip"]{
backdrop-filter: blur(12px);
background: rgba(0,0,0,.75);
color: #fff;
border-radius: 8px;
font-size: .75rem;
padding: .4rem .65rem;
}
/* -------------------- SIDEBAR -------------------- */
.sidebar .block-container{
padding: 1rem 1rem 2rem 1rem !important;
}
[class*="stSidebar"]{
background: rgba(255,255,255,0.7) !important;
backdrop-filter: blur(18px);
box-shadow: var(--shadow);
}
/* -------------------- CHARTS -------------------- */
.js-plotly-plot .plotly .main-svg{
border-radius: var(--radius);
box-shadow: var(--shadow);
}
/* -------------------- SCROLLBAR -------------------- */
::-webkit-scrollbar{
width: 8px;
height: 8px;
}
::-webkit-scrollbar-thumb{
background: var(--primary-light);
border-radius: 10px;
}
::-webkit-scrollbar-track{
background: transparent;
}
/* -------------------- SLIDER -------------------- */
/* Cacher totalement les chiffres min/max + graduations */
[data-testid="stSliderTickBarMin"], [data-testid="stSliderTickBarMax"]{
display:none !important;
}
stSliderTickBarMin
/* -------------------- MASQUER MENU & FOOTER -------------------- */
#MainMenu{visibility:hidden;}
footer{visibility:hidden;}
header{visibility:hidden;}
/* -------------------- GRADIENT TEXT -------------------- */
.gradient-premium {
font-size: 2.5rem !important; /* Titre XXL */
font-weight: 800 !important; /* Plus de présence */
letter-spacing: -0.025em !important; /* Ajustement espacement */
/* Dégradé en trois couleurs */
background: linear-gradient(
360deg,
#5A7BFF 10%,
#5A7BFF 100%,
#F0F4FF 150%
) !important;
color: transparent !important;
-webkit-text-fill-color: transparent !important;
-webkit-background-clip: text !important;
background-clip: text !important;
/* contour/glow léger */
text-shadow:
0 0 2px rgba(255,255,255,0.8)
display: inline-block;
}
</style>
"""
st.markdown(css, unsafe_allow_html=True)
def show(
config_path: dict,
height: int=600
):
# Chargement des config
params_config = pipeline_config(config_path, type="stat")
config = params_config["config"]
stat_choice = params_config["stat_choice"]
season_choice = params_config["season_choice"]
stat_choice_key = params_config["stat_choice_key"]
scale_choice_key = params_config["scale_choice_key"]
min_year_choice = params_config["min_year_choice"]
max_year_choice = params_config["max_year_choice"]
season_choice_key = params_config["season_choice_key"]
missing_rate = params_config["missing_rate"]
quantile_choice = params_config["quantile_choice"]
scale_choice = params_config["scale_choice"]
show_relief = params_config["show_relief"]
show_stations = params_config["show_stations"]
# Préparation des paramètres pour pipeline_data
params_load = (
stat_choice_key,
scale_choice_key,
min_year_choice,
max_year_choice,
season_choice_key,
missing_rate,
quantile_choice,
scale_choice
)
# Obtention des données
result = pipeline_data(params_load, config, use_cache=True)
# Chargement des affichages graphiques
unit_label = get_stat_unit(stat_choice_key, scale_choice_key)
params_map = (
stat_choice_key,
result,
unit_label,
height
)
layer, scatter_layer, tooltip, view_state, html_legend = pipeline_map(params_map)
col1, col2, col3 = st.columns([1, 0.15, 1])
with col1:
scatter_layer = None if not show_stations else scatter_layer
deck = plot_map([layer, scatter_layer], view_state, tooltip, activate_relief=show_relief)
st.markdown(
f"""
<div style='text-align: left; margin-bottom: 10px;'>
<b>{stat_choice} des précipitations de {min_year_choice} à {max_year_choice} ({season_choice.lower()})</b>
</div>
""",
unsafe_allow_html=True
)
if deck:
st.pydeck_chart(deck, use_container_width=True, height=height)
with col2:
st.markdown(html_legend, unsafe_allow_html=True)
with col3:
params_scatter = (
result,
stat_choice_key,
scale_choice_key,
stat_choice,unit_label,
height
)
n_tot_mod, n_tot_obs, me, mae, rmse, r2, scatter = pipeline_scatter(params_scatter)
st.markdown(
"""
<div style='text-align: left; font-size: 0.8em; color: grey; margin-top: 0px;'>
Données CP-RCM, 2.5 km, forçage ERA5, réanalyse ECMWF
</div>
""",
unsafe_allow_html=True
)
st.plotly_chart(scatter, use_container_width=True)
col0bis, col1bis, col2bis, col3bis, col4bis, col5bis, col6bis = st.columns(7)
show_info_data(col0bis, "CP-AROME map", result["modelised_show"].shape[0], n_tot_mod)
show_info_data(col1bis, "Stations", result["observed_show"].shape[0], n_tot_obs)
show_info_data(col2bis, "CP-AROME plot", result["modelised"].shape[0], n_tot_mod)
show_info_metric(col3bis, "ME", me)
show_info_metric(col4bis, "MAE", mae)
show_info_metric(col5bis, "RMSE", rmse)
show_info_metric(col6bis, "r²", r2)
if __name__ == "__main__":
config_path = "app/config/config.yaml"
st.markdown("""
<div style="text-align: center; margin-bottom: 2rem;">
<h1 style="
font-family: var(--font);
margin: 0;
">
<span class="gradient-premium">
Analyse interactive des précipitations en France — 1959 – 2022
</span>
</h1>
</div>
""", unsafe_allow_html=True)
show(config_path)
|