Skip to content

Commit

Permalink
Fix and document clearsky_model for ModelChain (#1924)
Browse files Browse the repository at this point in the history
* add note about clearsky_model

* whatsnew

* pass clearsky_model to get_clearsky

* add bug fix note

* test for correct argument

* test for correct argument

* test for correct argument
  • Loading branch information
cwhanse committed Dec 14, 2023
1 parent 304fbb5 commit ae84817
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/sphinx/source/whatsnew/v0.10.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Bug fixes
:py:func:`pvlib.iotools.get_cams` (:issue:`1799`, :pull:`1905`)
* Fix mapping of the dew point column to ``temp_dew`` when ``map_variables``
is True in :py:func:`pvlib.iotools.get_psm3`. (:pull:`1920`)
* Fix :py:class:`pvlib.modelchain.ModelChain` to use attribute `clearsky_model`
(:pull:`1924`)

Testing
~~~~~~~
Expand All @@ -34,6 +36,7 @@ Documentation
* Fixed a plotting issue in the IV curve gallery example (:pull:`1895`)
* Added two examples to demonstrate reverse transposition (:pull:`1907`)
* Fixed `detect_clearsky` example in `clearsky.rst` (:issue:`1914`)
* Clarified purpose of `ModelChain.clearsky_model` (:pull:`1924`)


Requirements
Expand All @@ -52,3 +55,4 @@ Contributors
* :ghuser:`matsuobasho`
* Harry Jack (:ghuser:`harry-solcast`)
* Kevin Anderson (:ghuser:`kandersolar`)
* Cliff Hansen (:ghuser:`cwhanse`)
6 changes: 4 additions & 2 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ class ModelChain:
the physical location at which to evaluate the model.
clearsky_model : str, default 'ineichen'
Passed to location.get_clearsky.
Passed to location.get_clearsky. Only used when DNI is not found in
the weather inputs.
transposition_model : str, default 'haydavies'
Passed to system.get_irradiance.
Expand Down Expand Up @@ -1354,7 +1355,8 @@ def _complete_irradiance(self, weather):
"https://github.com/pvlib/pvlib-python \n")
if {'ghi', 'dhi'} <= icolumns and 'dni' not in icolumns:
clearsky = self.location.get_clearsky(
weather.index, solar_position=self.results.solar_position)
weather.index, model=self.clearsky_model,
solar_position=self.results.solar_position)
complete_irrad_df = pvlib.irradiance.complete_irradiance(
solar_zenith=self.results.solar_position.zenith,
ghi=weather.ghi,
Expand Down
6 changes: 5 additions & 1 deletion pvlib/tests/test_modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ def test_complete_irradiance_clean_run(sapm_dc_snl_ac_system, location):
pd.Series([9, 5], index=times, name='ghi'))


def test_complete_irradiance(sapm_dc_snl_ac_system, location):
def test_complete_irradiance(sapm_dc_snl_ac_system, location, mocker):
"""Check calculations"""
mc = ModelChain(sapm_dc_snl_ac_system, location)
times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='H')
Expand All @@ -1867,7 +1867,11 @@ def test_complete_irradiance(sapm_dc_snl_ac_system, location):
pd.Series([372.103976116, 497.087579068],
index=times, name='ghi'))

# check that clearsky_model is used correctly
m_ineichen = mocker.spy(location, 'get_clearsky')
mc.complete_irradiance(i[['dhi', 'ghi']])
assert m_ineichen.call_count == 1
assert m_ineichen.call_args[1]['model'] == 'ineichen'
assert_series_equal(mc.results.weather['dni'],
pd.Series([49.756966, 62.153947],
index=times, name='dni'))
Expand Down

0 comments on commit ae84817

Please sign in to comment.