Skip to content

Commit 0428fbe

Browse files
bgpierckandersolarcwhanseAdamRJensen
authored
Perez coeff ModelChain example (#2148)
* added perez modelchain example * formatting * cleaned up * linter * linter 2 * added whatsnew * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Kevin Anderson <[email protected]> * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Kevin Anderson <[email protected]> * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Kevin Anderson <[email protected]> * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Kevin Anderson <[email protected]> * added plt tight layout * added plt tight layout * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Cliff Hansen <[email protected]> * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Cliff Hansen <[email protected]> * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Cliff Hansen <[email protected]> * linter * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Adam R. Jensen <[email protected]> * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Adam R. Jensen <[email protected]> * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Adam R. Jensen <[email protected]> * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Adam R. Jensen <[email protected]> * Update docs/examples/irradiance-transposition/use_perez_modelchain.py Co-authored-by: Adam R. Jensen <[email protected]> * broke up large code block --------- Co-authored-by: Kevin Anderson <[email protected]> Co-authored-by: Cliff Hansen <[email protected]> Co-authored-by: Adam R. Jensen <[email protected]>
1 parent cd9cb9a commit 0428fbe

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
"""
2+
Use different Perez coefficients with the ModelChain
3+
====================================================
4+
5+
This example demonstrates how to customize the ModelChain
6+
to use site-specific Perez transposition coefficients.
7+
"""
8+
9+
# %%
10+
# The :py:class:`pvlib.modelchain.ModelChain` object provides a useful method
11+
# for easily constructing a PV system model with a simple, unified interface.
12+
# However, a user may want to customize the steps
13+
# in the system model in various ways.
14+
# One such example is during the irradiance transposition step.
15+
# The Perez model perform very well on field data, but
16+
# it requires a set of fitted coefficients from various sites.
17+
# It has been noted that these coefficients can be specific to
18+
# various climates, so users may see improved model accuracy
19+
# when using a site-specific set of coefficients.
20+
# However, the base :py:class:`~pvlib.modelchain.ModelChain`
21+
# only supports the default coefficients.
22+
# This example shows how the :py:class:`~pvlib.modelchain.ModelChain` can
23+
# be adjusted to use a different set of Perez coefficients.
24+
25+
import pandas as pd
26+
from pvlib.pvsystem import PVSystem
27+
from pvlib.modelchain import ModelChain
28+
from pvlib.temperature import TEMPERATURE_MODEL_PARAMETERS
29+
from pvlib import iotools, location, irradiance
30+
import pvlib
31+
import os
32+
import matplotlib.pyplot as plt
33+
34+
# load in TMY weather data from North Carolina included with pvlib
35+
PVLIB_DIR = pvlib.__path__[0]
36+
DATA_FILE = os.path.join(PVLIB_DIR, 'data', '723170TYA.CSV')
37+
38+
tmy, metadata = iotools.read_tmy3(DATA_FILE, coerce_year=1990,
39+
map_variables=True)
40+
41+
weather_data = tmy[['ghi', 'dhi', 'dni', 'temp_air', 'wind_speed']]
42+
43+
loc = location.Location.from_tmy(metadata)
44+
45+
#%%
46+
# Now, let's set up a standard PV model using the ``ModelChain``
47+
48+
surface_tilt = metadata['latitude']
49+
surface_azimuth = 180
50+
51+
# define an example module and inverter
52+
sandia_modules = pvlib.pvsystem.retrieve_sam('SandiaMod')
53+
cec_inverters = pvlib.pvsystem.retrieve_sam('cecinverter')
54+
sandia_module = sandia_modules['Canadian_Solar_CS5P_220M___2009_']
55+
cec_inverter = cec_inverters['ABB__MICRO_0_25_I_OUTD_US_208__208V_']
56+
57+
temp_params = TEMPERATURE_MODEL_PARAMETERS['sapm']['open_rack_glass_glass']
58+
59+
# define the system and ModelChain
60+
system = PVSystem(arrays=None,
61+
surface_tilt=surface_tilt,
62+
surface_azimuth=surface_azimuth,
63+
module_parameters=sandia_module,
64+
inverter_parameters=cec_inverter,
65+
temperature_model_parameters=temp_params)
66+
67+
mc = ModelChain(system, location=loc)
68+
69+
# %%
70+
# Now, let's calculate POA irradiance values outside of the ``ModelChain``.
71+
# We do this for both the default Perez coefficients and the desired
72+
# alternative Perez coefficients. This enables comparison at the end.
73+
74+
# Cape Canaveral seems like the most likely match for climate
75+
model_perez = 'capecanaveral1988'
76+
77+
solar_position = loc.get_solarposition(times=weather_data.index)
78+
dni_extra = irradiance.get_extra_radiation(weather_data.index)
79+
80+
POA_irradiance = irradiance.get_total_irradiance(
81+
surface_tilt=surface_tilt,
82+
surface_azimuth=surface_azimuth,
83+
dni=weather_data['dni'],
84+
ghi=weather_data['ghi'],
85+
dhi=weather_data['dhi'],
86+
solar_zenith=solar_position['apparent_zenith'],
87+
solar_azimuth=solar_position['azimuth'],
88+
model='perez',
89+
dni_extra=dni_extra)
90+
91+
POA_irradiance_new_perez = irradiance.get_total_irradiance(
92+
surface_tilt=surface_tilt,
93+
surface_azimuth=surface_azimuth,
94+
dni=weather_data['dni'],
95+
ghi=weather_data['ghi'],
96+
dhi=weather_data['dhi'],
97+
solar_zenith=solar_position['apparent_zenith'],
98+
solar_azimuth=solar_position['azimuth'],
99+
model='perez',
100+
model_perez=model_perez,
101+
dni_extra=dni_extra)
102+
103+
# %%
104+
# Now, run the ``ModelChain`` with both sets of irradiance data and compare
105+
# (note that to use POA irradiance as input to the ModelChain the method
106+
# `.run_model_from_poa` is used):
107+
108+
mc.run_model_from_poa(POA_irradiance)
109+
ac_power_default = mc.results.ac
110+
111+
mc.run_model_from_poa(POA_irradiance_new_perez)
112+
ac_power_new_perez = mc.results.ac
113+
114+
start, stop = '1990-05-05 06:00:00', '1990-05-05 19:00:00'
115+
plt.plot(ac_power_default.loc[start:stop],
116+
label="Default Composite Perez Model")
117+
plt.plot(ac_power_new_perez.loc[start:stop],
118+
label="Cape Canaveral Perez Model")
119+
plt.xticks(rotation=90)
120+
plt.ylabel("AC Power ($W$)")
121+
plt.legend()
122+
plt.tight_layout()
123+
plt.show()
124+
# %%
125+
# Note that there is a small, but noticeable difference from the default
126+
# coefficients that may add up over longer periods of time.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Documentation
4444
* Added gallery example on calculating cell temperature for
4545
floating PV. (:pull:`2110`)
4646

47+
* Added gallery example demonstrating how to use
48+
different Perez coefficients in a ModelChain.
49+
(:issue:`2127`, :pull:`2148`)
50+
4751
* Removed unused "times" input from dni_et() function (:issue:`2105`)
4852

4953
Requirements
@@ -58,4 +62,5 @@ Contributors
5862
* Leonardo Micheli (:ghuser:`lmicheli`)
5963
* Echedey Luis (:ghuser:`echedey-ls`)
6064
* Rajiv Daxini (:ghuser:`RDaxini`)
65+
* Ben Pierce (:ghuser:`bgpierc`)
6166
* Jose Meza (:ghuser:`JoseMezaMendieta`)

0 commit comments

Comments
 (0)