-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Perez coeff ModelChain example #2148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
2b08efb
d86441d
a34e797
4196d54
6b2f57c
7aad3da
ef6ef60
7d8d6d3
c7b472e
dc670fd
814454d
8f8a937
6dbe662
d29e8f5
a9653d2
156194c
01c7125
fa6169c
2e370e7
c5cde3a
35cf150
417053b
0d0db58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
bgpierc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# One such example is during the irradiance transposition step. | ||
# The Perez models perform very well on field data, but | ||
bgpierc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# they require a set of fitted coefficients from various sites. | ||
bgpierc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# 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. | ||
bgpierc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# 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']}) | ||
bgpierc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
loc = location.Location.from_tmy(metadata) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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". There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
bgpierc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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: | ||
bgpierc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
mc.run_model_from_poa(POA_irradiance) | ||
bgpierc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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() | ||
kandersolar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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. |
Uh oh!
There was an error while loading. Please reload this page.