29
29
30
30
# Optional keys to communicate temperature data. If provided,
31
31
# 'cell_temperature' overrides ModelChain.temperature_model and sets
32
- # ModelChain.cell_temperature to the data. If 'module_temperature' is provdied ,
32
+ # ModelChain.cell_temperature to the data. If 'module_temperature' is provided ,
33
33
# overrides ModelChain.temperature_model with
34
34
# pvlib.temperature.sapm_celL_from_module
35
35
TEMPERATURE_KEYS = ('module_temperature' , 'cell_temperature' )
@@ -253,7 +253,7 @@ def __repr__(self):
253
253
def _head (obj ):
254
254
try :
255
255
return obj [:3 ]
256
- except :
256
+ except Exception :
257
257
return obj
258
258
259
259
if type (self .dc ) is tuple :
@@ -269,7 +269,7 @@ def _head(obj):
269
269
'\n ' )
270
270
lines = []
271
271
for attr in mc_attrs :
272
- if not (attr .startswith ('_' ) or attr == 'times' ):
272
+ if not (attr .startswith ('_' ) or attr == 'times' ):
273
273
lines .append (f' { attr } : ' + _mcr_repr (getattr (self , attr )))
274
274
desc4 = '\n ' .join (lines )
275
275
return (desc1 + desc2 + desc3 + desc4 )
@@ -330,12 +330,15 @@ class ModelChain:
330
330
'interp' and 'no_loss'. The ModelChain instance will be passed as the
331
331
first argument to a user-defined function.
332
332
333
- spectral_model : str, or function, optional
334
- If not specified, the model will be inferred from the parameters that
335
- are common to all of system.arrays[i].module_parameters.
336
- Valid strings are 'sapm', 'first_solar', 'no_loss'.
333
+ spectral_model : str or function, optional
334
+ Valid strings are:
335
+
336
+ - ``'sapm'``
337
+ - ``'first_solar'``
338
+ - ``'no_loss'``
339
+
337
340
The ModelChain instance will be passed as the first argument to
338
- a user-defined function.
341
+ a user-defined function. If not specified, ``'no_loss'`` is assumed.
339
342
340
343
temperature_model : str or function, optional
341
344
Valid strings are: 'sapm', 'pvsyst', 'faiman', 'fuentes', 'noct_sam'.
@@ -386,7 +389,6 @@ def __init__(self, system, location,
386
389
387
390
self .results = ModelChainResult ()
388
391
389
-
390
392
@classmethod
391
393
def with_pvwatts (cls , system , location ,
392
394
clearsky_model = 'ineichen' ,
@@ -855,9 +857,7 @@ def spectral_model(self):
855
857
856
858
@spectral_model .setter
857
859
def spectral_model (self , model ):
858
- if model is None :
859
- self ._spectral_model = self .infer_spectral_model ()
860
- elif isinstance (model , str ):
860
+ if isinstance (model , str ):
861
861
model = model .lower ()
862
862
if model == 'first_solar' :
863
863
self ._spectral_model = self .first_solar_spectral_loss
@@ -867,30 +867,12 @@ def spectral_model(self, model):
867
867
self ._spectral_model = self .no_spectral_loss
868
868
else :
869
869
raise ValueError (model + ' is not a valid spectral loss model' )
870
- else :
870
+ elif model is None :
871
+ # not setting a model is equivalent to setting no_loss
872
+ self ._spectral_model = self .no_spectral_loss
873
+ else : # assume model is callable with 1st argument = the MC instance
871
874
self ._spectral_model = partial (model , self )
872
875
873
- def infer_spectral_model (self ):
874
- """Infer spectral model from system attributes."""
875
- module_parameters = tuple (
876
- array .module_parameters for array in self .system .arrays )
877
- params = _common_keys (module_parameters )
878
- if {'A4' , 'A3' , 'A2' , 'A1' , 'A0' } <= params :
879
- return self .sapm_spectral_loss
880
- elif ((('Technology' in params or
881
- 'Material' in params ) and
882
- (self .system ._infer_cell_type () is not None )) or
883
- 'first_solar_spectral_coefficients' in params ):
884
- return self .first_solar_spectral_loss
885
- else :
886
- raise ValueError ('could not infer spectral model from '
887
- 'system.arrays[i].module_parameters. Check that '
888
- 'the module_parameters for all Arrays in '
889
- 'system.arrays contain valid '
890
- 'first_solar_spectral_coefficients, a valid '
891
- 'Material or Technology value, or set '
892
- 'spectral_model="no_loss".' )
893
-
894
876
def first_solar_spectral_loss (self ):
895
877
self .results .spectral_modifier = self .system .first_solar_spectral_loss (
896
878
_tuple_from_dfs (self .results .weather , 'precipitable_water' ),
@@ -1570,7 +1552,7 @@ def _prepare_temperature(self, data):
1570
1552
----------
1571
1553
data : DataFrame
1572
1554
May contain columns ``'cell_temperature'`` or
1573
- ``'module_temperaure '``.
1555
+ ``'module_temperature '``.
1574
1556
1575
1557
Returns
1576
1558
-------
@@ -1679,6 +1661,7 @@ def run_model(self, weather):
1679
1661
self .prepare_inputs (weather )
1680
1662
self .aoi_model ()
1681
1663
self .spectral_model ()
1664
+
1682
1665
self .effective_irradiance_model ()
1683
1666
1684
1667
self ._run_from_effective_irrad (weather )
0 commit comments