Skip to content

Commit

Permalink
1759 resolve attrib error model chain (pvlib#1947)
Browse files Browse the repository at this point in the history
* Remove or clause from if clause in infer_temperature_model in ModelChain

* Updated what's new

* Remove comment about removing or statement in infer_temperature_model in modelchain.py

* Added test to verify that error indicating inability to infer temperature model is raised when not providing temperature model to arrays

* Update docs/sphinx/source/whatsnew/v0.10.4.rst

Co-authored-by: Kevin Anderson <[email protected]>

* Update pvlib/tests/test_modelchain.py

---------

Co-authored-by: Kevin Anderson <[email protected]>
  • Loading branch information
matsuobasho and kandersolar authored Jan 23, 2024
1 parent b67a668 commit 477c923
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
5 changes: 3 additions & 2 deletions docs/sphinx/source/whatsnew/v0.10.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Enhancements

Bug fixes
~~~~~~~~~

* :py:class:`~pvlib.modelchain.ModelChain` now raises a more useful error when
``temperature_model_parameters`` are specified on the passed ``system`` instead of on its ``arrays``. (:issue:`1759`).

Testing
~~~~~~~
Expand All @@ -27,4 +28,4 @@ Requirements

Contributors
~~~~~~~~~~~~

* :ghuser:`matsuobasho`
5 changes: 1 addition & 4 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,10 +1117,7 @@ def infer_temperature_model(self):
temperature_model_parameters = tuple(
array.temperature_model_parameters for array in self.system.arrays)
params = _common_keys(temperature_model_parameters)
# remove or statement in v0.9
if {'a', 'b', 'deltaT'} <= params or (
not params and self.system.racking_model is None
and self.system.module_type is None):
if {'a', 'b', 'deltaT'} <= params:
return self.sapm_temp
elif {'u_c', 'u_v'} <= params:
return self.pvsyst_temp
Expand Down
16 changes: 16 additions & 0 deletions pvlib/tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,22 @@ def test_temperature_model_inconsistent(location, sapm_dc_snl_ac_system):
spectral_model='no_loss', temperature_model='pvsyst')


def test_temperature_model_not_specified():
# GH 1759 -- ensure correct error is raised when temperature model params
# are specified on the PVSystem instead of the Arrays
location = Location(latitude=32.2, longitude=-110.9)
arrays = [pvsystem.Array(pvsystem.FixedMount(),
module_parameters={'pdc0': 1, 'gamma_pdc': 0})]
system = pvsystem.PVSystem(arrays,
temperature_model_parameters={'u0': 1, 'u1': 1},
inverter_parameters={'pdc0': 1})
with pytest.raises(ValueError,
match='could not infer temperature model '
'from system.temperature_model_parameters'):
_ = ModelChain(system, location,
aoi_model='no_loss', spectral_model='no_loss')


def test_dc_model_user_func(pvwatts_dc_pvwatts_ac_system, location, weather,
mocker):
m = mocker.spy(sys.modules[__name__], 'poadc')
Expand Down

0 comments on commit 477c923

Please sign in to comment.