-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSWAN_ML_data_viewer.py
182 lines (166 loc) · 5.26 KB
/
SWAN_ML_data_viewer.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
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
import numpy as np
import pandas as pd
import plotly.express as px
from dash import Dash, Input, Output, dcc, html
data_all = pd.read_csv("data_all_density.csv", sep=";", header=0)
dropdown_options = data_all["location_name"].unique().tolist()
dropdown_options.insert(0, "All locations")
def get_mask(df, low, high, location):
print(location)
if location == "All locations":
mask = (df["Hm0 SWAN"] > low) & (df["Hm0 SWAN"] < high)
else:
mask = (df["Hm0 SWAN"] > low) & (df["Hm0 SWAN"] < high) & (df["location_name"] == location)
return mask
app = Dash(__name__)
app.layout = html.Div(
[
html.Div(
[
dcc.Graph(id="scatter-plot-windspeed"),
],
style={"width": "40vw", "display": "inline-block", "margin-left": "10vw", "height": "35vh"},
),
html.Div(
[
dcc.Graph(id="radial-scatter-wind"),
],
style={"width": "40vw", "display": "inline-block", "height": "35vh"},
),
html.Div(
[
dcc.Graph(id="scatter-plot-waveperiod"),
],
style={
"width": "40vw",
"display": "inline-block",
"margin-left": "10vw",
"margin-top": "5vh",
"height": "35vh",
},
),
html.Div(
[
dcc.Graph(id="radial-scatter-waves"),
],
style={"width": "40vw", "display": "inline-block", "margin-top": "5vh", "height": "35vh"},
),
html.Div(
[
html.P("Filter by measured spectral wave height:"),
dcc.RangeSlider(
id="range-slider",
min=0,
max=6,
step=0.1,
marks={
0: "0.0",
0.5: "0.5",
1: "1.0",
1.5: "1.5",
2: "2.0",
2.5: "2.5",
3: "3.0",
3.5: "3.5",
4: "4.0",
4.5: "4.5",
5: "5.0",
5.5: "5.5",
6: "6.0",
},
value=[0.0, 6.0],
),
dcc.Dropdown(
dropdown_options,
"All locations",
id="selected_location",
),
],
style={
"width": "80vw",
"display": "inline-block",
"margin-top": "5vh",
"margin-left": "10vw",
"margin-right": "10vw",
},
),
]
)
@app.callback(
Output("scatter-plot-windspeed", "figure"),
Input("range-slider", "value"),
Input("selected_location", "value"),
)
def update_figure_windspeed(slider_range, location):
df = data_all
low, high = slider_range
mask = get_mask(df, low, high, location)
fig = px.scatter(
df[mask],
x="Wind speed SWAN",
y="Hm0 SWAN",
color="density_Hm0_Uwind",
color_continuous_scale=px.colors.sequential.Hot,
)
fig.update_xaxes(range=[0, np.ceil(df["Wind speed SWAN"].max())])
fig.update_yaxes(range=[0, np.ceil(df["Hm0 SWAN"].max())])
fig.update_layout(coloraxis_showscale=False)
return fig
@app.callback(
Output("radial-scatter-wind", "figure"),
Input("range-slider", "value"),
Input("selected_location", "value"),
)
def update_figure_radial_wind(slider_range, location):
df = data_all
low, high = slider_range
mask = get_mask(df, low, high, location)
fig = px.scatter_polar(
df[mask],
theta="Wind direction SWAN",
r="Hm0 SWAN",
color="density_Hm0_WindDir",
color_continuous_scale=px.colors.sequential.Hot,
range_r=[0, np.ceil(df["Hm0 SWAN"].max())],
)
fig.update_layout(coloraxis_showscale=False)
return fig
@app.callback(
Output("scatter-plot-waveperiod", "figure"),
Input("range-slider", "value"),
Input("selected_location", "value"),
)
def update_figure_waveperiod(slider_range, location):
df = data_all
low, high = slider_range
mask = get_mask(df, low, high, location)
fig = px.scatter(
df[mask],
x="Tm10 SWAN",
y="Hm0 SWAN",
color="density_Hm0_Tmm10",
color_continuous_scale=px.colors.sequential.Hot,
)
fig.update_xaxes(range=[0, np.ceil(df["Tm10 SWAN"].max())])
fig.update_yaxes(range=[0, np.ceil(df["Hm0 SWAN"].max())])
fig.update_layout(coloraxis_showscale=False)
return fig
@app.callback(
Output("radial-scatter-waves", "figure"),
Input("range-slider", "value"),
Input("selected_location", "value"),
)
def update_figure_radial_waves(slider_range, location):
df = data_all
low, high = slider_range
mask = get_mask(df, low, high, location)
fig = px.scatter_polar(
df[mask],
theta="Wdir SWAN",
r="Hm0 SWAN",
color="density_Hm0_WaveDir",
color_continuous_scale=px.colors.sequential.Hot,
range_r=[0, np.ceil(df["Hm0 SWAN"].max())],
)
fig.update_layout(coloraxis_showscale=False)
return fig