-
Notifications
You must be signed in to change notification settings - Fork 4
/
string_length_calculator_sandia.py
1476 lines (1335 loc) · 54.6 KB
/
string_length_calculator_sandia.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
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
This script builds a Dash web application for finding maximum module Voc.
Todd Karin
"""
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
# import dash_table
import plotly.colors
import plotly.graph_objs as go
# import plotly.plotly as py
# from flask_caching import Cache
from dash.dependencies import Input, Output, State
import vocmaxlib
import numpy as np
import pvlib
import nsrdbtools
import pandas as pd
# import uuid
# import os
# import flask
# import json
# import time
import datetime
import io
import pvtoolslib
import urllib
from app import app
# mapbox_access_token = 'pk.eyJ1IjoidG9kZGthcmluIiwiYSI6Ik1aSndibmcifQ.hwkbjcZevafx2ApulodXaw'
# app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
# session_id = str(uuid.uuid4())
layout = dbc.Container([
html.Hr(),
html.Div([
html.H1("Photovoltaic Maximum Open Circuit Voltage"),
], style={
# 'background-color': 'lightblue',
'width': '100%',
'padding-left': '10px',
'padding-right': '10px',
'textAlign': 'center'}),
html.Hr(),
# html.Div(str(uuid.uuid4()), id='session-id', style={'display': 'none'}),
html.Div(id='click-data', style={'display': 'none'}),
html.H2('Overview'),
# html.H1(
# children='Photovoltaic String Length Based on Historical Weather',
# style={
# 'textAlign': 'left'
# }
# ),
html.P("""The maximum open circuit voltage (Voc) is a key design
parameter for solar power plants. This application provides an
industry-standard method for calculating the maximum open circuit voltage
given weather data and module parameters. Weather data is sourced from the
national solar radiation database (NSRDB) [1]. The open circuit voltage
is calculated using the Sandia PV models [2] as implemented in the open
source python library PVLIB [3]. This work is funded by the Duramat
consortium [4].
"""),
html.P("""In order to download raw data, please use Firefox.
"""),
html.H2('Methods'),
html.P("""The national electric code 2017 lists three different methods
for determining the maximum string length in Article 690.7:
"""),
html.Ol([
html.Li("""690.7(A)(1) Instruction in listing or labeling of module:
The sum of the PV module-rated open-circuit voltage of the
series-connected modules corrected for the lowest expected ambient
temperature using the open-circuit voltage temperature coefficients
in accordance with the instructions included in the listing or
labeling of the module.
"""),
html.Li("""690.7(A)(2) Crystalline and multicrystalline modules: For
crystalline and multicrystalline silicon modules, the sum of the PV
module-rated open-circuit voltage of the series-connected modules
corrected for the lowest expected ambient temperature using the
correction factor provided in Table 690.7(A).
"""),
html.Li("""690.7(A)(3) PV systems of 100 kW or larger: For PV systems
with a generating capcity of 100 kW or greater, a documented and
stamped PV system design, using an industry standard method and
provided by a licensed professional electrical engineer, shall be
permitted.
""")
], style={'marginLeft': 50}),
html.P("""This tool provides information for methods 690.7(A)(1) and
690.7(A)(3). For method 690.7(A)(1), The lowest expected ambient
temperature is calculated by finding the minimum temperature during
daylight hours, defined as GHI>150 W/m^2.
"""),
html.P("""For method 690.7(A)(3), a full PVLIB model is run using weather
data from the selected location and module parameters. Module parameters
are either taken from database values or entered manually.
"""),
# html.H2('Simulation Input'),
html.H2('Weather'),
html.P(
'Enter Latitude and longitude to set target point for weather data.'),
html.Table([
html.Tr([
html.Td([
html.P('Latitude'),
dbc.Input(id='lat', value='37.88', type='text')
]),
html.Td([
html.P('Longitude'),
dbc.Input(id='lon', value='-122.25', type='text')
]),
html.Td([
html.P('Get Data'),
dbc.Button(id='get-weather', n_clicks=0,
children='Show Map')
])
])
]),
# html.Label('Latitude (degrees)'),
# dbc.Input(id='lat', value=37.88, type='number'),
# html.Label('Longitude (degrees)'),
# dbc.Input(id='lon', value=-122.25, type='number'),
# html.Div(
# 'Press button to get closest weather data to target point'),
# dbc.Button(id='get-weather', n_clicks=0,
# children='Get Weather Data'),
html.Div(id='closest-message',
children='Closest point shown on map'),
html.Div(id='location-map', children=[
dcc.Graph(id='map')
],
style={'align': 'left'}),
html.H2('Simulation Parameters'),
html.Label('Choose module to get library values for simulation'),
dcc.Dropdown(
id='module_name',
options=vocmaxlib.get_sandia_module_dropdown_list(),
value=vocmaxlib.get_sandia_module_dropdown_list()[0]['value'],
style={'max-width': 500}
),
html.Label('Choose racking model to get library values for simulation'),
dcc.Dropdown(
id='racking_model',
options=[
{'label': 'open rack cell glassback',
'value': 'open_rack_cell_glassback'},
{'label': 'roof mount cell glassback',
'value': 'roof_mount_cell_glassback'},
{'label': 'insulated back polymerback',
'value': 'insulated_back_polymerback'},
{'label': 'open rack polymer thinfilm steel',
'value': 'open_rack_polymer_thinfilm_steel'},
{'label': '22x concentrator tracker',
'value': '22x_concentrator_tracker'}
],
value='open_rack_cell_glassback',
style={'max-width': 500}
),
html.Label('Choose fixed tilt or single axis tracker'),
dbc.Tabs([
dbc.Tab([
dbc.Card(
dbc.CardBody(
[dbc.Label('Surface Tilt (degrees)'),
dbc.Input(id='surface_tilt', value='30', type='text',
style={'max-width': 200}),
dbc.Label('Surface Azimuth (degrees)'),
dbc.Input(id='surface_azimuth', value='180', type='text',
style={'max-width': 200})],
dbc.FormText("""For module face oriented due South use 180.
For module face oreinted due East use 90"""),
)
)
], tab_id='fixed_tilt', label='Fixed Tilt'),
dbc.Tab([
dbc.Card(
dbc.CardBody(
[dbc.Label('Axis Tilt (degrees)'),
dbc.Input(id='axis_tilt', value='0', type='text',
style={'max-width': 200}),
dbc.FormText("""The tilt of the axis of rotation (i.e,
the y-axis defined by axis_azimuth) with respect to
horizontal, in decimal degrees."""),
dbc.Label('Axis Azimuth (degrees)'),
dbc.Input(id='axis_azimuth', value='0', type='text',
style={'max-width': 200}),
dbc.FormText("""A value denoting the compass direction along
which the axis of rotation lies. Measured in decimal degrees
East of North."""),
dbc.Label('Max Angle (degrees)'),
dbc.Input(id='max_angle', value='90', type='text',
style={'max-width': 200}),
dbc.FormText("""A value denoting the maximum rotation angle,
in decimal degrees, of the one-axis tracker from its
horizontal position (horizontal if axis_tilt = 0). A
max_angle of 90 degrees allows the tracker to rotate to a
vertical position to point the panel towards a horizon.
max_angle of 180 degrees allows for full rotation."""),
dbc.Label('Backtrack'),
dbc.FormText("""Controls whether the tracker has the
capability to ''backtrack'' to avoid row-to-row shading. False
denotes no backtrack capability. True denotes backtrack
capability."""),
dbc.RadioItems(
options=[
{"label": "True", "value": True},
{"label": "False", "value": False},
],
value=True,
id="backtrack",
),
dbc.Label('Ground Coverage Ratio'),
dbc.Input(id='ground_coverage_ratio', value='0.286',
type='text',
style={'max-width': 200}),
dbc.FormText("""A value denoting the ground coverage ratio
of a tracker system which utilizes backtracking; i.e. the
ratio between the PV array surface area to total ground
area. A tracker system with modules 2 meters wide, centered
on the tracking axis, with 6 meters between the tracking
axes has a gcr of 2/6=0.333. If gcr is not provided,
a gcr of 2/7 is default. gcr must be <=1"""),
]
)
)
], tab_id='single_axis_tracker', label='Single Axis Tracker')
], id='mount_type', active_tab='fixed_tilt'),
dbc.Label('Max string voltage (V)'),
dbc.Input(id='max_string_voltage',
value=1500,
type='number',
style={'max-width': 200}),
dbc.FormText('Maximum string voltage for calculating string length'),
html.Details([
html.Summary('Modify/view model Parameters'),
html.Div([
html.P(
'Module and racking model (above) are used to populate fields '
'below. Changing the fields below will use these modified '
'parameters in the model.'),
dbc.Label(
'Voco: Open circuit module voltage at standard test conditions (V)'),
dbc.Input(id='Voco', value='60', type='text',
style={'max-width': 200}),
dbc.Label('Num_cells: Cells in series.'),
dbc.Input(id='Cells_in_Series', value='96', type='text',
style={'max-width': 200}),
dbc.Label(
'Bvoco: Temperature coefficient for module open-circuit-voltage (V/C)'),
dbc.Input(id='Bvoco', value='-0.21696', type='text',
style={'max-width': 200}),
dbc.Label(
'Mbvoc: Coefficient providing the irradiance dependence for the Voc temperature coefficient, typically assumed to be zero (V/C)'),
dbc.Input(id='Mbvoc', value='0', type='text',
style={'max-width': 200}),
dbc.Label('n: Diode ideality factor'),
dbc.Input(id='diode_ideality_factor', value='1.4032', type='text',
style={'max-width': 200}),
dbc.Label('FD: Fraction of diffuse irradiance used'),
dbc.Input(id='FD', value='1', type='text',
style={'max-width': 200}),
dbc.Label('Air mass coefficients'),
# dbc.Form([
# dbc.FormGroup([
# dbc.Label('A0'),
# dbc.Input(id='A0',type='number')
# ])
# ],inlne=True),
dbc.Row(
[
dbc.Col(
dbc.FormGroup(
[
dbc.Label("A0"),
dbc.Input(id="A0",value='0.9281',type="text"),
]
),
width=2,
),
dbc.Col(
dbc.FormGroup(
[
dbc.Label("A1"),
dbc.Input(id="A1",value='0.06615',type="text"),
]
),
width=2,
),
dbc.Col(
dbc.FormGroup(
[
dbc.Label("A2"),
dbc.Input(id="A2",value='-0.01384',type="text"),
]
),
width=2,
),
dbc.Col(
dbc.FormGroup(
[
dbc.Label("A3"),
dbc.Input(id="A3",value='0.001298',type="text"),
]
),
width=2,
),
dbc.Col(
dbc.FormGroup(
[
dbc.Label("A4"),
dbc.Input(id="A4",value='-4.6e-05',type="text"),
]
),
width=2,
),
],
form=True,
),
dbc.Label('AOI coefficients'),
dbc.Row(
[
dbc.Col(
dbc.FormGroup(
[
dbc.Label("B0"),
dbc.Input(id="B0",value='1',type="text"),
]
),
width=2,
),
dbc.Col(
dbc.FormGroup(
[
dbc.Label("B1"),
dbc.Input(id="B1",value='-0.002438', type="text"),
]
),
width=2,
),
dbc.Col(
dbc.FormGroup(
[
dbc.Label("B2"),
dbc.Input(id="B2",value='0.0003103', type="text"),
]
),
width=2,
),
dbc.Col(
dbc.FormGroup(
[
dbc.Label("B3"),
dbc.Input(id="B3",value='-1.246e-05', type="text"),
]
),
width=2,
),
dbc.Col(
dbc.FormGroup(
[
dbc.Label("B4"),
dbc.Input(id="B4",value='2.11e-07',type="text"),
]
),
width=2,
),
dbc.Col(
dbc.FormGroup(
[
dbc.Label("B5"),
dbc.Input(id="B5",value='-1.36e-09',type="text"),
]
),
width=2,
),
],
form=True,
),
dbc.Label(
'a: Empirically-determined coefficient establishing the upper limit for module temperature at low wind speeds and high solar irradiance'),
dbc.Input(id='a', value=-3.47, type='number',
style={'max-width': 200}),
dbc.Label(
'b: Empirically-determined coefficient establishing the rate at which module temperature drops as wind speed increases (s/m)'),
dbc.Input(id='b', value=-0.0594, type='number',
style={'max-width': 200}),
dbc.Label(
'DT: temperature difference between cell and module at reference irradiance (C)'),
dbc.Input(id='DT', value=3, type='number', style={'max-width': 200})
], style={'marginLeft': 50})
]),
html.H3('Calculate Voc'),
html.P('Press "Calculate" to run Voc calculation (15-20 seconds)'),
dbc.Button(id='submit-button', n_clicks=0, children='Calculate',
color="secondary"),
# html.P(' '),
# html.A(dbc.Button(id='submit-button-with-download',
# n_clicks=0,
# children='Calculate and download data as csv'),
# href="/download_simulation_data/"),
# html.P(
# 'Select whether to generate csv for downloading data (summary csv is always generated):'),
# dbc.Checklist(id='generate-datafile',
# options=[
# {'label': 'Generate Download Datafile',
# 'value': 'generate-datafile'},
# ],
# values=[]
# ),
html.H2('Results'),
html.Div(id='load'),
html.Div(id='graphs', style={'display': 'none'}),
dcc.Store(id='results-store',storage_type='memory'),
# dbc.Button('Download results as csv',id='download_csv',n_clicks=0),
# html.Div(id='graphs'),
# html.Div([html.Div('Calculating...')], id='graphs'),
# html.A('Download data as csv file', id='download-data',style={'display':None}),
# dcc.Slider(
# min=0,
# max=9,
# marks={i: '{}'.format(i) for i in range(9)},
# value=5,
# ),
html.Div(id='voc_list'),
html.H2('Frequently Asked Questions'),
html.Details([
html.Summary(
'Why is there a spike in the temperature histogram at 0 C?'),
html.Div("""In the NSRDB database, the temperature values are
interpolated from the NASA MERRA-2 dataset using a standard
temperature lapse rate [1]. The temperature data are then truncated
to an integer value, meaning all temperatures between -0.999 and
0.999 become 0 in the stored data. This only affects the calculation
result if the max Voc values occur at a temperature of 0 C. So,
for most locations, this rounding error has no effect on max Voc,
but in the worst case the rounding error results in a fractional
error in Voc of Bvoco*(1 C)/Voco, on the order of 0.3%.
""", style={'marginLeft': 50}),
]),
html.Details([
html.Summary(
'Can I get the source code for this website?'),
html.Div([
html.Label(["Of Course! Please visit us on github: ",
html.A("https://github.com/toddkarin/pvtools",
href="https://github.com/toddkarin/pvtools")])
],
style={'marginLeft': 50})
]),
html.H2('References'),
html.P("""
[1] M. Sengupta, Y. Xie, A. Lopez, A. Habte, G. Maclaurin, and J.
Shelby, “The national solar radiation data base (NSRDB),” Renewable
and Sustainable Energy Reviews, vol. 89, pp. 51–60, 2018.
"""),
html.P("""
[2] D. King, W. Boyson, and J. Kratochvill, “Photovoltaic array
performance model,” SAND2004-3535, 2004.
"""),
html.P("""[3] W. F. Holmgren, C. W. Hansen, and M. A. Mikofski, “pvlib
python: a python package for modeling solar energy systems,” Journal of
Open Source Software, vol. 3, no. 29, p. 884, 2018"""),
html.H2('About'),
html.P("""Funding was primarily provided as part of the Durable Modules
Consortium (DuraMAT), an Energy Materials Network Consortium funded by
the U.S. Department of Energy, Office of Energy Efficiency and Renewable
Energy, Solar Energy Technologies Office. Lawrence Berkeley National
Laboratory is funded by the DOE under award DE-AC02-05CH11231 """),
html.P('VOCMAX-DASH V-0.1'),
html.P('Author: Todd Karin')
],
style={'columnCount': 1,
'maxWidth': 1000,
'align': 'center'})
# app.layout = layout
# Callback for finding closest lat/lon in database.
@app.callback(
Output('closest-message', 'children'),
[Input('lat', 'value'),
Input('lon', 'value')]
)
def update_output_div(lat, lon):
filedata = vocmaxlib.filedata
filedata_closest = nsrdbtools.find_closest_datafiles(float(lat), float(lon),
filedata)
closest_lat = np.array(filedata_closest['lat'])[0]
closest_lon = np.array(filedata_closest['lon'])[0]
return 'Closest position in database is {:.3f} latitude, {:.3f} longitude'.format(
closest_lat, closest_lon)
# return str(n_clicks)
#
# @app.callback(
# Output('map','config'),
# [Input('map','figure')]
# )
# def forcezoom(f):
# return(dict(scrollZoom = True))
# @app.callback(
# Output('map', 'figure'),
# [Input('session-id', 'children'),
# Input('lat', 'value'),
# Input('lon', 'value')])
@app.callback(
[Output('map','figure'),
Output('map','config')
],
[Input('get-weather', 'n_clicks')],
[State('lat', 'value'),
State('lon', 'value')])
def update_map_callback(n_clicks, lat, lon):
filedata = pvtoolslib.get_s3_filename_df()
filedata_closest = nsrdbtools.find_closest_datafiles(float(lat), float(lon),
filedata)
closest_lat = np.array(filedata_closest['lat'])[0]
closest_lon = np.array(filedata_closest['lon'])[0]
map_figure = {
'data': [
go.Scattermapbox(
lat=filedata['lat'],
lon=filedata['lon'],
mode='markers',
marker=dict(
size=4
),
text=[''],
name='Database location'
),
go.Scattermapbox(
lat=[float(lat)],
lon=[float(lon)],
mode='markers',
marker=dict(
size=14
),
text=['Target location'],
name='Target location'
),
go.Scattermapbox(
lat=[closest_lat],
lon=[closest_lon],
mode='markers',
marker=dict(
size=14
),
text=['Closest datapoint'],
name='Closest datapoint'
)
],
'layout': go.Layout(
autosize=False,
width=1000,
height=600,
margin={'l': 10, 'b': 10, 't': 0, 'r': 0},
hovermode='closest',
mapbox=dict(
accesstoken='pk.eyJ1IjoidG9kZGthcmluIiwiYSI6Ik1aSndibmcifQ.hwkbjcZevafx2ApulodXaw',
bearing=0,
center=dict(
lat=float(lat),
lon=float(lon)
),
pitch=0,
zoom=5,
style='light'
),
legend=dict(
x=0,
y=1,
traceorder='normal',
font=dict(
family='sans-serif',
size=12,
color='#000'
),
bgcolor='#E2E2E2',
bordercolor='#FFFFFF',
borderwidth=2
)
)}
return map_figure, dict(scrollZoom = True)
# @app.callback(
# Output('click-data', 'children'),
# [Input('map', 'clickData')])
# def display_click_data(clickData):
#
# # If no type given, do not change lat or lon
# if type(clickData)==type(None):
# d = {'lat':37.88, 'lon':-122.25}
# else:
# click_dict = eval(str(clickData))
# d = click_dict['points'][0]
# print(d)
#
# # update_map(d['lat'],d['lon'])
#
# return str(d)
# @app.callback(
# Output('lon', 'value'),
# [Input('click-data', 'children')])
# def set_lat(click_data):
# print(click_data)
# d = eval(click_data)
# return d['lon']
# #
#
# @app.callback(
# Output('lat', 'value'),
# [Input('click-data', 'children')])
# def set_lat(click_data):
# print(click_data)
# d = eval(click_data)
# return d['lat']
# #
# @app.callback(
# Output('lon', 'value'),
# [Input('click-data', 'children')])
# def set_lat(click_data):
# d = eval(click_data)
# return d['lon']
#
#
# @app.callback(
# Output('get-weather', 'n_clicks'),
# [Input('click-data', 'children')],
# [State('get-weather', 'n_clicks')])
# def display_click_data(click_data, n_clicks):
# return n_clicks+1
# # return json.dumps(clickData, indent=2)
#
#
# Update values when changing the module name.
@app.callback(Output('Voco', 'value'), [Input('module_name', 'value')])
def update_Voco(module_name):
return str(pvtoolslib.sandia_modules[module_name]['Voco'])
@app.callback(Output('Bvoco', 'value'), [Input('module_name', 'value')])
def update_Voco(module_name):
return str(pvtoolslib.sandia_modules[module_name]['Bvoco'])
@app.callback(Output('Mbvoc', 'value'), [Input('module_name', 'value')])
def update_Voco(module_name):
return str(pvtoolslib.sandia_modules[module_name]['Mbvoc'])
@app.callback(Output('Cells_in_Series', 'value'),
[Input('module_name', 'value')])
def update_Voco(module_name):
return str(pvtoolslib.sandia_modules[module_name]['Cells_in_Series'])
@app.callback(Output('diode_ideality_factor', 'value'),
[Input('module_name', 'value')])
def update_Voco(module_name):
return str(pvtoolslib.sandia_modules[module_name]['N'])
@app.callback(Output('FD', 'value'), [Input('module_name', 'value')])
def update_Voco(module_name):
return str(pvtoolslib.sandia_modules[module_name]['FD'])
@app.callback(Output('A0', 'value'), [Input('module_name', 'value')])
def update(module_name):
return str(pvtoolslib.sandia_modules[module_name]['A0'])
@app.callback(Output('A1', 'value'), [Input('module_name', 'value')])
def update(module_name):
return str(pvtoolslib.sandia_modules[module_name]['A1'])
@app.callback(Output('A2', 'value'), [Input('module_name', 'value')])
def update(module_name):
return str(pvtoolslib.sandia_modules[module_name]['A2'])
@app.callback(Output('A3', 'value'), [Input('module_name', 'value')])
def update(module_name):
return str(pvtoolslib.sandia_modules[module_name]['A3'])
@app.callback(Output('A4', 'value'), [Input('module_name', 'value')])
def update(module_name):
return str(pvtoolslib.sandia_modules[module_name]['A4'])
@app.callback(Output('B0', 'value'), [Input('module_name', 'value')])
def update(module_name):
return str(pvtoolslib.sandia_modules[module_name]['B0'])
@app.callback(Output('B1', 'value'), [Input('module_name', 'value')])
def update(module_name):
return str(pvtoolslib.sandia_modules[module_name]['B1'])
@app.callback(Output('B2', 'value'), [Input('module_name', 'value')])
def update(module_name):
return str(pvtoolslib.sandia_modules[module_name]['B2'])
@app.callback(Output('B3', 'value'), [Input('module_name', 'value')])
def update(module_name):
return str(pvtoolslib.sandia_modules[module_name]['B3'])
@app.callback(Output('B4', 'value'), [Input('module_name', 'value')])
def update(module_name):
return str(pvtoolslib.sandia_modules[module_name]['B4'])
@app.callback(Output('B5', 'value'), [Input('module_name', 'value')])
def update(module_name):
return str(pvtoolslib.sandia_modules[module_name]['B5'])
@app.callback(Output('a', 'value'), [Input('racking_model', 'value')])
def update_Voco(racking_model):
return pvlib.pvsystem.TEMP_MODEL_PARAMS['sapm'][racking_model][0]
@app.callback(Output('b', 'value'), [Input('racking_model', 'value')])
def update_Voco(racking_model):
return pvlib.pvsystem.TEMP_MODEL_PARAMS['sapm'][racking_model][1]
@app.callback(Output('DT', 'value'), [Input('racking_model', 'value')])
def update(racking_model):
return pvlib.pvsystem.TEMP_MODEL_PARAMS['sapm'][racking_model][2]
#
# @app.callback(Output('download-data', 'href'),
# [Input('session-id', 'children')])
# def update_download_link(session_id):
# # dff = filter_data(filter_value)
# # csv_string = dff.to_csv(index=False, encoding='utf-8')
# # csv_string = "data:text/csv;charset=utf-8," + urllib.quote(csv_string)
#
# csv_string = 'hello'
# return csv_string
#
#
@app.callback(Output('load', 'children'),
[Input('submit-button', 'n_clicks')
])
def prepare_data(categ):
if categ:
return html.Div([
dbc.Alert("Calculating...",
color="primary")
],
id='graphs')
#
@app.callback(Output('graphs', 'children'),
[Input('submit-button', 'n_clicks')
],
[State('module_name', 'value'),
State('racking_model', 'value'),
State('surface_tilt', 'value'),
State('surface_azimuth', 'value'),
State('lat', 'value'),
State('lon', 'value'),
State('Voco', 'value'),
State('Bvoco', 'value'),
State('Mbvoc', 'value'),
State('Cells_in_Series', 'value'),
State('diode_ideality_factor', 'value'),
State('FD', 'value'),
State('A0', 'value'),
State('A1', 'value'),
State('A2', 'value'),
State('A3', 'value'),
State('A4', 'value'),
State('B0', 'value'),
State('B1', 'value'),
State('B2', 'value'),
State('B3', 'value'),
State('B4', 'value'),
State('B5', 'value'),
State('a', 'value'),
State('b', 'value'),
State('DT', 'value'),
State('max_string_voltage', 'value'),
State('mount_type', 'active_tab'),
State('axis_tilt', 'value'),
State('axis_azimuth', 'value'),
State('max_angle', 'value'),
State('backtrack', 'value'),
State('ground_coverage_ratio', 'value'),
]
)
def update_graph(n_clicks, module_name, racking_model,
surface_tilt, surface_azimuth, lat, lon, Voco, Bvoco, Mbvoc,
Cells_in_Series,
diode_ideality_factor, FD,
A0,A1,A2,A3,A4,B0,B1,B2,B3,B4,B5,
a, b, DT,
max_string_voltage,
mount_type, axis_tilt, axis_azimuth, max_angle, backtrack,
ground_coverage_ratio):
system_parameters = {
'racking_model': {'a': a, 'b': b, 'deltaT': DT},
# 'racking_model': racking_model,
'surface_tilt': float(surface_tilt),
'surface_azimuth': float(surface_azimuth),
'mount_type': mount_type,
'axis_tilt': float(axis_tilt),
'axis_azimuth': float(axis_azimuth),
'max_angle': float(max_angle),
'backtrack': float(backtrack),
'ground_coverage_ratio': float(ground_coverage_ratio)}
if n_clicks<1:
print('Not running simulation.')
return [], ''
module_parameters = pvtoolslib.sandia_modules[module_name]
# Overwrite provided module parameters.
module_parameters['Voco'] = float(Voco)
module_parameters['Bvoco'] = float(Bvoco)
module_parameters['Mbvoc'] = float(Mbvoc)
module_parameters['Cells_in_Series'] = float(Cells_in_Series)
module_parameters['diode_ideality_factor'] = float(diode_ideality_factor)
module_parameters['FD'] = float(FD)
module_parameters['A0'] = float(A0)
module_parameters['A1'] = float(A1)
module_parameters['A2'] = float(A2)
module_parameters['A3'] = float(A3)
module_parameters['A4'] = float(A4)
module_parameters['B0'] = float(B0)
module_parameters['B1'] = float(B1)
module_parameters['B2'] = float(B2)
module_parameters['B3'] = float(B3)
module_parameters['B4'] = float(B4)
module_parameters['B5'] = float(B5)
filedata = pvtoolslib.get_s3_filename_df()
filedata_closest = nsrdbtools.find_closest_datafiles(float(lat), float(lon),
filedata)
print('Getting weather data...')
weather, info = pvtoolslib.get_s3_weather_data(filedata_closest['filename'].iloc[0])
# print(info.keys())
print('Simulating system...')
(df, mc) = vocmaxlib.calculate_max_voc_sandia(weather, info,
module_parameters=module_parameters,
system_parameters=system_parameters)
info_df = pd.DataFrame(
{'Weather data source': info['Source'],
'Location ID': info['Location_ID'],
'Latitude': info['Latitude'],
'Longitude': info['Longitude'],
'Elevation': info['Elevation'],
'Time Zone': info['local_time_zone'],
'Data time step (hours)': info['interval_in_hours'],
'Data time length (years)': info['timedelta_in_years'],
'PVTOOLS Version': pvtoolslib.version,
'v_oc units':'Volts',
'temp_air units': 'C',
'wind_speed units': 'm/s',
'dni units': 'W/m^2',
'dhi units': 'W/m^2',
'ghi units': 'W/m^2',
},
index=[0]
)
print('Generating files for downloading...')
df_temp = df.copy()
df_temp['wind_speed'] = df_temp['wind_speed'].map(lambda x: '%2.1f' % x)
df_temp['v_oc'] = df_temp['v_oc'].map(lambda x: '%3.2f' % x)
df_temp['temp_cell'] = df_temp['temp_cell'].map(lambda x: '%2.1f' % x)
# csv_string = "data:text/csv;charset=utf-8," + urllib.parse.quote(
# df_temp.to_csv(index=False, encoding='utf-8',float_format='%.3f')
# )
csv_string = "data:text/csv;charset=utf-8,"
csv_string_one_year = "data:text/csv;charset=utf-8," + \
urllib.parse.quote(
info_df.to_csv(index=False,
encoding='utf-8',
float_format='%.3f')
) + \
urllib.parse.quote(
df_temp[0:17520].to_csv(index=False,
encoding='utf-8',
float_format='%.3f')
)
print('done')
y, c = np.histogram(df['v_oc'],
bins=np.linspace(df['v_oc'].max() * 0.75,
df['v_oc'].max() + 1, 500))
years = list(set(weather.index.year))
yearly_min_temp = []
yearly_min_daytime_temp = []
for j in years:
yearly_min_temp.append(
weather[weather.index.year == j]['temp_air'].min())
yearly_min_daytime_temp.append(
weather[weather.index.year == j]['temp_air'][
weather[weather.index.year == j]['ghi'] > 150].min()
)
mean_yearly_min_ambient_temp = np.mean(yearly_min_temp)
mean_yearly_min_daytime_ambient_temp = np.mean(yearly_min_daytime_temp)
# min_daytime_temp = df['temp_air'][df['ghi']>150].min()
voc_1sun_min_temp = mc.system.sapm(1, mean_yearly_min_ambient_temp)['v_oc']
voc_1sun_min_daytime_temp = \
mc.system.sapm(1, mean_yearly_min_daytime_ambient_temp)['v_oc']
voc_dni_cell_temp = \
mc.system.sapm((df['dni'] + df['dhi']) / 1000, df['temp_cell'])[
'v_oc'].max()
voc_P99p5 = np.percentile(
df['v_oc'][np.logical_not(np.isnan(df['v_oc']))],
99.5)
voc_P99 = np.percentile(df['v_oc'][np.logical_not(np.isnan(df['v_oc']))],
99)
# results_dict = {
# 'Source': info['source'],
# 'Location ID': info['location_id'],
# 'Elevation': info['elevation'],
# 'Latitude': info['lat'],
# 'Longitude': info['lon'],
# # 'DHI Units': info['DHI Units'][0],
# # 'DNI Units': info['DNI Units'][0],
# # 'GHI Units': info['GHI Units'][0],
# # 'V_oc Units': 'V',
# # 'Wind Speed Units': info['Wind Speed'][0],
# 'interval_in_hours': info['interval_in_hours'],
# 'timedelta_in_years': info['timedelta_in_years'],
# 'NSRDB Version': info['version'],
# 'PVLIB Version': pvlib._version.get_versions()['version'],