RoyAalekh commited on
Commit
375516b
·
verified ·
1 Parent(s): 5f40a6b

Update plotting.py

Browse files
Files changed (1) hide show
  1. plotting.py +430 -427
plotting.py CHANGED
@@ -1,427 +1,430 @@
1
- import panel as pn
2
- import plotly.graph_objs as go
3
- import plotly.express as px
4
- from plotly.subplots import make_subplots
5
-
6
- from consts import (
7
- INVERTER_ID_MAPPING,
8
- CURRENT,
9
- IRRADIANCE,
10
- VOLTAGE,
11
- POWER_DC,
12
- POWER_AC,
13
- T_AMBIENT,
14
- T_MODULE,
15
- T_HEATSINK,
16
- T_CPU,
17
- T_BOARD,
18
- )
19
-
20
-
21
- def create_iv_plot(df, inverter_ids):
22
- """# Helper function to create a line plot with secondary y-axis"""
23
-
24
- print("Selected Inverter Ids: {}".format(inverter_ids))
25
- fig = make_subplots(
26
- rows=2,
27
- cols=1,
28
- shared_xaxes=True,
29
- vertical_spacing=0.01,
30
- specs=[[{"secondary_y": True}], [{}]],
31
- )
32
-
33
- for inverter in inverter_ids:
34
- inv_id = INVERTER_ID_MAPPING[inverter]
35
- print("Creating plot for inv_id: {}".format(inv_id))
36
- inv_data = df[str(inv_id)]
37
-
38
- # Graph 1: DC current and G-POA (Twin Y-Axis)
39
- fig.add_trace(
40
- go.Scatter(
41
- x=inv_data.index,
42
- y=inv_data[CURRENT],
43
- mode="lines",
44
- name=f"{CURRENT}-{inv_id}",
45
- ),
46
- row=1,
47
- col=1,
48
- secondary_y=False,
49
- )
50
-
51
- fig.add_trace(
52
- go.Scatter(
53
- x=inv_data.index,
54
- y=inv_data[IRRADIANCE],
55
- mode="lines",
56
- name=f"{IRRADIANCE}-{inv_id}",
57
- ),
58
- row=1,
59
- col=1,
60
- secondary_y=True,
61
- )
62
-
63
- # Graph 2: Voltage
64
- fig.add_trace(
65
- go.Scatter(
66
- x=inv_data.index,
67
- y=inv_data[VOLTAGE],
68
- mode="lines",
69
- name=f"{VOLTAGE}-{inv_id}",
70
- ),
71
- row=2,
72
- col=1,
73
- )
74
- # Update axis labels
75
- fig.update_yaxes(title_text="Current (A)", row=1, col=1)
76
- fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True)
77
- fig.update_yaxes(title_text="Voltage (V)", row=2, col=1)
78
- fig.update_xaxes(title_text="Datetime", row=2, col=1)
79
-
80
- # Update layout to add titles and adjust axis labels
81
- fig.update_layout(title_text="IV Plots", height=800, width=1000)
82
-
83
- return fig
84
-
85
-
86
- def create_iv_plot_with_power_curves(df, inverter_ids):
87
- """# Helper function to create a line plot with secondary y-axis"""
88
-
89
- print("Selected Inverter Ids: {}".format(inverter_ids))
90
- fig = make_subplots(
91
- rows=3,
92
- cols=1,
93
- shared_xaxes=True,
94
- vertical_spacing=0.01,
95
- specs=[[{"secondary_y": True}], [{}], [{}]],
96
- )
97
-
98
- for inverter in inverter_ids:
99
- inv_id = INVERTER_ID_MAPPING[inverter]
100
- print("Creating plot for inv_id: {}".format(inv_id))
101
- inv_data = df[str(inv_id)]
102
-
103
- # Graph 1: DC current and G-POA (Twin Y-Axis)
104
- fig.add_trace(
105
- go.Scatter(
106
- x=inv_data.index,
107
- y=inv_data[CURRENT],
108
- mode="lines",
109
- name=f"{CURRENT}-{inv_id}",
110
- ),
111
- row=1,
112
- col=1,
113
- secondary_y=False,
114
- )
115
-
116
- fig.add_trace(
117
- go.Scatter(
118
- x=inv_data.index,
119
- y=inv_data[IRRADIANCE],
120
- mode="lines",
121
- name=f"{IRRADIANCE}-{inv_id}",
122
- ),
123
- row=1,
124
- col=1,
125
- secondary_y=True,
126
- )
127
-
128
- # Graph 2: Voltage
129
- fig.add_trace(
130
- go.Scatter(
131
- x=inv_data.index,
132
- y=inv_data[VOLTAGE],
133
- mode="lines",
134
- name=f"{VOLTAGE}-{inv_id}",
135
- ),
136
- row=2,
137
- col=1,
138
- )
139
-
140
- # Graph 3: P-dc and P-ac
141
- fig.add_trace(
142
- go.Scatter(
143
- x=inv_data.index,
144
- y=inv_data[POWER_DC],
145
- mode="lines",
146
- name=f"{POWER_DC}-{inv_id}",
147
- ),
148
- row=3,
149
- col=1,
150
- )
151
- fig.add_trace(
152
- go.Scatter(
153
- x=inv_data.index,
154
- y=inv_data[POWER_AC],
155
- mode="lines",
156
- name=f"{POWER_AC}-{inv_id}",
157
- ),
158
- row=3,
159
- col=1,
160
- )
161
-
162
- # Update axis labels
163
- fig.update_yaxes(title_text="Current (A)", row=1, col=1)
164
- fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True)
165
- fig.update_yaxes(title_text="Voltage (V)", row=2, col=1)
166
- fig.update_yaxes(title_text="P-dc & P-ac (W)", row=3, col=1)
167
- fig.update_xaxes(title_text="Datetime", row=3, col=1)
168
-
169
- # Update layout to add titles
170
- fig.update_layout(title_text="IV Plot with Power Curves", height=800, width=1000)
171
-
172
- return fig
173
-
174
-
175
- def create_iv_plot_with_power_and_temperature_curves(df, df2, inverter_ids):
176
- # Create the specs for subplots
177
- print("Selected Inverter Ids: {}".format(inverter_ids))
178
- fig = make_subplots(
179
- rows=4,
180
- cols=1,
181
- shared_xaxes=True,
182
- vertical_spacing=0.01,
183
- specs=[[{"secondary_y": True}], [{}], [{}], [{}]],
184
- )
185
-
186
- for inverter in inverter_ids:
187
- inv_id = INVERTER_ID_MAPPING[inverter]
188
- print("Creating plot for inv_id: {}".format(inv_id))
189
- inv_data = df[str(inv_id)]
190
- temperature_data = df2[df2["Inv"] == inv_id]
191
-
192
- # Graph 1: DC current and G-POA (Twin Y-Axis)
193
- fig.add_trace(
194
- go.Scatter(
195
- x=inv_data.index,
196
- y=inv_data[CURRENT],
197
- mode="lines",
198
- name=f"{CURRENT}-{inv_id}",
199
- ),
200
- row=1,
201
- col=1,
202
- secondary_y=False,
203
- )
204
-
205
- fig.add_trace(
206
- go.Scatter(
207
- x=inv_data.index,
208
- y=inv_data[IRRADIANCE],
209
- mode="lines",
210
- name=f"{IRRADIANCE}-{inv_id}",
211
- ),
212
- row=1,
213
- col=1,
214
- secondary_y=True,
215
- )
216
-
217
- # Graph 2: Voltage
218
- fig.add_trace(
219
- go.Scatter(
220
- x=inv_data.index,
221
- y=inv_data[VOLTAGE],
222
- mode="lines",
223
- name=f"{VOLTAGE}-{inv_id}",
224
- ),
225
- row=2,
226
- col=1,
227
- )
228
-
229
- # Graph 3: P-dc and P-ac
230
- fig.add_trace(
231
- go.Scatter(
232
- x=inv_data.index,
233
- y=inv_data[POWER_DC],
234
- mode="lines",
235
- name=f"{POWER_DC}-{inv_id}",
236
- ),
237
- row=3,
238
- col=1,
239
- )
240
- fig.add_trace(
241
- go.Scatter(
242
- x=inv_data.index,
243
- y=inv_data[POWER_AC],
244
- mode="lines",
245
- name=f"{POWER_AC}-{inv_id}",
246
- ),
247
- row=3,
248
- col=1,
249
- )
250
-
251
- # Graph 4: T-amb, T-mod, T-heatsink, T-CPU and T-board
252
- fig.add_trace(
253
- go.Scatter(
254
- x=temperature_data.index,
255
- y=temperature_data[T_AMBIENT],
256
- name=f"{T_AMBIENT}-{inv_id}",
257
- ),
258
- row=4,
259
- col=1,
260
- )
261
- fig.add_trace(
262
- go.Scatter(
263
- x=inv_data.index, y=inv_data[T_MODULE], name=f"{T_MODULE}-{inv_id}"
264
- ),
265
- row=4,
266
- col=1,
267
- )
268
- fig.add_trace(
269
- go.Scatter(
270
- x=temperature_data.index,
271
- y=temperature_data[T_HEATSINK],
272
- name=f"{T_HEATSINK}-{inv_id}",
273
- ),
274
- row=4,
275
- col=1,
276
- )
277
- fig.add_trace(
278
- go.Scatter(
279
- x=temperature_data.index,
280
- y=temperature_data[T_CPU],
281
- name=f"{T_CPU}-{inv_id}",
282
- ),
283
- row=4,
284
- col=1,
285
- )
286
- fig.add_trace(
287
- go.Scatter(
288
- x=temperature_data.index,
289
- y=temperature_data[T_BOARD],
290
- name=f"{T_BOARD}-{inv_id}",
291
- ),
292
- row=4,
293
- col=1,
294
- )
295
-
296
- # Update axis labels
297
- fig.update_yaxes(title_text="Current (A)", row=1, col=1)
298
- fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True)
299
- fig.update_yaxes(title_text="Voltage (V)", row=2, col=1)
300
- fig.update_yaxes(title_text="P-dc & P-ac (W)", row=3, col=1)
301
- fig.update_xaxes(title_text="Datetime", row=4, col=1)
302
- fig.update_yaxes(title_text="Temperature (°C)", row=4, col=1)
303
-
304
- # Update layout to add titles
305
- fig.update_layout(
306
- title_text="IV Plots with Power and Temperature", height=800, width=1000
307
- )
308
-
309
- return pn.pane.Plotly(fig)
310
-
311
-
312
- def create_iv_plot_with_temperature_curves(df, df2, inverter_ids):
313
- # Create the specs for subplots
314
- print("Selected Inverter Ids: {}".format(inverter_ids))
315
- fig = make_subplots(
316
- rows=3,
317
- cols=1,
318
- shared_xaxes=True,
319
- vertical_spacing=0.01,
320
- specs=[[{"secondary_y": True}], [{}], [{}]],
321
- )
322
-
323
- for inverter in inverter_ids:
324
- inv_id = INVERTER_ID_MAPPING[inverter]
325
- print("Creating plot for inv_id: {}".format(inv_id))
326
- inv_data = df[str(inv_id)]
327
- temperature_data = df2[df2["Inv"] == inv_id]
328
-
329
- # Graph 1: DC current and G-POA (Twin Y-Axis)
330
- fig.add_trace(
331
- go.Scatter(
332
- x=inv_data.index,
333
- y=inv_data[CURRENT],
334
- mode="lines",
335
- name=f"{CURRENT}-{inv_id}",
336
- ),
337
- row=1,
338
- col=1,
339
- secondary_y=False,
340
- )
341
-
342
- fig.add_trace(
343
- go.Scatter(
344
- x=inv_data.index,
345
- y=inv_data[IRRADIANCE],
346
- mode="lines",
347
- name=f"{IRRADIANCE}-{inv_id}",
348
- ),
349
- row=1,
350
- col=1,
351
- secondary_y=True,
352
- )
353
-
354
- # Graph 2: Voltage
355
- fig.add_trace(
356
- go.Scatter(
357
- x=inv_data.index,
358
- y=inv_data[VOLTAGE],
359
- mode="lines",
360
- name=f"{VOLTAGE}-{inv_id}",
361
- ),
362
- row=2,
363
- col=1,
364
- )
365
-
366
- # Graph 4: T-amb, T-mod, T-heatsink, T-CPU and T-board
367
- fig.add_trace(
368
- go.Scatter(
369
- x=temperature_data.index,
370
- y=temperature_data[T_AMBIENT],
371
- name=f"{T_AMBIENT}-{inv_id}",
372
- ),
373
- row=3,
374
- col=1,
375
- )
376
- fig.add_trace(
377
- go.Scatter(
378
- x=inv_data.index, y=inv_data[T_MODULE], name=f"{T_MODULE}-{inv_id}"
379
- ),
380
- row=3,
381
- col=1,
382
- )
383
- fig.add_trace(
384
- go.Scatter(
385
- x=temperature_data.index,
386
- y=temperature_data[T_HEATSINK],
387
- name=f"{T_HEATSINK}-{inv_id}",
388
- ),
389
- row=3,
390
- col=1,
391
- )
392
- fig.add_trace(
393
- go.Scatter(
394
- x=temperature_data.index,
395
- y=temperature_data[T_CPU],
396
- name=f"{T_CPU}-{inv_id}",
397
- ),
398
- row=3,
399
- col=1,
400
- )
401
- fig.add_trace(
402
- go.Scatter(
403
- x=temperature_data.index,
404
- y=temperature_data[T_BOARD],
405
- name=f"{T_BOARD}-{inv_id}",
406
- ),
407
- row=3,
408
- col=1,
409
- )
410
-
411
- # Update axis labels
412
- fig.update_yaxes(title_text="Current (A)", row=1, col=1)
413
- fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True)
414
- fig.update_yaxes(title_text="Voltage (V)", row=2, col=1)
415
- fig.update_xaxes(title_text="Datetime", row=3, col=1)
416
- fig.update_yaxes(title_text="Temperature (°C)", row=3, col=1)
417
-
418
- # Update layout to add titles
419
- fig.update_layout(title_text="IV Plots with Temperature", height=800, width=1000)
420
-
421
- return pn.pane.Plotly(fig)
422
-
423
-
424
- def create_heatmap(df, title):
425
- fig = px.imshow(df.transpose(), aspect="auto", title=title)
426
- fig.update_layout(height=400, width=1200)
427
- return pn.pane.Plotly(fig)
 
 
 
 
1
+ import panel as pn
2
+ import plotly.graph_objs as go
3
+ import plotly.express as px
4
+ from plotly.subplots import make_subplots
5
+
6
+ from consts import (
7
+ INVERTER_ID_MAPPING,
8
+ CURRENT,
9
+ IRRADIANCE,
10
+ VOLTAGE,
11
+ POWER_DC,
12
+ POWER_AC,
13
+ T_AMBIENT,
14
+ T_MODULE,
15
+ T_HEATSINK,
16
+ T_CPU,
17
+ T_BOARD,
18
+ )
19
+
20
+
21
+ def create_iv_plot(df, inverter_ids):
22
+ """# Helper function to create a line plot with secondary y-axis"""
23
+
24
+ print("Selected Inverter Ids: {}".format(inverter_ids))
25
+ fig = make_subplots(
26
+ rows=2,
27
+ cols=1,
28
+ shared_xaxes=True,
29
+ vertical_spacing=0.01,
30
+ specs=[[{"secondary_y": True}], [{}]],
31
+ )
32
+
33
+ for inverter in inverter_ids:
34
+ inv_id = INVERTER_ID_MAPPING[inverter]
35
+ print("Creating plot for inv_id: {}".format(inv_id))
36
+ inv_data = df[str(inv_id)]
37
+ print(inv_data.head())
38
+ print(inv_data.columns)
39
+ print(f"df columns {df.columns}")
40
+
41
+ # Graph 1: DC current and G-POA (Twin Y-Axis)
42
+ fig.add_trace(
43
+ go.Scatter(
44
+ x=inv_data.index,
45
+ y=inv_data[CURRENT],
46
+ mode="lines",
47
+ name=f"{CURRENT}-{inv_id}",
48
+ ),
49
+ row=1,
50
+ col=1,
51
+ secondary_y=False,
52
+ )
53
+
54
+ fig.add_trace(
55
+ go.Scatter(
56
+ x=inv_data.index,
57
+ y=inv_data[IRRADIANCE],
58
+ mode="lines",
59
+ name=f"{IRRADIANCE}-{inv_id}",
60
+ ),
61
+ row=1,
62
+ col=1,
63
+ secondary_y=True,
64
+ )
65
+
66
+ # Graph 2: Voltage
67
+ fig.add_trace(
68
+ go.Scatter(
69
+ x=inv_data.index,
70
+ y=inv_data[VOLTAGE],
71
+ mode="lines",
72
+ name=f"{VOLTAGE}-{inv_id}",
73
+ ),
74
+ row=2,
75
+ col=1,
76
+ )
77
+ # Update axis labels
78
+ fig.update_yaxes(title_text="Current (A)", row=1, col=1)
79
+ fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True)
80
+ fig.update_yaxes(title_text="Voltage (V)", row=2, col=1)
81
+ fig.update_xaxes(title_text="Datetime", row=2, col=1)
82
+
83
+ # Update layout to add titles and adjust axis labels
84
+ fig.update_layout(title_text="IV Plots", height=800, width=1000)
85
+
86
+ return fig
87
+
88
+
89
+ def create_iv_plot_with_power_curves(df, inverter_ids):
90
+ """# Helper function to create a line plot with secondary y-axis"""
91
+
92
+ print("Selected Inverter Ids: {}".format(inverter_ids))
93
+ fig = make_subplots(
94
+ rows=3,
95
+ cols=1,
96
+ shared_xaxes=True,
97
+ vertical_spacing=0.01,
98
+ specs=[[{"secondary_y": True}], [{}], [{}]],
99
+ )
100
+
101
+ for inverter in inverter_ids:
102
+ inv_id = INVERTER_ID_MAPPING[inverter]
103
+ print("Creating plot for inv_id: {}".format(inv_id))
104
+ inv_data = df[str(inv_id)]
105
+
106
+ # Graph 1: DC current and G-POA (Twin Y-Axis)
107
+ fig.add_trace(
108
+ go.Scatter(
109
+ x=inv_data.index,
110
+ y=inv_data[CURRENT],
111
+ mode="lines",
112
+ name=f"{CURRENT}-{inv_id}",
113
+ ),
114
+ row=1,
115
+ col=1,
116
+ secondary_y=False,
117
+ )
118
+
119
+ fig.add_trace(
120
+ go.Scatter(
121
+ x=inv_data.index,
122
+ y=inv_data[IRRADIANCE],
123
+ mode="lines",
124
+ name=f"{IRRADIANCE}-{inv_id}",
125
+ ),
126
+ row=1,
127
+ col=1,
128
+ secondary_y=True,
129
+ )
130
+
131
+ # Graph 2: Voltage
132
+ fig.add_trace(
133
+ go.Scatter(
134
+ x=inv_data.index,
135
+ y=inv_data[VOLTAGE],
136
+ mode="lines",
137
+ name=f"{VOLTAGE}-{inv_id}",
138
+ ),
139
+ row=2,
140
+ col=1,
141
+ )
142
+
143
+ # Graph 3: P-dc and P-ac
144
+ fig.add_trace(
145
+ go.Scatter(
146
+ x=inv_data.index,
147
+ y=inv_data[POWER_DC],
148
+ mode="lines",
149
+ name=f"{POWER_DC}-{inv_id}",
150
+ ),
151
+ row=3,
152
+ col=1,
153
+ )
154
+ fig.add_trace(
155
+ go.Scatter(
156
+ x=inv_data.index,
157
+ y=inv_data[POWER_AC],
158
+ mode="lines",
159
+ name=f"{POWER_AC}-{inv_id}",
160
+ ),
161
+ row=3,
162
+ col=1,
163
+ )
164
+
165
+ # Update axis labels
166
+ fig.update_yaxes(title_text="Current (A)", row=1, col=1)
167
+ fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True)
168
+ fig.update_yaxes(title_text="Voltage (V)", row=2, col=1)
169
+ fig.update_yaxes(title_text="P-dc & P-ac (W)", row=3, col=1)
170
+ fig.update_xaxes(title_text="Datetime", row=3, col=1)
171
+
172
+ # Update layout to add titles
173
+ fig.update_layout(title_text="IV Plot with Power Curves", height=800, width=1000)
174
+
175
+ return fig
176
+
177
+
178
+ def create_iv_plot_with_power_and_temperature_curves(df, df2, inverter_ids):
179
+ # Create the specs for subplots
180
+ print("Selected Inverter Ids: {}".format(inverter_ids))
181
+ fig = make_subplots(
182
+ rows=4,
183
+ cols=1,
184
+ shared_xaxes=True,
185
+ vertical_spacing=0.01,
186
+ specs=[[{"secondary_y": True}], [{}], [{}], [{}]],
187
+ )
188
+
189
+ for inverter in inverter_ids:
190
+ inv_id = INVERTER_ID_MAPPING[inverter]
191
+ print("Creating plot for inv_id: {}".format(inv_id))
192
+ inv_data = df[str(inv_id)]
193
+ temperature_data = df2[df2["Inv"] == inv_id]
194
+
195
+ # Graph 1: DC current and G-POA (Twin Y-Axis)
196
+ fig.add_trace(
197
+ go.Scatter(
198
+ x=inv_data.index,
199
+ y=inv_data[CURRENT],
200
+ mode="lines",
201
+ name=f"{CURRENT}-{inv_id}",
202
+ ),
203
+ row=1,
204
+ col=1,
205
+ secondary_y=False,
206
+ )
207
+
208
+ fig.add_trace(
209
+ go.Scatter(
210
+ x=inv_data.index,
211
+ y=inv_data[IRRADIANCE],
212
+ mode="lines",
213
+ name=f"{IRRADIANCE}-{inv_id}",
214
+ ),
215
+ row=1,
216
+ col=1,
217
+ secondary_y=True,
218
+ )
219
+
220
+ # Graph 2: Voltage
221
+ fig.add_trace(
222
+ go.Scatter(
223
+ x=inv_data.index,
224
+ y=inv_data[VOLTAGE],
225
+ mode="lines",
226
+ name=f"{VOLTAGE}-{inv_id}",
227
+ ),
228
+ row=2,
229
+ col=1,
230
+ )
231
+
232
+ # Graph 3: P-dc and P-ac
233
+ fig.add_trace(
234
+ go.Scatter(
235
+ x=inv_data.index,
236
+ y=inv_data[POWER_DC],
237
+ mode="lines",
238
+ name=f"{POWER_DC}-{inv_id}",
239
+ ),
240
+ row=3,
241
+ col=1,
242
+ )
243
+ fig.add_trace(
244
+ go.Scatter(
245
+ x=inv_data.index,
246
+ y=inv_data[POWER_AC],
247
+ mode="lines",
248
+ name=f"{POWER_AC}-{inv_id}",
249
+ ),
250
+ row=3,
251
+ col=1,
252
+ )
253
+
254
+ # Graph 4: T-amb, T-mod, T-heatsink, T-CPU and T-board
255
+ fig.add_trace(
256
+ go.Scatter(
257
+ x=temperature_data.index,
258
+ y=temperature_data[T_AMBIENT],
259
+ name=f"{T_AMBIENT}-{inv_id}",
260
+ ),
261
+ row=4,
262
+ col=1,
263
+ )
264
+ fig.add_trace(
265
+ go.Scatter(
266
+ x=inv_data.index, y=inv_data[T_MODULE], name=f"{T_MODULE}-{inv_id}"
267
+ ),
268
+ row=4,
269
+ col=1,
270
+ )
271
+ fig.add_trace(
272
+ go.Scatter(
273
+ x=temperature_data.index,
274
+ y=temperature_data[T_HEATSINK],
275
+ name=f"{T_HEATSINK}-{inv_id}",
276
+ ),
277
+ row=4,
278
+ col=1,
279
+ )
280
+ fig.add_trace(
281
+ go.Scatter(
282
+ x=temperature_data.index,
283
+ y=temperature_data[T_CPU],
284
+ name=f"{T_CPU}-{inv_id}",
285
+ ),
286
+ row=4,
287
+ col=1,
288
+ )
289
+ fig.add_trace(
290
+ go.Scatter(
291
+ x=temperature_data.index,
292
+ y=temperature_data[T_BOARD],
293
+ name=f"{T_BOARD}-{inv_id}",
294
+ ),
295
+ row=4,
296
+ col=1,
297
+ )
298
+
299
+ # Update axis labels
300
+ fig.update_yaxes(title_text="Current (A)", row=1, col=1)
301
+ fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True)
302
+ fig.update_yaxes(title_text="Voltage (V)", row=2, col=1)
303
+ fig.update_yaxes(title_text="P-dc & P-ac (W)", row=3, col=1)
304
+ fig.update_xaxes(title_text="Datetime", row=4, col=1)
305
+ fig.update_yaxes(title_text="Temperature (°C)", row=4, col=1)
306
+
307
+ # Update layout to add titles
308
+ fig.update_layout(
309
+ title_text="IV Plots with Power and Temperature", height=800, width=1000
310
+ )
311
+
312
+ return pn.pane.Plotly(fig)
313
+
314
+
315
+ def create_iv_plot_with_temperature_curves(df, df2, inverter_ids):
316
+ # Create the specs for subplots
317
+ print("Selected Inverter Ids: {}".format(inverter_ids))
318
+ fig = make_subplots(
319
+ rows=3,
320
+ cols=1,
321
+ shared_xaxes=True,
322
+ vertical_spacing=0.01,
323
+ specs=[[{"secondary_y": True}], [{}], [{}]],
324
+ )
325
+
326
+ for inverter in inverter_ids:
327
+ inv_id = INVERTER_ID_MAPPING[inverter]
328
+ print("Creating plot for inv_id: {}".format(inv_id))
329
+ inv_data = df[str(inv_id)]
330
+ temperature_data = df2[df2["Inv"] == inv_id]
331
+
332
+ # Graph 1: DC current and G-POA (Twin Y-Axis)
333
+ fig.add_trace(
334
+ go.Scatter(
335
+ x=inv_data.index,
336
+ y=inv_data[CURRENT],
337
+ mode="lines",
338
+ name=f"{CURRENT}-{inv_id}",
339
+ ),
340
+ row=1,
341
+ col=1,
342
+ secondary_y=False,
343
+ )
344
+
345
+ fig.add_trace(
346
+ go.Scatter(
347
+ x=inv_data.index,
348
+ y=inv_data[IRRADIANCE],
349
+ mode="lines",
350
+ name=f"{IRRADIANCE}-{inv_id}",
351
+ ),
352
+ row=1,
353
+ col=1,
354
+ secondary_y=True,
355
+ )
356
+
357
+ # Graph 2: Voltage
358
+ fig.add_trace(
359
+ go.Scatter(
360
+ x=inv_data.index,
361
+ y=inv_data[VOLTAGE],
362
+ mode="lines",
363
+ name=f"{VOLTAGE}-{inv_id}",
364
+ ),
365
+ row=2,
366
+ col=1,
367
+ )
368
+
369
+ # Graph 4: T-amb, T-mod, T-heatsink, T-CPU and T-board
370
+ fig.add_trace(
371
+ go.Scatter(
372
+ x=temperature_data.index,
373
+ y=temperature_data[T_AMBIENT],
374
+ name=f"{T_AMBIENT}-{inv_id}",
375
+ ),
376
+ row=3,
377
+ col=1,
378
+ )
379
+ fig.add_trace(
380
+ go.Scatter(
381
+ x=inv_data.index, y=inv_data[T_MODULE], name=f"{T_MODULE}-{inv_id}"
382
+ ),
383
+ row=3,
384
+ col=1,
385
+ )
386
+ fig.add_trace(
387
+ go.Scatter(
388
+ x=temperature_data.index,
389
+ y=temperature_data[T_HEATSINK],
390
+ name=f"{T_HEATSINK}-{inv_id}",
391
+ ),
392
+ row=3,
393
+ col=1,
394
+ )
395
+ fig.add_trace(
396
+ go.Scatter(
397
+ x=temperature_data.index,
398
+ y=temperature_data[T_CPU],
399
+ name=f"{T_CPU}-{inv_id}",
400
+ ),
401
+ row=3,
402
+ col=1,
403
+ )
404
+ fig.add_trace(
405
+ go.Scatter(
406
+ x=temperature_data.index,
407
+ y=temperature_data[T_BOARD],
408
+ name=f"{T_BOARD}-{inv_id}",
409
+ ),
410
+ row=3,
411
+ col=1,
412
+ )
413
+
414
+ # Update axis labels
415
+ fig.update_yaxes(title_text="Current (A)", row=1, col=1)
416
+ fig.update_yaxes(title_text="Irradiance (W/m2)", row=1, col=1, secondary_y=True)
417
+ fig.update_yaxes(title_text="Voltage (V)", row=2, col=1)
418
+ fig.update_xaxes(title_text="Datetime", row=3, col=1)
419
+ fig.update_yaxes(title_text="Temperature (°C)", row=3, col=1)
420
+
421
+ # Update layout to add titles
422
+ fig.update_layout(title_text="IV Plots with Temperature", height=800, width=1000)
423
+
424
+ return pn.pane.Plotly(fig)
425
+
426
+
427
+ def create_heatmap(df, title):
428
+ fig = px.imshow(df.transpose(), aspect="auto", title=title)
429
+ fig.update_layout(height=400, width=1200)
430
+ return pn.pane.Plotly(fig)