-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2b08efb
added perez modelchain example
bgpierc d86441d
formatting
bgpierc a34e797
cleaned up
bgpierc 4196d54
linter
bgpierc 6b2f57c
linter 2
bgpierc 7aad3da
added whatsnew
bgpierc ef6ef60
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc 7d8d6d3
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc c7b472e
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc dc670fd
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc 814454d
added plt tight layout
bgpierc 8f8a937
added plt tight layout
bgpierc 6dbe662
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc d29e8f5
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc a9653d2
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc 156194c
linter
bgpierc 01c7125
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc fa6169c
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc 2e370e7
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc c5cde3a
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc 35cf150
Update docs/examples/irradiance-transposition/use_perez_modelchain.py
bgpierc 417053b
broke up large code block
bgpierc 0d0db58
Merge branch 'main' into perez_coeff_example
kandersolar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
docs/examples/irradiance-transposition/use_perez_modelchain.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
""" | ||
Use different Perez coefficients with the ModelChain | ||
==================================================== | ||
|
||
This example demonstrates how to customize the ModelChain | ||
to use site-specific Perez transposition coefficients. | ||
""" | ||
|
||
# %% | ||
# The :py:class:`pvlib.modelchain.ModelChain` object provides a useful method | ||
# for easily constructing a PV system model with a simple, unified interface. | ||
# However, a user may want to customize the steps | ||
# in the system model in various ways. | ||
# One such example is during the irradiance transposition step. | ||
# The Perez model perform very well on field data, but | ||
# it requires 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 improved model accuracy | ||
# when using a site-specific set of coefficients. | ||
# 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 = tmy[['ghi', 'dhi', 'dni', 'temp_air', 'wind_speed']] | ||
|
||
loc = location.Location.from_tmy(metadata) | ||
|
||
#%% | ||
# Now, let's set up a standard PV model using the ``ModelChain`` | ||
|
||
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 | ||
# (note that to use POA irradiance as input to the ModelChain the method | ||
# `.run_model_from_poa` is used): | ||
|
||
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, agreed, done