-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add spectral factor gallery example #2114
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 17 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
c9b860c
Create spectral_factor.py
RDaxini d1156be
Update spectral_factor.py
RDaxini 8fefcf2
Update spectral_factor.py
RDaxini c566795
Update spectral_factor.py
RDaxini e8b63ec
Update spectral_factor.py
RDaxini 12c5d6c
Update spectral_factor.py
RDaxini fedba93
Update spectral_factor.py
RDaxini eeea56b
Update docs/examples/spectrum/spectral_factor.py
RDaxini bca1f93
Update docs/examples/spectrum/spectral_factor.py
RDaxini 4c7ca2d
Update docs/examples/spectrum/spectral_factor.py
RDaxini 134fc30
Update docs/examples/spectrum/spectral_factor.py
RDaxini 96c6144
Update spectral_factor.py
RDaxini dba0ce8
Update docs/examples/spectrum/spectral_factor.py
RDaxini 2f1fa7a
Update docs/examples/spectrum/spectral_factor.py
RDaxini c3f9b05
Update spectral_factor.py
RDaxini 9837013
Update spectral_factor.py
RDaxini 4105785
Merge branch 'main' into scf_example
RDaxini 21043c9
Update spectral_factor.py
RDaxini 4254c85
Update docs/examples/spectrum/spectral_factor.py
RDaxini 18ceb37
Update docs/examples/spectrum/spectral_factor.py
RDaxini 1bf00b1
Update spectral_factor.py
RDaxini 02891ea
Merge branch 'scf_example' of https://github.com/RDaxini/pvlib-python…
RDaxini 8c859a7
Update spectral_factor.py
RDaxini d935a7c
Update spectral_factor.py
RDaxini 37bdee0
Update spectral_factor.py
RDaxini 665f494
Update spectral_factor.py
RDaxini ea48684
Update v0.11.1.rst
RDaxini 3b0a79b
Update spectral_factor.py
RDaxini d4c03cb
Update spectral_factor.py
RDaxini 0af9b2d
Update spectral_factor.py
RDaxini e1398d3
Apply suggestions from code review
RDaxini 69d9567
Update spectral_factor.py
RDaxini 68edc03
Update docs/examples/spectrum/spectral_factor.py
RDaxini 094a744
expand ama/amr initialism
RDaxini fa2e353
Update spectral_factor.py
RDaxini 782e076
Update spectral_factor.py
RDaxini 19d6ddb
Update spectral_factor.py
RDaxini 2db4db0
Update docs/examples/spectrum/spectral_factor.py
RDaxini 63d52cb
Update spectral_factor.py
RDaxini ecd9cf9
Merge remote-tracking branch 'upstream/main' into scf_example
RDaxini 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
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,138 @@ | ||
""" | ||
Spectral Mismatch Estimation | ||
============================ | ||
Comparison of spectral factor calculation methods used to estimate the spectral | ||
mismatch factor, :math:`M`, from atmospheric variable inputs. | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
|
||
# %% | ||
# Introduction | ||
# ------------ | ||
# This example demonstrates how to use different `spectrum.spectral_factor` | ||
# models in pvlib to calculate the spectral mismatch factor, :math:`M`. While | ||
# :math:`M` for a photovoltaic (PV) module can be calculated exactly using | ||
# spectral irradiance and module spectral response data, these data are not | ||
# always available. pvlib provides several functions to estimate the spectral | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# mismatch factor, M, using proxies of the prevailing spectral | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# irradiance conditions, such as air mass and clearsky index, which are easily | ||
# derived from common ground-based measurements such as broadband irradiance. | ||
# More information on a range of spectral factor models, as well as the | ||
# variables upon which they are based, can be found in [1]_. | ||
# | ||
# Let's import some data. This example uses a Typical Meteorological Year 3 | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# (TMY3) file for the location of Greensboro, North Carolina, from the pvlib | ||
# data directory. This TMY3 file is constructed using the median month from | ||
# each year between 1980 and 2003, from which we extract the first week of | ||
# August 2001 to analyse. | ||
|
||
# %% | ||
import pathlib | ||
from matplotlib import pyplot as plt | ||
import pandas as pd | ||
import pvlib as pv | ||
from pvlib import location | ||
from pvlib.atmosphere import get_relative_airmass | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
DATA_DIR = pathlib.Path(pv.__file__).parent / 'data' | ||
meteo, metadata = pv.iotools.read_tmy3(DATA_DIR / '723170TYA.CSV', | ||
coerce_year=2001, map_variables=True) | ||
meteo = meteo.loc['2001-08-01':'2001-08-07'] | ||
|
||
# %% | ||
# pvlib Spectral Factor Functions | ||
# ----------------------------- | ||
# This example demonstrates the application of three pvlib spectral factor | ||
# functions: | ||
# | ||
# - :py:func:`~pvlib.spectrum.spectral_factor_sapm`, which requires only | ||
# the absolute airmass :math:`AM_a` | ||
# - :py:func:`~pvlib.spectrum.spectral_factor_pvspec`, which requires | ||
# :math:`AM_a` and the clearsky index :math:`k_c` | ||
# - :py:func:`~pvlib.spectrum.spectral_factor_firstsolar`, which requires | ||
# :math:`AM_a` and the atmospheric precipitable water content :math:`W` | ||
|
||
# %% | ||
# Calculation of inputs | ||
# --------------------- | ||
# Let's calculate the absolute air mass, which is required for all three | ||
# models. We use the Kasten and Young [2]_ model, which requires the apparent | ||
# sun zenith. Note: TMY3 files timestamps indicate the end of the hour, so we | ||
# shift the indices back 30-minutes to calculate solar position at the centre | ||
# of the interval. | ||
|
||
# Create a location object | ||
lat, lon = metadata['latitude'], metadata['longitude'] | ||
alt = altitude = metadata['altitude'] | ||
tz = 'Etc/GMT+5' | ||
loc = location.Location(lat, lon, tz=tz, name='Greensboro, NC') | ||
|
||
# Calculate solar position parameters | ||
solpos = loc.get_solarposition( | ||
meteo.index.shift(freq="-30min"), | ||
pressure=meteo.pressure*100, # convert from millibar to Pa | ||
temperature=meteo.temp_air) | ||
solpos.index = meteo.index # reset index to end of the hour | ||
|
||
amr = get_relative_airmass(solpos.apparent_zenith).dropna() # relative airmass | ||
ama = amr*(meteo.pressure/1013.25) # absolute airmass | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Now we calculate the clearsky index, :math:`kc`, by comparing the TMY3 GHI to | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# the modelled clearky GHI. | ||
|
||
cs = loc.get_clearsky(meteo.index) | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
kc = pv.irradiance.clearsky_index(meteo.ghi, cs.ghi) | ||
|
||
# :math:`W` is provided in the TMY3 file but in other cases can be calculated | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# from temperature and relative humidity | ||
# (see :py:func:`pvlib.atmosphere.gueymard94_pw`). | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
w = meteo.precipitable_water | ||
|
||
# %% | ||
# Calculation of Spectral Mismatch | ||
# -------------------------------- | ||
# Let's calculate the spectral mismatch factor using the three pvlib functions. | ||
# First, we need to import some model coefficients for the SAPM spectral factor | ||
# function, which, unlike the other two functions, lacks built-in coefficients. | ||
|
||
# Import some for a mc-Si module from the SAPM module database. | ||
module = pv.pvsystem.retrieve_sam('SandiaMod')['LG_LG290N1C_G3__2013_'] | ||
# Calculate M using the three models for an mc-Si PV module. | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
m_sapm = pv.spectrum.spectral_factor_sapm(ama, module) | ||
m_pvspec = pv.spectrum.spectral_factor_pvspec(ama, kc, 'multisi') | ||
m_fs = pv.spectrum.spectral_factor_firstsolar(w, ama, 'multisi') | ||
df_results = pd.concat([m_sapm, m_pvspec, m_fs], axis=1) | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
df_results.columns = ['SAPM', 'PVSPEC', 'FS'] | ||
# %% | ||
# Comparison Plots | ||
# ---------------- | ||
# We can plot the results to visualise variability between the models. Note | ||
# that this is not an exact comparison since the exact same PV modules has | ||
# not been modelled in each case, only the same module technology. | ||
|
||
# Plot M | ||
fig1, ax1 = plt.subplots() | ||
df_results.plot(ax=ax1) | ||
|
||
ax1.set_xlabel('Date (m-d H:M)') | ||
ax1.set_ylabel('Mismatch (-)') | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ax1.legend() | ||
ax1.set_ylim(0.85, 1.15) | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
plt.show() | ||
|
||
# We can also zoom in one one day, for example August 1st. | ||
fig2, ax1 = plt.subplots() | ||
df_results.loc['2001-08-01'].plot(ax=ax1) | ||
ax1.set_ylim(0.85, 1.15) | ||
plt.show() | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# %% | ||
# References | ||
# ---------- | ||
# .. [1] Daxini, Rajiv, and Wu, Yupeng (2023). "Review of methods to account | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# for the solar spectral influence on photovoltaic device performance." | ||
# Energy 286 | ||
# :doi:`10.1016/j.energy.2023.129461` | ||
# .. [2] Kasten, F. and Young, A.T., 1989. Revised optical air mass tables | ||
RDaxini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# and approximation formula. Applied Optics, 28(22), pp.4735-4738. | ||
# :doi:`10.1364/AO.28.004735` |
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.
Uh oh!
There was an error while loading. Please reload this page.