forked from pvlib/pvlib-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpvsystem.py
3005 lines (2451 loc) · 106 KB
/
pvsystem.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
"""
The ``pvsystem`` module contains functions for modeling the output and
performance of PV modules and inverters.
"""
from collections import OrderedDict
import functools
import io
import itertools
from pathlib import Path
import inspect
from urllib.request import urlopen
import numpy as np
from scipy import constants
import pandas as pd
from dataclasses import dataclass
from abc import ABC, abstractmethod
from typing import Optional, Union
from pvlib._deprecation import deprecated
import pvlib # used to avoid albedo name collision in the Array class
from pvlib import (atmosphere, iam, inverter, irradiance,
singlediode as _singlediode, spectrum, temperature)
from pvlib.tools import _build_kwargs, _build_args
import pvlib.tools as tools
# a dict of required parameter names for each DC power model
_DC_MODEL_PARAMS = {
'sapm': {
'A0', 'A1', 'A2', 'A3', 'A4', 'B0', 'B1', 'B2', 'B3',
'B4', 'B5', 'C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6',
'C7', 'Isco', 'Impo', 'Voco', 'Vmpo', 'Aisc', 'Aimp', 'Bvoco',
'Mbvoc', 'Bvmpo', 'Mbvmp', 'N', 'Cells_in_Series',
'IXO', 'IXXO', 'FD'},
'desoto': {
'alpha_sc', 'a_ref', 'I_L_ref', 'I_o_ref',
'R_sh_ref', 'R_s'},
'cec': {
'alpha_sc', 'a_ref', 'I_L_ref', 'I_o_ref',
'R_sh_ref', 'R_s', 'Adjust'},
'pvsyst': {
'gamma_ref', 'mu_gamma', 'I_L_ref', 'I_o_ref',
'R_sh_ref', 'R_sh_0', 'R_s', 'alpha_sc', 'EgRef',
'cells_in_series'},
'singlediode': {
'alpha_sc', 'a_ref', 'I_L_ref', 'I_o_ref',
'R_sh_ref', 'R_s'},
'pvwatts': {'pdc0', 'gamma_pdc'}
}
def _unwrap_single_value(func):
"""Decorator for functions that return iterables.
If the length of the iterable returned by `func` is 1, then
the single member of the iterable is returned. If the length is
greater than 1, then entire iterable is returned.
Adds 'unwrap' as a keyword argument that can be set to False
to force the return value to be a tuple, regardless of its length.
"""
@functools.wraps(func)
def f(*args, **kwargs):
unwrap = kwargs.pop('unwrap', True)
x = func(*args, **kwargs)
if unwrap and len(x) == 1:
return x[0]
return x
return f
# not sure if this belongs in the pvsystem module.
# maybe something more like core.py? It may eventually grow to
# import a lot more functionality from other modules.
class PVSystem:
"""
The PVSystem class defines a standard set of PV system attributes
and modeling functions. This class describes the collection and
interactions of PV system components rather than an installed system
on the ground. It is typically used in combination with
:py:class:`~pvlib.location.Location` and
:py:class:`~pvlib.modelchain.ModelChain`
objects.
The class supports basic system topologies consisting of:
* `N` total modules arranged in series
(`modules_per_string=N`, `strings_per_inverter=1`).
* `M` total modules arranged in parallel
(`modules_per_string=1`, `strings_per_inverter=M`).
* `NxM` total modules arranged in `M` strings of `N` modules each
(`modules_per_string=N`, `strings_per_inverter=M`).
The class is complementary to the module-level functions.
The attributes should generally be things that don't change about
the system, such the type of module and the inverter. The instance
methods accept arguments for things that do change, such as
irradiance and temperature.
Parameters
----------
arrays : Array or iterable of Array, optional
An Array or list of arrays that are part of the system. If not
specified, a single array is created from the other parameters (e.g.
`surface_tilt`, `surface_azimuth`). If specified as a list, the list
must contain at least one Array;
if length of arrays is 0 a ValueError is raised. If `arrays` is
specified the following PVSystem parameters are ignored:
- `surface_tilt`
- `surface_azimuth`
- `albedo`
- `surface_type`
- `module`
- `module_type`
- `module_parameters`
- `temperature_model_parameters`
- `modules_per_string`
- `strings_per_inverter`
surface_tilt: float or array-like, default 0
Surface tilt angles in decimal degrees.
The tilt angle is defined as degrees from horizontal
(e.g. surface facing up = 0, surface facing horizon = 90)
surface_azimuth: float or array-like, default 180
Azimuth angle of the module surface in decimal degrees.
North=0, East=90, South=180, West=270.
albedo : float, optional
Ground surface albedo. If not supplied, then ``surface_type`` is used
to look up a value in :py:const:`pvlib.albedo.SURFACE_ALBEDOS`.
If ``surface_type`` is also not supplied then a ground surface albedo
of 0.25 is used.
surface_type : string, optional
The ground surface type. See :py:const:`pvlib.albedo.SURFACE_ALBEDOS`
for valid values.
module : string, optional
The model name of the modules.
May be used to look up the ``module_parameters`` dictionary
via some other method.
module_type : string, default `glass_polymer`
Describes the module's construction. Valid strings are `glass_polymer`
and `glass_glass`. Used for cell and module temperature calculations.
module_parameters : dict or Series, optional
Module parameters as defined by the SAPM, CEC, or other.
temperature_model_parameters : dict or Series, optional
Temperature model parameters as required by one of the models in
py:func:`pvlib.temperature` (excluding ``poa_global``, ``temp_air`` and
``wind_speed``).
modules_per_string: int or float, default 1
See system topology discussion above.
strings_per_inverter: int or float, default 1
See system topology discussion above.
inverter : string, optional
The model name of the inverters.
May be used to look up the ``inverter_parameters`` dictionary
via some other method.
inverter_parameters : dict or Series, optional
Inverter parameters as defined by the SAPM, CEC, or other.
racking_model : string, default None
Valid strings are `open_rack`, `close_mount`, `freestanding`, or
`insulated_back`.
Used to identify a parameter set for the cell temperature model.
losses_parameters : dict or Series, optional
Losses parameters as defined by PVWatts or other.
name : string, optional
**kwargs
Arbitrary keyword arguments.
Included for compatibility, but not used.
Raises
------
ValueError
If ``arrays`` is not None and has length 0.
See also
--------
pvlib.location.Location
"""
def __init__(self,
arrays=None,
surface_tilt=0, surface_azimuth=180,
albedo=None, surface_type=None,
module=None, module_type=None,
module_parameters=None,
temperature_model_parameters=None,
modules_per_string=1, strings_per_inverter=1,
inverter=None, inverter_parameters=None,
racking_model=None, losses_parameters=None, name=None):
if arrays is None:
if losses_parameters is None:
array_losses_parameters = {}
else:
array_losses_parameters = _build_kwargs(['dc_ohmic_percent'],
losses_parameters)
self.arrays = (Array(
FixedMount(surface_tilt, surface_azimuth, racking_model),
albedo,
surface_type,
module,
module_type,
module_parameters,
temperature_model_parameters,
modules_per_string,
strings_per_inverter,
array_losses_parameters,
),)
elif isinstance(arrays, Array):
self.arrays = (arrays,)
elif len(arrays) == 0:
raise ValueError("PVSystem must have at least one Array. "
"If you want to create a PVSystem instance "
"with a single Array pass `arrays=None` and pass "
"values directly to PVSystem attributes, e.g., "
"`surface_tilt=30`")
else:
self.arrays = tuple(arrays)
self.inverter = inverter
if inverter_parameters is None:
self.inverter_parameters = {}
else:
self.inverter_parameters = inverter_parameters
if losses_parameters is None:
self.losses_parameters = {}
else:
self.losses_parameters = losses_parameters
self.name = name
def __repr__(self):
repr = f'PVSystem:\n name: {self.name}\n '
for array in self.arrays:
repr += '\n '.join(array.__repr__().split('\n'))
repr += '\n '
repr += f'inverter: {self.inverter}'
return repr
def _validate_per_array(self, values, system_wide=False):
"""Check that `values` is a tuple of the same length as
`self.arrays`.
If `values` is not a tuple it is packed in to a length-1 tuple before
the check. If the lengths are not the same a ValueError is raised,
otherwise the tuple `values` is returned.
When `system_wide` is True and `values` is not a tuple, `values`
is replicated to a tuple of the same length as `self.arrays` and that
tuple is returned.
"""
if system_wide and not isinstance(values, tuple):
return (values,) * self.num_arrays
if not isinstance(values, tuple):
values = (values,)
if len(values) != len(self.arrays):
raise ValueError("Length mismatch for per-array parameter")
return values
@_unwrap_single_value
def _infer_cell_type(self):
"""
Examines module_parameters and maps the Technology key for the CEC
database and the Material key for the Sandia database to a common
list of strings for cell type.
Returns
-------
cell_type: str
"""
return tuple(array._infer_cell_type() for array in self.arrays)
@_unwrap_single_value
def get_aoi(self, solar_zenith, solar_azimuth):
"""Get the angle of incidence on the Array(s) in the system.
Parameters
----------
solar_zenith : float or Series.
Solar zenith angle.
solar_azimuth : float or Series.
Solar azimuth angle.
Returns
-------
aoi : Series or tuple of Series
The angle of incidence
"""
return tuple(array.get_aoi(solar_zenith, solar_azimuth)
for array in self.arrays)
@_unwrap_single_value
def get_irradiance(self, solar_zenith, solar_azimuth, dni, ghi, dhi,
dni_extra=None, airmass=None, albedo=None,
model='haydavies', **kwargs):
"""
Uses the :py:func:`irradiance.get_total_irradiance` function to
calculate the plane of array irradiance components on the tilted
surfaces defined by each array's ``surface_tilt`` and
``surface_azimuth``.
Parameters
----------
solar_zenith : float or Series
Solar zenith angle.
solar_azimuth : float or Series
Solar azimuth angle.
dni : float or Series or tuple of float or Series
Direct Normal Irradiance. [W/m2]
ghi : float or Series or tuple of float or Series
Global horizontal irradiance. [W/m2]
dhi : float or Series or tuple of float or Series
Diffuse horizontal irradiance. [W/m2]
dni_extra : float, Series or tuple of float or Series, optional
Extraterrestrial direct normal irradiance. [W/m2]
airmass : float or Series, optional
Airmass. [unitless]
albedo : float or Series, optional
Ground surface albedo. [unitless]
model : String, default 'haydavies'
Irradiance model.
kwargs
Extra parameters passed to :func:`irradiance.get_total_irradiance`.
Notes
-----
Each of `dni`, `ghi`, and `dni` parameters may be passed as a tuple
to provide different irradiance for each array in the system. If not
passed as a tuple then the same value is used for input to each Array.
If passed as a tuple the length must be the same as the number of
Arrays.
Returns
-------
poa_irradiance : DataFrame or tuple of DataFrame
Column names are: ``'poa_global', 'poa_direct', 'poa_diffuse',
'poa_sky_diffuse', 'poa_ground_diffuse'``.
See also
--------
pvlib.irradiance.get_total_irradiance
"""
dni = self._validate_per_array(dni, system_wide=True)
ghi = self._validate_per_array(ghi, system_wide=True)
dhi = self._validate_per_array(dhi, system_wide=True)
albedo = self._validate_per_array(albedo, system_wide=True)
return tuple(
array.get_irradiance(solar_zenith, solar_azimuth,
dni, ghi, dhi,
dni_extra=dni_extra, airmass=airmass,
albedo=albedo, model=model, **kwargs)
for array, dni, ghi, dhi, albedo in zip(
self.arrays, dni, ghi, dhi, albedo
)
)
@_unwrap_single_value
def get_iam(self, aoi, iam_model='physical'):
"""
Determine the incidence angle modifier using the method specified by
``iam_model``.
Parameters for the selected IAM model are expected to be in
``PVSystem.module_parameters``. Default parameters are available for
the 'physical', 'ashrae' and 'martin_ruiz' models.
Parameters
----------
aoi : numeric or tuple of numeric
The angle of incidence in degrees.
aoi_model : string, default 'physical'
The IAM model to be used. Valid strings are 'physical', 'ashrae',
'martin_ruiz', 'sapm' and 'interp'.
Returns
-------
iam : numeric or tuple of numeric
The AOI modifier.
Raises
------
ValueError
if `iam_model` is not a valid model name.
"""
aoi = self._validate_per_array(aoi)
return tuple(array.get_iam(aoi, iam_model)
for array, aoi in zip(self.arrays, aoi))
@_unwrap_single_value
def get_cell_temperature(self, poa_global, temp_air, wind_speed, model,
effective_irradiance=None):
"""
Determine cell temperature using the method specified by ``model``.
Parameters
----------
poa_global : numeric or tuple of numeric
Total incident irradiance in W/m^2.
temp_air : numeric or tuple of numeric
Ambient dry bulb temperature in degrees C.
wind_speed : numeric or tuple of numeric
Wind speed in m/s.
model : str
Supported models include ``'sapm'``, ``'pvsyst'``,
``'faiman'``, ``'fuentes'``, and ``'noct_sam'``
effective_irradiance : numeric or tuple of numeric, optional
The irradiance that is converted to photocurrent in W/m^2.
Only used for some models.
Returns
-------
numeric or tuple of numeric
Values in degrees C.
See Also
--------
Array.get_cell_temperature
Notes
-----
The `temp_air` and `wind_speed` parameters may be passed as tuples
to provide different values for each Array in the system. If passed as
a tuple the length must be the same as the number of Arrays. If not
passed as a tuple then the same value is used for each Array.
"""
poa_global = self._validate_per_array(poa_global)
temp_air = self._validate_per_array(temp_air, system_wide=True)
wind_speed = self._validate_per_array(wind_speed, system_wide=True)
# Not used for all models, but Array.get_cell_temperature handles it
effective_irradiance = self._validate_per_array(effective_irradiance,
system_wide=True)
return tuple(
array.get_cell_temperature(poa_global, temp_air, wind_speed,
model, effective_irradiance)
for array, poa_global, temp_air, wind_speed, effective_irradiance
in zip(
self.arrays, poa_global, temp_air, wind_speed,
effective_irradiance
)
)
@_unwrap_single_value
def calcparams_desoto(self, effective_irradiance, temp_cell):
"""
Use the :py:func:`calcparams_desoto` function, the input
parameters and ``self.module_parameters`` to calculate the
module currents and resistances.
Parameters
----------
effective_irradiance : numeric or tuple of numeric
The irradiance (W/m2) that is converted to photocurrent.
temp_cell : float or Series or tuple of float or Series
The average cell temperature of cells within a module in C.
Returns
-------
See pvsystem.calcparams_desoto for details
"""
effective_irradiance = self._validate_per_array(effective_irradiance)
temp_cell = self._validate_per_array(temp_cell)
build_kwargs = functools.partial(
_build_kwargs,
['a_ref', 'I_L_ref', 'I_o_ref', 'R_sh_ref',
'R_s', 'alpha_sc', 'EgRef', 'dEgdT',
'irrad_ref', 'temp_ref']
)
return tuple(
calcparams_desoto(
effective_irradiance, temp_cell,
**build_kwargs(array.module_parameters)
)
for array, effective_irradiance, temp_cell
in zip(self.arrays, effective_irradiance, temp_cell)
)
@_unwrap_single_value
def calcparams_cec(self, effective_irradiance, temp_cell):
"""
Use the :py:func:`calcparams_cec` function, the input
parameters and ``self.module_parameters`` to calculate the
module currents and resistances.
Parameters
----------
effective_irradiance : numeric or tuple of numeric
The irradiance (W/m2) that is converted to photocurrent.
temp_cell : float or Series or tuple of float or Series
The average cell temperature of cells within a module in C.
Returns
-------
See pvsystem.calcparams_cec for details
"""
effective_irradiance = self._validate_per_array(effective_irradiance)
temp_cell = self._validate_per_array(temp_cell)
build_kwargs = functools.partial(
_build_kwargs,
['a_ref', 'I_L_ref', 'I_o_ref', 'R_sh_ref',
'R_s', 'alpha_sc', 'Adjust', 'EgRef', 'dEgdT',
'irrad_ref', 'temp_ref']
)
return tuple(
calcparams_cec(
effective_irradiance, temp_cell,
**build_kwargs(array.module_parameters)
)
for array, effective_irradiance, temp_cell
in zip(self.arrays, effective_irradiance, temp_cell)
)
@_unwrap_single_value
def calcparams_pvsyst(self, effective_irradiance, temp_cell):
"""
Use the :py:func:`calcparams_pvsyst` function, the input
parameters and ``self.module_parameters`` to calculate the
module currents and resistances.
Parameters
----------
effective_irradiance : numeric or tuple of numeric
The irradiance (W/m2) that is converted to photocurrent.
temp_cell : float or Series or tuple of float or Series
The average cell temperature of cells within a module in C.
Returns
-------
See pvsystem.calcparams_pvsyst for details
"""
effective_irradiance = self._validate_per_array(effective_irradiance)
temp_cell = self._validate_per_array(temp_cell)
build_kwargs = functools.partial(
_build_kwargs,
['gamma_ref', 'mu_gamma', 'I_L_ref', 'I_o_ref',
'R_sh_ref', 'R_sh_0', 'R_sh_exp',
'R_s', 'alpha_sc', 'EgRef',
'irrad_ref', 'temp_ref',
'cells_in_series']
)
return tuple(
calcparams_pvsyst(
effective_irradiance, temp_cell,
**build_kwargs(array.module_parameters)
)
for array, effective_irradiance, temp_cell
in zip(self.arrays, effective_irradiance, temp_cell)
)
@_unwrap_single_value
def sapm(self, effective_irradiance, temp_cell):
"""
Use the :py:func:`sapm` function, the input parameters,
and ``self.module_parameters`` to calculate
Voc, Isc, Ix, Ixx, Vmp, and Imp.
Parameters
----------
effective_irradiance : numeric or tuple of numeric
The irradiance (W/m2) that is converted to photocurrent.
temp_cell : float or Series or tuple of float or Series
The average cell temperature of cells within a module in C.
Returns
-------
See pvsystem.sapm for details
"""
effective_irradiance = self._validate_per_array(effective_irradiance)
temp_cell = self._validate_per_array(temp_cell)
return tuple(
sapm(effective_irradiance, temp_cell, array.module_parameters)
for array, effective_irradiance, temp_cell
in zip(self.arrays, effective_irradiance, temp_cell)
)
@_unwrap_single_value
def sapm_spectral_loss(self, airmass_absolute):
"""
Use the :py:func:`pvlib.spectrum.spectral_factor_sapm` function,
the input parameters, and ``self.module_parameters`` to calculate F1.
Parameters
----------
airmass_absolute : numeric
Absolute airmass.
Returns
-------
F1 : numeric or tuple of numeric
The SAPM spectral loss coefficient.
"""
return tuple(
spectrum.spectral_factor_sapm(airmass_absolute,
array.module_parameters)
for array in self.arrays
)
@_unwrap_single_value
def sapm_effective_irradiance(self, poa_direct, poa_diffuse,
airmass_absolute, aoi,
reference_irradiance=1000):
"""
Use the :py:func:`sapm_effective_irradiance` function, the input
parameters, and ``self.module_parameters`` to calculate
effective irradiance.
Parameters
----------
poa_direct : numeric or tuple of numeric
The direct irradiance incident upon the module. [W/m2]
poa_diffuse : numeric or tuple of numeric
The diffuse irradiance incident on module. [W/m2]
airmass_absolute : numeric
Absolute airmass. [unitless]
aoi : numeric or tuple of numeric
Angle of incidence. [degrees]
Returns
-------
effective_irradiance : numeric or tuple of numeric
The SAPM effective irradiance. [W/m2]
"""
poa_direct = self._validate_per_array(poa_direct)
poa_diffuse = self._validate_per_array(poa_diffuse)
aoi = self._validate_per_array(aoi)
return tuple(
sapm_effective_irradiance(
poa_direct, poa_diffuse, airmass_absolute, aoi,
array.module_parameters)
for array, poa_direct, poa_diffuse, aoi
in zip(self.arrays, poa_direct, poa_diffuse, aoi)
)
@_unwrap_single_value
def first_solar_spectral_loss(self, pw, airmass_absolute):
"""
Use :py:func:`pvlib.spectrum.spectral_factor_firstsolar` to
calculate the spectral loss modifier. The model coefficients are
specific to the module's cell type, and are determined by searching
for one of the following keys in self.module_parameters (in order):
- 'first_solar_spectral_coefficients' (user-supplied coefficients)
- 'Technology' - a string describing the cell type, can be read from
the CEC module parameter database
- 'Material' - a string describing the cell type, can be read from
the Sandia module database.
Parameters
----------
pw : array-like
atmospheric precipitable water (cm).
airmass_absolute : array-like
absolute (pressure corrected) airmass.
Returns
-------
modifier: array-like or tuple of array-like
spectral mismatch factor (unitless) which can be multiplied
with broadband irradiance reaching a module's cells to estimate
effective irradiance, i.e., the irradiance that is converted to
electrical current.
"""
pw = self._validate_per_array(pw, system_wide=True)
def _spectral_correction(array, pw):
if 'first_solar_spectral_coefficients' in \
array.module_parameters.keys():
coefficients = \
array.module_parameters[
'first_solar_spectral_coefficients'
]
module_type = None
else:
module_type = array._infer_cell_type()
coefficients = None
return spectrum.spectral_factor_firstsolar(
pw, airmass_absolute, module_type, coefficients
)
return tuple(
itertools.starmap(_spectral_correction, zip(self.arrays, pw))
)
def singlediode(self, photocurrent, saturation_current,
resistance_series, resistance_shunt, nNsVth):
"""Wrapper around the :py:func:`pvlib.pvsystem.singlediode` function.
See :py:func:`pvsystem.singlediode` for details
"""
return singlediode(photocurrent, saturation_current,
resistance_series, resistance_shunt, nNsVth)
def i_from_v(self, voltage, photocurrent, saturation_current,
resistance_series, resistance_shunt, nNsVth):
"""Wrapper around the :py:func:`pvlib.pvsystem.i_from_v` function.
See :py:func:`pvlib.pvsystem.i_from_v` for details.
.. versionchanged:: 0.10.0
The function's arguments have been reordered.
"""
return i_from_v(voltage, photocurrent, saturation_current,
resistance_series, resistance_shunt, nNsVth)
def get_ac(self, model, p_dc, v_dc=None):
r"""Calculates AC power from p_dc using the inverter model indicated
by model and self.inverter_parameters.
Parameters
----------
model : str
Must be one of 'sandia', 'adr', or 'pvwatts'.
p_dc : numeric, or tuple, list or array of numeric
DC power on each MPPT input of the inverter. Use tuple, list or
array for inverters with multiple MPPT inputs. If type is array,
p_dc must be 2d with axis 0 being the MPPT inputs. [W]
v_dc : numeric, or tuple, list or array of numeric
DC voltage on each MPPT input of the inverter. Required when
model='sandia' or model='adr'. Use tuple, list or
array for inverters with multiple MPPT inputs. If type is array,
v_dc must be 2d with axis 0 being the MPPT inputs. [V]
Returns
-------
power_ac : numeric
AC power output for the inverter. [W]
Raises
------
ValueError
If model is not one of 'sandia', 'adr' or 'pvwatts'.
ValueError
If model='adr' and the PVSystem has more than one array.
See also
--------
pvlib.inverter.sandia
pvlib.inverter.sandia_multi
pvlib.inverter.adr
pvlib.inverter.pvwatts
pvlib.inverter.pvwatts_multi
"""
model = model.lower()
multiple_arrays = self.num_arrays > 1
if model == 'sandia':
p_dc = self._validate_per_array(p_dc)
v_dc = self._validate_per_array(v_dc)
if multiple_arrays:
return inverter.sandia_multi(
v_dc, p_dc, self.inverter_parameters)
return inverter.sandia(v_dc[0], p_dc[0], self.inverter_parameters)
elif model == 'pvwatts':
kwargs = _build_kwargs(['eta_inv_nom', 'eta_inv_ref'],
self.inverter_parameters)
p_dc = self._validate_per_array(p_dc)
if multiple_arrays:
return inverter.pvwatts_multi(
p_dc, self.inverter_parameters['pdc0'], **kwargs)
return inverter.pvwatts(
p_dc[0], self.inverter_parameters['pdc0'], **kwargs)
elif model == 'adr':
if multiple_arrays:
raise ValueError(
'The adr inverter function cannot be used for an inverter',
' with multiple MPPT inputs')
# While this is only used for single-array systems, calling
# _validate_per_arry lets us pass in singleton tuples.
p_dc = self._validate_per_array(p_dc)
v_dc = self._validate_per_array(v_dc)
return inverter.adr(v_dc[0], p_dc[0], self.inverter_parameters)
else:
raise ValueError(
model + ' is not a valid AC power model.',
' model must be one of "sandia", "adr" or "pvwatts"')
@_unwrap_single_value
def scale_voltage_current_power(self, data):
"""
Scales the voltage, current, and power of the `data` DataFrame
by `self.modules_per_string` and `self.strings_per_inverter`.
Parameters
----------
data: DataFrame or tuple of DataFrame
May contain columns `'v_mp', 'v_oc', 'i_mp' ,'i_x', 'i_xx',
'i_sc', 'p_mp'`.
Returns
-------
scaled_data: DataFrame or tuple of DataFrame
A scaled copy of the input data.
"""
data = self._validate_per_array(data)
return tuple(
scale_voltage_current_power(data,
voltage=array.modules_per_string,
current=array.strings)
for array, data in zip(self.arrays, data)
)
@_unwrap_single_value
def pvwatts_dc(self, g_poa_effective, temp_cell):
"""
Calculates DC power according to the PVWatts model using
:py:func:`pvlib.pvsystem.pvwatts_dc`, `self.module_parameters['pdc0']`,
and `self.module_parameters['gamma_pdc']`.
See :py:func:`pvlib.pvsystem.pvwatts_dc` for details.
"""
g_poa_effective = self._validate_per_array(g_poa_effective)
temp_cell = self._validate_per_array(temp_cell)
return tuple(
pvwatts_dc(g_poa_effective, temp_cell,
array.module_parameters['pdc0'],
array.module_parameters['gamma_pdc'],
**_build_kwargs(['temp_ref'], array.module_parameters))
for array, g_poa_effective, temp_cell
in zip(self.arrays, g_poa_effective, temp_cell)
)
def pvwatts_losses(self):
"""
Calculates DC power losses according the PVwatts model using
:py:func:`pvlib.pvsystem.pvwatts_losses` and
``self.losses_parameters``.
See :py:func:`pvlib.pvsystem.pvwatts_losses` for details.
"""
kwargs = _build_kwargs(['soiling', 'shading', 'snow', 'mismatch',
'wiring', 'connections', 'lid',
'nameplate_rating', 'age', 'availability'],
self.losses_parameters)
return pvwatts_losses(**kwargs)
@_unwrap_single_value
def dc_ohms_from_percent(self):
"""
Calculates the equivalent resistance of the wires for each array using
:py:func:`pvlib.pvsystem.dc_ohms_from_percent`
See :py:func:`pvlib.pvsystem.dc_ohms_from_percent` for details.
"""
return tuple(array.dc_ohms_from_percent() for array in self.arrays)
@property
def num_arrays(self):
"""The number of Arrays in the system."""
return len(self.arrays)
class Array:
"""
An Array is a set of modules at the same orientation.
Specifically, an array is defined by its mount, the
module parameters, the number of parallel strings of modules
and the number of modules on each string.
Parameters
----------
mount: FixedMount, SingleAxisTrackerMount, or other
Mounting for the array, either on fixed-tilt racking or horizontal
single axis tracker. Mounting is used to determine module orientation.
If not provided, a FixedMount with zero tilt is used.
albedo : float, optional
Ground surface albedo. If not supplied, then ``surface_type`` is used
to look up a value in :py:const:`pvlib.albedo.SURFACE_ALBEDOS`.
If ``surface_type`` is also not supplied then a ground surface albedo
of 0.25 is used.
surface_type : string, optional
The ground surface type. See :py:const:`pvlib.albedo.SURFACE_ALBEDOS`
for valid values.
module : string, optional
The model name of the modules.
May be used to look up the module_parameters dictionary
via some other method.
module_type : string, optional
Describes the module's construction. Valid strings are 'glass_polymer'
and 'glass_glass'. Used for cell and module temperature calculations.
module_parameters : dict or Series, optional
Parameters for the module model, e.g., SAPM, CEC, or other.
temperature_model_parameters : dict or Series, optional
Parameters for the module temperature model, e.g., SAPM, Pvsyst, or
other.
modules_per_string: int, default 1
Number of modules per string in the array.
strings: int, default 1
Number of parallel strings in the array.
array_losses_parameters : dict or Series, optional
Supported keys are 'dc_ohmic_percent'.
name : str, optional
Name of Array instance.
"""
def __init__(self, mount,
albedo=None, surface_type=None,
module=None, module_type=None,
module_parameters=None,
temperature_model_parameters=None,
modules_per_string=1, strings=1,
array_losses_parameters=None,
name=None):
self.mount = mount
self.surface_type = surface_type
if albedo is None:
self.albedo = pvlib.albedo.SURFACE_ALBEDOS.get(surface_type, 0.25)
else:
self.albedo = albedo
self.module = module
if module_parameters is None:
self.module_parameters = {}
else:
self.module_parameters = module_parameters
self.module_type = module_type
self.strings = strings
self.modules_per_string = modules_per_string
if temperature_model_parameters is None:
self.temperature_model_parameters = \
self._infer_temperature_model_params()
else:
self.temperature_model_parameters = temperature_model_parameters
if array_losses_parameters is None:
self.array_losses_parameters = {}
else:
self.array_losses_parameters = array_losses_parameters
self.name = name
def __repr__(self):
attrs = ['name', 'mount', 'module',
'albedo', 'module_type',
'temperature_model_parameters',
'strings', 'modules_per_string']
return 'Array:\n ' + '\n '.join(
f'{attr}: {getattr(self, attr)}' for attr in attrs
)
def _infer_temperature_model_params(self):
# try to infer temperature model parameters from racking_model
# and module_type