Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2b08efb
added perez modelchain example
bgpierc Jul 30, 2024
d86441d
formatting
bgpierc Jul 30, 2024
a34e797
cleaned up
bgpierc Jul 30, 2024
4196d54
linter
bgpierc Jul 30, 2024
6b2f57c
linter 2
bgpierc Jul 30, 2024
7aad3da
added whatsnew
bgpierc Jul 30, 2024
ef6ef60
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 1, 2024
7d8d6d3
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 1, 2024
c7b472e
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 1, 2024
dc670fd
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 1, 2024
814454d
added plt tight layout
bgpierc Aug 1, 2024
8f8a937
added plt tight layout
bgpierc Aug 1, 2024
6dbe662
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 5, 2024
d29e8f5
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 5, 2024
a9653d2
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 5, 2024
156194c
linter
bgpierc Aug 5, 2024
01c7125
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 15, 2024
fa6169c
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 15, 2024
2e370e7
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 15, 2024
c5cde3a
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 15, 2024
35cf150
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc Aug 15, 2024
417053b
broke up large code block
bgpierc Aug 15, 2024
0d0db58
Merge branch 'main' into perez_coeff_example
kandersolar Aug 15, 2024
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
123 changes: 123 additions & 0 deletions docs/examples/irradiance-transposition/use_perez_modelchain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""
Use different Perez coefficients with the ModelChain
====================================================

This example demonstrates how to customize the ModelChain
to use site-specifc Perez coefficients.
"""

# %%
# The :py:class:`pvlib.modelchain.ModelChain` object provides a useful method
# for easily constructing a model with a simple, unified interface.
# However, a user may want to customize their models in various ways.
# One such example is during the irradiance transposition step.
# The Perez models perform very well on field data, but
# they require a set of fitted coefficients from various sites.
# It has been noted that these coefficients can be specific to
# various climates, so users may see a boost in model performance
# when using the correct set of parameters.
# However, the base :py:class:`~pvlib.modelchain.ModelChain`
# only supports the default coefficients.
# This example shows how the :py:class:`~pvlib.modelchain.ModelChain` can
# be adjusted to use a different set of Perez coefficients.

import pandas as pd
from pvlib.pvsystem import PVSystem
from pvlib.modelchain import ModelChain
from pvlib.temperature import TEMPERATURE_MODEL_PARAMETERS
from pvlib import iotools, location, irradiance
import pvlib
import os
import matplotlib.pyplot as plt

# load in TMY weather data from North Carolina included with pvlib
PVLIB_DIR = pvlib.__path__[0]
DATA_FILE = os.path.join(PVLIB_DIR, 'data', '723170TYA.CSV')

tmy, metadata = iotools.read_tmy3(DATA_FILE, coerce_year=1990,
map_variables=True)

weather_data = pd.DataFrame({'ghi': tmy['ghi'], 'dhi': tmy['dhi'],
'dni': tmy['dni'],
'temp_air': tmy['temp_air'],
'wind_speed': tmy['wind_speed']})

loc = location.Location.from_tmy(metadata)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined to break the code block in two at this point, just to make it less overwhelming to users. This can be done by adding in a sentence saying something like "Next, we set up a standard PV model using ModelChain".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agreed, done

surface_tilt = metadata['latitude']
surface_azimuth = 180

# define an example module and inverter
sandia_modules = pvlib.pvsystem.retrieve_sam('SandiaMod')
cec_inverters = pvlib.pvsystem.retrieve_sam('cecinverter')
sandia_module = sandia_modules['Canadian_Solar_CS5P_220M___2009_']
cec_inverter = cec_inverters['ABB__MICRO_0_25_I_OUTD_US_208__208V_']

temp_params = TEMPERATURE_MODEL_PARAMETERS['sapm']['open_rack_glass_glass']

# define the system and ModelChain
system = PVSystem(arrays=None,
surface_tilt=surface_tilt,
surface_azimuth=surface_azimuth,
module_parameters=sandia_module,
inverter_parameters=cec_inverter,
temperature_model_parameters=temp_params)

mc = ModelChain(system, location=loc)

# %%
# Now, let's calculate POA irradiance values outside of the ``ModelChain``.
# We do this for both the default Perez coefficients and the desired
# alternative Perez coefficients. This enables comparison at the end.

# Cape Canaveral seems like the most likely match for climate
model_perez = 'capecanaveral1988'

solar_position = loc.get_solarposition(times=weather_data.index)
dni_extra = irradiance.get_extra_radiation(weather_data.index)

POA_irradiance = irradiance.get_total_irradiance(
surface_tilt=surface_tilt,
surface_azimuth=surface_azimuth,
dni=weather_data['dni'],
ghi=weather_data['ghi'],
dhi=weather_data['dhi'],
solar_zenith=solar_position['apparent_zenith'],
solar_azimuth=solar_position['azimuth'],
model='perez',
dni_extra=dni_extra)

POA_irradiance_new_perez = irradiance.get_total_irradiance(
surface_tilt=surface_tilt,
surface_azimuth=surface_azimuth,
dni=weather_data['dni'],
ghi=weather_data['ghi'],
dhi=weather_data['dhi'],
solar_zenith=solar_position['apparent_zenith'],
solar_azimuth=solar_position['azimuth'],
model='perez',
model_perez=model_perez,
dni_extra=dni_extra)

# %%
# Now, run the ``ModelChain`` with both sets of irradiance data and compare:

mc.run_model_from_poa(POA_irradiance)
ac_power_default = mc.results.ac

mc.run_model_from_poa(POA_irradiance_new_perez)
ac_power_new_perez = mc.results.ac

start, stop = '1990-05-05 06:00:00', '1990-05-05 19:00:00'
plt.plot(ac_power_default.loc[start:stop],
label="Default Composite Perez Model")
plt.plot(ac_power_new_perez.loc[start:stop],
label="Cape Canaveral Perez Model")
plt.xticks(rotation=90)
plt.ylabel("AC Power ($W$)")
plt.legend()
plt.tight_layout()
plt.show()
# %%
# Note that there is a small, but noticeable difference from the default
# coefficients that may add up over longer periods of time.
6 changes: 6 additions & 0 deletions docs/sphinx/source/whatsnew/v0.11.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ Documentation
* Added gallery example on calculating cell temperature for
floating PV. (:pull:`2110`)

* Added gallery example demonstrating how to use
different Perez coefficients in a ModelChain.
(:issue:`2127`, :pull:`2148`)


Requirements
~~~~~~~~~~~~

Expand All @@ -45,4 +50,5 @@ Contributors
* Leonardo Micheli (:ghuser:`lmicheli`)
* Echedey Luis (:ghuser:`echedey-ls`)
* Rajiv Daxini (:ghuser:`RDaxini`)
* Ben Pierce (:ghuser:`bgpierc`)

Loading