Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 68 additions & 17 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,33 @@

from pvlib._deprecation import deprecated

# keys that are used to detect input data and assign data to appropriate
# ModelChain attribute
# for ModelChain.weather
WEATHER_KEYS = ('ghi', 'dhi', 'dni', 'wind_speed', 'temp_air',
'precipitable_water')

# for ModelChain.total_irrad
POA_KEYS = ('poa_global', 'poa_direct', 'poa_diffuse')

# Optional keys to communicate temperature data. If provided,
# 'cell_temperature' overrides ModelChain.temperature_model and sets
# ModelChain.cell_temperature to the data. If 'module_temperature' is provided,
# overrides ModelChain.temperature_model with
# pvlib.temperature.sapm_cell_from_module
TEMPERATURE_KEYS = ('module_temperature', 'cell_temperature')
# Keys used to detect input data and assign values to the appropriate
# ModelChain attributes.

# Weather-related input columns for ModelChain.weather
WEATHER_KEYS = (
'ghi', # Global Horizontal Irradiance (W/m^2)
'dhi', # Diffuse Horizontal Irradiance (W/m^2)
'dni', # Direct Normal Irradiance (W/m^2)
'wind_speed', # Wind speed (m/s)
'temp_air', # Ambient air temperature (°C)
'precipitable_water' # Column precipitable water (cm)
)

# Plane-of-array irradiance input columns for ModelChain.total_irrad
POA_KEYS = (
'poa_global', # Total plane-of-array irradiance (W/m^2)
'poa_direct', # Direct POA irradiance (W/m^2)
'poa_diffuse' # Diffuse POA irradiance (W/m^2)
)

# Temperature-related optional input columns for ModelChain
TEMPERATURE_KEYS = (
'module_temperature', # Back-surface module temperature (°C)
'cell_temperature', # Direct cell temperature input (°C)
)

# All supported input keys combined
DATA_KEYS = WEATHER_KEYS + POA_KEYS + TEMPERATURE_KEYS

# these dictionaries contain the default configuration for following
Expand Down Expand Up @@ -1713,6 +1724,27 @@ def run_model_from_poa(self, data):
of Arrays in the PVSystem.
ValueError
If the DataFrames in `data` have different indexes.
Examples
--------
Single-array system:

>>> import pandas as pd
>>> from pvlib.pvsystem import PVSystem
>>> from pvlib.location import Location
>>> from pvlib.modelchain import ModelChain
>>>
>>> system = PVSystem(module_parameters={'pdc0': 300})
>>> location = Location(35, -110)
>>> mc = ModelChain(system, location)
>>>
>>> poa = pd.DataFrame({
... 'poa_global': [900, 850],
... 'poa_direct': [600, 560],
... 'poa_diffuse': [300, 290],
... }, index=pd.date_range("2021-06-01", periods=2, freq="H"))
>>>
>>> mc.run_model_from_poa(poa)
<pvlib.modelchain.ModelChain ...>

Notes
-----
Expand All @@ -1738,7 +1770,6 @@ def run_model_from_poa(self, data):
self._run_from_effective_irrad(data)

return self

def _run_from_effective_irrad(self, data):
"""
Executes the temperature, DC, losses and AC models.
Expand All @@ -1757,7 +1788,7 @@ def _run_from_effective_irrad(self, data):

Notes
-----
Assigns attributes:``cell_temperature``, ``dc``, ``ac``, ``losses``,
Assigns attributes:``cell_temperature, 'dc', ``ac', ``losses``,
``diode_params`` (if dc_model is a single diode model).
"""
self._prepare_temperature(data)
Expand Down Expand Up @@ -1798,6 +1829,25 @@ def run_model_from_effective_irradiance(self, data):
of Arrays in the PVSystem.
ValueError
If the DataFrames in `data` have different indexes.
Examples
--------
>>> import pandas as pd
>>> from pvlib.pvsystem import PVSystem
>>> from pvlib.location import Location
>>> from pvlib.modelchain import ModelChain
>>>
>>> system = PVSystem(module_parameters={'pdc0': 300})
>>> location = Location(35, -110)
>>> mc = ModelChain(system, location)
>>>
>>> eff = pd.DataFrame({
... 'effective_irradiance': [900, 920],
... 'temp_air': [25, 24],
... 'wind_speed': [2.0, 1.5],
... })
>>>
>>> mc.run_model_from_effective_irradiance(eff)
<pvlib.modelchain.ModelChain ...>

Notes
-----
Expand Down Expand Up @@ -1836,6 +1886,7 @@ def run_model_from_effective_irradiance(self, data):
return self



def _irrad_for_celltemp(total_irrad, effective_irradiance):
"""
Determine irradiance to use for cell temperature models, in order
Expand Down