-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlottingTools.py
More file actions
254 lines (231 loc) · 6.21 KB
/
Copy pathPlottingTools.py
File metadata and controls
254 lines (231 loc) · 6.21 KB
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
from itertools import cycle
import plotly.graph_objects as go
import pandas as pd
from plotly.subplots import make_subplots
COLORWAY = ['#f3cec9', '#e7a4b6', '#cd7eaf', '#a262a9', '#6f4d96', '#3d3b72', '#182844']
def extract_plotly(df):
traces = []
axes = []
n_cols = len(df.columns)
color_cycle = cycle(COLORWAY[:n_cols])
dash_styles = ['solid', 'dash', 'dot', 'dash', 'longdash', 'dashdot', 'longdashdot']
dash_cycle = cycle(dash_styles[:n_cols])
for column in df.columns:
_, _, equipment, parameter = column.split('-')
name = f'{equipment} {parameter}'
if name not in axes:
axes.append(name)
del dash_cycle
dash_cycle = cycle(dash_styles)
else:
pass
trace = go.Scattergl(
x=df.index,
y=df[column],
yaxis='y{}'.format(axes.index(name) + 1),
name=f'{equipment} {parameter}',
mode='lines+markers',
line=dict(
dash=next(dash_cycle),
color=next(color_cycle)
),
marker=dict(
opacity=0,
),
)
traces.append(trace)
n_axes = len(axes)
layout_axes = []
ax_pos = 0
for i in range(len(df.columns)):
color = next(color_cycle),
ax_pos = i * 0.075
layout_axes.append({
'yaxis{}'.format(i + 1): dict(
title=axes[i],
titlefont=dict(
color=color
),
tickfont=dict(
color=color
),
anchor='free',
side='left',
position=ax_pos
)
})
layout = {
'title': 'Data to extract',
'xaxis': {
'domain': [0.075 * (n_axes - 1), 1],
'title': 'Date and time'
},
'paper_bgcolor': 'rgba(0,0,0,0)',
'plot_bgcolor': 'rgba(0,0,0,0)'
}
for ax in layout_axes:
layout = {**layout, **ax}
figure = go.Figure(data=traces, layout=layout)
return figure
def avn_plot(df):
df = df.groupby(pd.Grouper(freq='600S')).first()
# df = df[df['pilEAUte-Pilote effluent-Varion_002-NH4_N'].notnull()]
fig = go.Figure()
# NH4
trace_nh4 = go.Scattergl(
x=df.index,
y=df['pilEAUte-Pilote effluent-Varion_002-NH4_N'] * 1000,
name='Ammonia',
mode='lines',
yaxis='y',
line=dict(
dash='solid',
color='blue'
),
)
fig.add_trace(trace_nh4)
# NO3
trace_no3 = go.Scattergl(
x=df.index,
y=df['pilEAUte-Pilote effluent-Varion_002-NO3_N'] * 1000,
name='Nitrate',
mode='lines',
yaxis='y',
line=dict(
dash='solid',
color='turquoise'
),
)
fig.add_trace(trace_no3)
# AvN
trace_avn = go.Scattergl(
x=df.index,
y=df['pilEAUte-Pilote effluent-Varion_002-NH4_N']
/ df['pilEAUte-Pilote effluent-Varion_002-NO3_N'],
name='AvN ratio',
yaxis='y2',
mode='lines+markers',
line=dict(
dash='solid',
color='orange'
),
marker={
'opacity': 0
}
)
fig.add_trace(trace_avn)
# layout
layout_axes = []
name_axes = ['y1', 'y2']
title_axes = ['Nitrogen (mg/l)', 'AvN ratio']
n_axes = len(name_axes)
for i in range(len(name_axes)):
ax_pos = i * 0.075
layout_axes.append({
'title': title_axes[i],
'anchor': 'free',
'side': 'left',
'position': ax_pos
})
fig.update_layout(
xaxis={
'domain': [0.075 * (n_axes - 1), 1],
'title': 'Date and time'
},
yaxis=layout_axes[0],
yaxis2=layout_axes[1],
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)'
)
return fig
def airflow_plot(df):
df = df.rolling('300s').mean()
fig = go.Figure()
trace = go.Scattergl(
x=df.index,
y=df['pilEAUte-Pilote reactor 5-FIT_430-Flowrate (Gas)'],
name='Aeration',
mode='lines',
line=dict(
dash='solid',
color='red'
),
)
fig.add_trace(trace)
fig.update_layout(
xaxis={
'title': 'Date and time'
},
yaxis={
'title': 'Flow rate (L/h)',
},
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
)
return fig
def threefigs(df):
fig = make_subplots(
rows=3, cols=1,
specs=[[{'secondary_y': True}], [{}], [{}]],
shared_xaxes=True,
)
# Top
# NH4
trace_nh4 = go.Scattergl(
x=df.index,
y=df['pilEAUte-Pilote effluent-Varion_002-NH4_N'] * 1000,
name='Ammonia',
mode='lines',
line=dict(
dash='solid',
color='blue'
),
)
fig.add_trace(trace_nh4, row=1, col=1, secondary_y=False)
# NO3
trace_no3 = go.Scattergl(
x=df.index,
y=df['pilEAUte-Pilote effluent-Varion_002-NO3_N'] * 1000,
name='Nitrate',
mode='lines',
line=dict(
dash='solid',
color='turquoise'
)
)
fig.add_trace(trace_no3, row=1, col=1, secondary_y=False)
# AvN
trace_avn = go.Scattergl(
x=df.index,
y=df['pilEAUte-Pilote effluent-Varion_002-NH4_N']
/ df['pilEAUte-Pilote effluent-Varion_002-NO3_N'],
name='AvN ratio',
mode='lines+markers',
line=dict(
dash='solid',
color='orange'
),
marker={
'opacity': 0
}
)
fig.add_trace(trace_avn, row=1, col=1, secondary_y=True)
# Middle
df_mid = df.sort_index().rolling('300s').mean()
flow_trace = go.Scattergl(
x=df_mid.index,
y=df_mid['pilEAUte-Pilote reactor 5-FIT_430-Flowrate (Gas)'] * 1000 * 60,
name='Aeration flow',
mode='lines',
line=dict(
dash='solid',
color='red'
),
)
fig.add_trace(flow_trace, row=2, col=1)
fig.add_trace(flow_trace, row=3, col=1)
# layout
layout = dict(
title=''
)
return fig