-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
54 lines (42 loc) · 1.77 KB
/
app.py
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
import streamlit as st
import numpy as np
from scripts.load_data import load_data
from scripts.sidebar import create_sidebar
from scripts.subpages import display_about_page, display_dashboard_page, display_analysis_page, display_download_page
def main():
# Self-define parameters
start_date = 2015
end_date = 2021
n_input = 7
rows = 1
cols = 2
xlat = np.load("./static/assets/coords_xlat.npy")
xlong = np.load("./static/assets/coords_xlong.npy")
logo = "./static/images/logo.png"
# Create a Streamlit application
st.set_page_config(page_title="Weather Prediction App", layout='wide', initial_sidebar_state='auto', page_icon=logo)
st.title("Weather Prediction App")
# Load data
prcp_true, prcp_pred, spi_true, spi_pred, world, reservoirs_gdf = load_data(start_date, end_date)
# Store key variables in session state
st.session_state['prcp_true'] = prcp_true
st.session_state['prcp_pred'] = prcp_pred
st.session_state['spi_true'] = spi_true
st.session_state['spi_pred'] = spi_pred
st.session_state['reservoirs_gdf'] = reservoirs_gdf
# Initialize session state variables if they do not exist
variables = ['plot_type', 'dates', 'year', 'waterbody', 'target', 'true_reservoir', 'pred_reservoir']
for v in variables:
if v not in st.session_state:
st.session_state[v] = None
# Initialize sidebar
selected_page = create_sidebar(start_date, end_date, n_input, logo, reservoirs_gdf)
if selected_page == "About":
display_about_page()
elif selected_page == "Dashboard":
display_dashboard_page(world, rows, cols, xlat, xlong)
display_analysis_page()
elif selected_page == "Data":
display_download_page()
if __name__ == "__main__":
main()