-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.py
executable file
·149 lines (111 loc) · 5.6 KB
/
dashboard.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
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
#import libraries
import streamlit as st
import pandas as pd
import numpy as np
import requests
from sklearn.ensemble import RandomForestClassifier
import json
import datetime
from datetime import timedelta
import streamlit as st
from pymongo import MongoClient, errors
from PIL import Image
import requests
from io import BytesIO
def user_input_features():
option = st.sidebar.selectbox(
'What would you like to see?', ('Results', 'About us'))
date_ = st.sidebar.date_input("For which date you want to see the results", datetime.date.today() - timedelta(days=12), min_value = datetime.date(2021,1,1), max_value = datetime.date.today() - timedelta(days=12))
return date_, option
# Initialize connection.
# Uses st.experimental_singleton to only run once.
@st.experimental_singleton
def init_connection():
client = MongoClient('mongodb://root:example@mongodb:27017/')
return client
@st.experimental_memo(ttl=600)
def get_data(date_):
cygnss = client.cygnss
from_date = date_
criteria = {"event_date": {"$eq": from_date}}
items = cygnss.cygnss_collection.find(criteria)
items = list(items) # make hashable for st.experimental_memo
return items
date_, option = user_input_features()
# Pull data from the collection.
# Uses st.experimental_memo to only rerun when the query changes or after 10 min.
# Initializing connection
client = init_connection()
date_ = date_.strftime("%Y-%m-%d")
# drop database if exists, just to not clutter it with multiple values of data
# client.drop_database('cygnss')
items = get_data(date_)
if option == 'About us':
st.write("""
# About US""")
st.write("The objective of this website is to use a pre-trained CyGNSSnet \
to predict global ocean wind speed in near time. The results are shown on a web interface, \
which provides different illustrations of the predicted wind speed and its error compared to ERA5 windspeed data.\
CyGNSSnet is a neural net developed to predict wind speed from CYGNSS(Cyclone Global Navigation Satellite System) data.\
The code for CyGNSSnet itself is not public. For more information or if you need to access it contact Caroline Arnold (arnold@dkrz.de)\
or the Helmholtz AI consultant team for Earth and Environment (consultant-helmholtz.ai@dkrz.de). For more information on CyGNSSnet,\
see Asgarimehr et al, Remote Sensing of Environment (2022)")
if option == 'Results':
# Display results.
if len(items) == 0:
st.write(f" Data does not exist for this date. Choose a different date please!")
else:
# Creating UI
# st.subheader('User Input parameters')
st.write("""
# Results """)
# app heading
st.write("""
# Ocean Wind Speed""")
st.write('Date:', date_)
y_bins = ["up to 4m/s", "up to 8m/s", "up to 12m/s",
"up to 16m/s", "up to 20m/s", "up to 100m/s"]
for item in items: # @harsh can this be more than 1 item?
st.write(f"Total RMSE is: {item['rmse']:.3f} m/s ")
d = {'Windspeed': y_bins, 'RMSE': item['bin_rmse'], 'Bias': item['bin_bias'],
'Counts': [int(i) for i in item['bin_counts']]}
df = pd.DataFrame(data=d)
# hide first column (index) of the table
hide_table_row_index = """
<style>
thead tr th:first-child {display:none}
tbody th {display:none}
</style>
"""
st.markdown(hide_table_row_index, unsafe_allow_html=True)
st.table(data=df)
for item in items:
#response = requests.get(item['image_url'])
# Image.open(BytesIO(response.content))
scatter = Image.open(item['scatterplot_path'])
st.markdown(f"## Scatterplot: ERA5 wind speed - model prediction")
st.image(scatter, caption="Scatterplot")
histo = Image.open(item['histogram_path'])
st.markdown(f"## Histogram: ERA5 wind speed and predicted wind speed")
st.image(histo, caption="Histogram")
#era_avg = Image.open(item['era_average_path'])
# st.markdown(f"## ERA 5 Average")
#st.image(era_avg, caption="ERA5 average")
#rmse_avg = Image.open(item['rmse_average_path'])
# st.markdown(f"## RMSE Average")
#st.image(rmse_avg, caption="RMSE average")
today_longavg = Image.open(item['today_longrunavg_path'])
st.markdown(f"## RMSE - Today and Longrun Average")
st.image(today_longavg, caption="RMSE - Today and Longrun Average")
today_long_bias = Image.open(item['today_long_bias_path'])
st.markdown(f"## BIAS - Today and Longrun Average")
st.image(today_long_bias, caption="Bias - Today and Longrun Average")
sample_counts = Image.open(item['sample_counts_path'])
st.markdown(f"## Sample Counts")
st.image(sample_counts, caption="Sample Counts")
rmse_bins_era = Image.open(item['rmse_bins_era_path'])
st.markdown(f"## RMSE for different Windspeed Bins")
st.image(rmse_bins_era, caption="RMSE for different Windspeed Bins")
bias_bins_era = Image.open(item['bias_bins_era_path'])
st.markdown(f"## Bias for different Windspeed Bins")
st.image(bias_bins_era, caption="Bias for different Windspeed Bins")