8000 deprecate clear sky default in modelchain (#710) · midwest88/pvlib-python@252c1b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 252c1b2

Browse files
authored
deprecate clear sky default in modelchain (pvlib#710)
* remove clear sky default from modelchain * compat with 27min * stickler * typos
1 parent 6946ef1 commit 252c1b2

File tree

6 files changed

+65
-36
lines changed

6 files changed

+65
-36
lines changed

docs/sphinx/source/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ Transposition models
170170
irradiance.reindl
171171
irradiance.king
172172

173+
.. _dniestmodels:
174+
173175
DNI estimation models
174176
---------------------
175177

docs/sphinx/source/introexamples.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,13 @@ The following code demonstrates how to use
134134
:py:class:`~pvlib.modelchain.ModelChain` objects to accomplish our
135135
system modeling goal. ModelChain objects provide convenience methods
136136
that can provide default selections for models and can also fill
137-
necessary input data with modeled data. In our example below, we use
138-
convenience methods. For example, no irradiance data is provided as
139-
input, so the ModelChain object substitutes irradiance from a clear-sky
140-
model via the prepare_inputs method. Also, no irradiance transposition
141-
model is specified (keyword argument `transposition` for ModelChain) so
142-
the ModelChain defaults to the `haydavies` model. In this example,
143-
ModelChain infers the DC power model from the module provided by
144-
examining the parameters defined for module.
137+
necessary input with modeled data. For example, no air temperature
138+
or wind speed data is provided in the input *weather* DataFrame,
139+
so the ModelChain object defaults to 20 C and 0 m/s. Also, no irradiance
140+
transposition model is specified (keyword argument `transposition` for
141+
ModelChain) so the ModelChain defaults to the `haydavies` model. In this
142+
example, ModelChain infers the DC power model from the module provided
143+
by examining the parameters defined for the module.
145144

146145
.. ipython:: python
147146
@@ -157,12 +156,12 @@ examining the parameters defined for module.
157156
times = naive_times.tz_localize(timezone)
158157
location = Location(latitude, longitude, name=name, altitude=altitude,
159158
tz=timezone)
160-
# very experimental
159+
weather = location.get_clearsky(times)
161160
mc = ModelChain(system, location,
162161
orientation_strategy='south_at_latitude_tilt')
163162
# model results (ac, dc) and intermediates (aoi, temps, etc.)
164163
# assigned as mc object attributes
165-
mc.run_model(times)
164+
mc.run_model(times=times, weather=weather)
166165
annual_energy = mc.ac.sum()
167166
energies[name] = annual_energy
168167

docs/sphinx/source/modelchain.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Modeling with a :py:class:`~.ModelChain` typically involves 3 steps:
2424
1. Creating the :py:class:`~.ModelChain`.
2525
2. Executing the :py:meth:`ModelChain.run_model() <.ModelChain.run_model>`
2626
method with prepared weather data.
27-
3. Examining the model results that :py:meth:`~.ModelChain.run_model` stored in attributes of the :py:class:`~.ModelChain`.
27+
3. Examining the model results that :py:meth:`~.ModelChain.run_model`
28+
stored in attributes of the :py:class:`~.ModelChain`.
2829

2930
A simple ModelChain example
3031
---------------------------
@@ -212,8 +213,13 @@ method, :py:meth:`~pvlib.modelchain.ModelChain.prepare_inputs`, computes
212213
parameters such as solar position, airmass, angle of incidence, and
213214
plane of array irradiance. The
214215
:py:meth:`~pvlib.modelchain.ModelChain.prepare_inputs` method also
215-
assigns default values for irradiance (clear sky), temperature (20 C),
216+
assigns default values for temperature (20 C)
216217
and wind speed (0 m/s) if these inputs are not provided.
218+
:py:meth:`~pvlib.modelchain.ModelChain.prepare_inputs` requires all irradiance
219+
components (GHI, DNI, and DHI). See
220+
:py:meth:`~pvlib.modelchain.ModelChain.complete_irradiance` and
221+
:ref:`dniestmodels` for methods and functions that can help fully define
222+
the irradiance inputs.
217223

218224
Next, :py:meth:`~pvlib.modelchain.ModelChain.run_model` calls the
219225
wrapper methods for AOI loss, spectral loss, effective irradiance, cell

docs/sphinx/source/whatsnew/v0.6.2.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ API Changes
2323
*ghi* or *zenith*.
2424
* Added *min_cos_zenith* and *max_zenith* keyword arguments to
2525
:py:func:`~pvlib.irradiance.erbs`. (:issue:`681`)
26+
* Deprecated :py:meth:`~pvlib.modelchain.ModelChain.prepare_inputs`
27+
assumption of clear sky if no irradiance fields were provided.
28+
(:issue:`705`, :issue:`707`)
2629

2730
Enhancements
2831
~~~~~~~~~~~~

pvlib/modelchain.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -810,19 +810,20 @@ def prepare_inputs(self, times=None, weather=None):
810810
Times at which to evaluate the model. Can be None if
811811
attribute `times` is already set.
812812
weather : None or DataFrame, default None
813-
If ``None``, the weather attribute is used. If the weather
814-
attribute is also ``None`` assumes air temperature is 20 C, wind
815-
speed is 0 m/s and irradiation calculated from clear sky
816-
data. Column names must be ``'wind_speed'``, ``'temp_air'``,
817-
``'dni'``, ``'ghi'``, ``'dhi'``. Do not pass incomplete irradiation
818-
data. Use method
819-
:py:meth:`~pvlib.modelchain.ModelChain.complete_irradiance`
820-
instead.
813+
If ``None``, the weather attribute is used. Column names
814+
must be ``'dni'``, ``'ghi'``, ``'dhi'``, ``'wind_speed'``,
815+
``'temp_air'``. All irradiance components are required.
816+
Assumes air temperature is 20 C and wind speed is 0 m/s if
817+
not provided.
821818
822819
Notes
823820
-----
824821
Assigns attributes: ``times``, ``solar_position``, ``airmass``,
825822
``total_irrad``, `aoi`
823+
824+
See also
825+
--------
826+
ModelChain.complete_irradiance
826827
"""
827828
if weather is not None:
828829
self.weather = weather
@@ -839,15 +840,19 @@ def prepare_inputs(self, times=None, weather=None):
839840
solar_position=self.solar_position, model=self.airmass_model)
840841

841842
if not any([x in ['ghi', 'dni', 'dhi'] for x in self.weather.columns]):
843+
warnings.warn('Clear sky assumption for no input irradiance is '
844+
'deprecated and will be removed in v0.7.0. Use '
845+
'location.get_clearsky instead',
846+
pvlibDeprecationWarning)
842847
self.weather[['ghi', 'dni', 'dhi']] = self.location.get_clearsky(
843848
self.solar_position.index, self.clearsky_model,
844849
solar_position=self.solar_position,
845850
airmass_absolute=self.airmass['airmass_absolute'])
846851

847852
if not {'ghi', 'dni', 'dhi'} <= set(self.weather.columns):
848853
raise ValueError(
849-
"Uncompleted irradiance data set. Please check you input " +
850-
"data.\nData set needs to have 'dni', 'dhi' and 'ghi'.\n" +
854+
"Uncompleted irradiance data set. Please check your input "
855+
"data.\nData set needs to have 'dni', 'dhi' and 'ghi'.\n"
851856
"Detected data: {0}".format(list(self.weather.columns)))
852857

853858
# PVSystem.get_irradiance and SingleAxisTracker.get_irradiance
@@ -903,12 +908,11 @@ def run_model(self, times=None, weather=None):
903908
Times at which to evaluate the model. Can be None if
904909
attribute `times` is already set.
905910
weather : None or DataFrame, default None
906-
If None, assumes air temperature is 20 C, wind speed is 0
907-
m/s and irradiation calculated from clear sky data. Column
908-
names must be 'wind_speed', 'temp_air', 'dni', 'ghi', 'dhi'.
909-
Do not pass incomplete irradiation data. Use method
910-
:py:meth:`~pvlib.modelchain.ModelChain.complete_irradiance`
911-
instead.
911+
If ``None``, the weather attribute is used. Column names
912+
must be ``'dni'``, ``'ghi'``, ``'dhi'``, ``'wind_speed'``,
913+
``'temp_air'``. All irradiance components are required.
914+
Assumes air temperature is 20 C and wind speed is 0 m/s if
915+
not provided.
912916
913917
Returns
914918
-------

pvlib/test/test_modelchain.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import pytest
2020

2121
from test_pvsystem import sam_data, pvsyst_module_params
22-
from conftest import fail_on_pvlib_version, requires_scipy
22+
from conftest import fail_on_pvlib_version, requires_scipy, requires_tables
2323

2424

2525
@pytest.fixture
@@ -153,7 +153,9 @@ def test_orientation_strategy(strategy, expected, system, location):
153153
def test_run_model(system, location):
154154
mc = ModelChain(system, location)
155155
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
156-
ac = mc.run_model(times).ac
156+
157+
with pytest.warns(pvlibDeprecationWarning):
158+
ac = mc.run_model(times).ac
157159

158160
expected = pd.Series(np.array([ 183.522449305, -2.00000000e-02]),
159161
index=times)
@@ -374,14 +376,12 @@ def constant_spectral_loss(mc):
374376
@pytest.mark.parametrize('spectral_model', [
375377
'sapm', 'first_solar', 'no_loss', constant_spectral_loss
376378
])
377-
def test_spectral_models(system, location, spectral_model):
378-
times = pd.date_range('20160101 1200-0700', periods=3, freq='6H')
379-
weather = pd.DataFrame(data=[0.3, 0.5, 1.0],
380-
index=times,
381-
columns=['precipitable_water'])
379+
def test_spectral_models(system, location, spectral_model, weather):
380+
# add pw to weather dataframe
381+
weather['precipitable_water'] = [0.3, 0.5]
382382
mc = ModelChain(system, location, dc_model='sapm',
383383
aoi_model='no_loss', spectral_model=spectral_model)
384-
spectral_modifier = mc.run_model(times=times,
384+
spectral_modifier = mc.run_model(times=weather.index,
385385
weather=weather).spectral_modifier
386386
assert isinstance(spectral_modifier, (pd.Series, float, int))
387387

@@ -493,6 +493,21 @@ def test_deprecated_07():
493493
ac_model='snlinverter')
494494

495495

496+
@requires_tables
497+
@fail_on_pvlib_version('0.7')
498+
def test_deprecated_clearsky_07():
499+
# explicit system creation call because fail_on_pvlib_version
500+
# does not support decorators.
501+
system = PVSystem(module_parameters={'pdc0': 1, 'gamma_pdc': -0.003})
502+
location = Location(32.2, -110.9)
503+
mc = ModelChain(system, location, dc_model='pvwatts', ac_model='pvwatts',
504+
aoi_model='no_loss', spectral_model='no_loss')
505+
times = pd.date_range(start='20160101 1200-0700',
506+
end='20160101 1800-0700', freq='6H')
507+
with pytest.warns(pvlibDeprecationWarning):
508+
mc.prepare_inputs(times=times)
509+
510+
496511
@requires_scipy
497512
def test_basic_chain_required(sam_data):
498513
times = pd.date_range(start='20160101 1200-0700',

0 commit comments

Comments
 (0)
0