8000 Implement reverse transposition using Perez-Driesse forward transposition by adriesse · Pull Request #1907 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Implement reverse transposition using Perez-Driesse forward transposition #1907

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 28 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
662846e
Add reverse transposition function and two helpers.
adriesse Nov 12, 2023
24772a9
Add missing import.
adriesse Nov 12, 2023
60b103a
Add to docs under transposition until a better place is found/made.
adriesse Nov 12, 2023
2c4e4b9
Minor doc string fixes.
adriesse Nov 12, 2023
9bf9064
Add full_output option similar to newton().
adriesse Nov 13, 2023
1196851
First example for reverse transposition.
adriesse Nov 13, 2023
bf9105a
Second example for reverse transposition.
adriesse Nov 13, 2023
97d4559
Some improvements to the two examples.
adriesse Nov 13, 2023
17b3f3d
Placate flake8.
adriesse Nov 13, 2023
613e70b
Add tests for reverse transpostion.
adriesse Nov 14, 2023
e5025b4
Refine examples and fix test.
adriesse Nov 14, 2023
aaf34ba
Update whatsnew.
adriesse Nov 14, 2023
74f5c06
Refine examples.
adriesse Nov 14, 2023
58e8ded
Try to get rid of matplotlib warning in example.
adriesse Nov 14, 2023
0f35860
Remove unused import.
adriesse Nov 14, 2023
6e7ec7b
Update pvlib/irradiance.py
adriesse Nov 27, 2023
8106fcb
Improve examples based on reviews.
adriesse Nov 27, 2023
1c4da53
Settle conflict.
adriesse Nov 27, 2023
1c16709
Try again.
adriesse Nov 27, 2023
69d6288
Merge branch 'main' into rtranspose
adriesse Nov 27, 2023
8d7afa9
Remove one space.
adriesse Nov 27, 2023
d83e306
Merge branch 'main' into rtranspose
adriesse Dec 2, 2023
ae3cdb6
Final(?) changes.
adriesse Dec 2, 2023
d7fb73d
Update reference in erbs_driesse().
adriesse Dec 2, 2023
8021769
Fix links in examples.
adriesse Dec 2, 2023
cbf971b
Update docs/examples/irradiance-transposition/plot_rtranpose_limitati…
adriesse Dec 7, 2023
afcf178
Address review comments.
adriesse Dec 7, 2023
71db4c4
Final renames.
adriesse Dec 12, 2023
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
Prev Previous commit
Next Next commit
Final(?) changes.
  • Loading branch information
adriesse committed Dec 2, 2023
commit ae3cdb61e1dc1b83daf5fda6a3304187136adb52
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
#
# In this example we look at a single point in time and consider a full range
# of possible GHI and POA global values as shown in figures 3 and 4 of [1]_.
# Then we use :py:func:`pvlib.irradiance.rtranspose_driesse_2023` to estimate
# Then we use :py:func:`pvlib.irradiance.ghi_from_poa_driesse_2023` to estimate
# the original GHI from POA global.
#
# References
# ----------
# .. [1] A. Driesse, A. Jensen, R. Perez, A Continuous Form of the Perez
# Diffuse Sky Model for Forward and Reverse Transposition, accepted
# for publication in the Solar Energy Journal.
# .. [1] Driesse, A., Jensen, A., Perez, R., 2024. A Continuous form of the
# Perez diffuse sky model for forward and reverse transposition.
# Solar Energy vol. 267. :doi:`10.1016/j.solener.2023.112093`
#

import numpy as np
Expand All @@ -45,7 +45,7 @@

from pvlib.irradiance import (erbs_driesse,
get_total_irradiance,
rtranspose_driesse_2023,
ghi_from_poa_driesse_2023,
)

matplotlib.rcParams['axes.grid'] = True
Expand Down Expand Up @@ -92,11 +92,11 @@

poa_test = 200

ghi_hat = rtranspose_driesse_2023(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
poa_test,
dni_extra,
full_output=False)
ghi_hat = ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
poa_test,
dni_extra,
full_output=False)

print('Estimated GHI: %.2f W/m².' % ghi_hat)

Expand Down Expand Up @@ -156,12 +156,12 @@
# out, other times not.
#

result = rtranspose_driesse_2023(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
poa_global,
dni_extra,
full_output=True,
)
result = ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
poa_global,
dni_extra,
full_output=True,
)

ghi_hat, conv, niter = result
correct = np.isclose(ghi, ghi_hat, atol=0.01)
Expand Down
22 changes: 12 additions & 10 deletions docs/examples/irradiance-transposition/plot_rtranpose_year.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
# Recovering GHI from POA irradiance is termed "reverse transposition."
#
# In this example we start with a TMY file and calculate POA global irradiance.
# Then, we use :py:func:`pvlib.irradiance.rtranspose_driesse_2023` to estimate
# Then we use :py:func:`pvlib.irradiance.ghi_from_poa_driesse_2023` to estimate
# the original GHI from POA global. Details of the method found in [1]_.
#
# References
# ----------
# .. [1] A. Driesse, A. Jensen, R. Perez, A Continuous Form of the Perez
# Diffuse Sky Model for Forward and Reverse Transposition, accepted
# for publication in the Solar Energy Journal.
# .. [1] Driesse, A., Jensen, A., Perez, R., 2024. A Continuous form of the
# Perez diffuse sky model for forward and reverse transposition.
# Solar Energy vol. 267. :doi:`10.1016/j.solener.2023.112093`
#

import os
Expand All @@ -41,7 +41,7 @@
from pvlib import iotools, location
from pvlib.irradiance import (get_extra_radiation,
get_total_irradiance,
rtranspose_driesse_2023,
ghi_from_poa_driesse_2023,
aoi,
)

Expand Down Expand Up @@ -83,7 +83,8 @@
df['dni_extra'] = get_extra_radiation(df.index)

total_irrad = get_total_irradiance(TILT, ORIENT,
solpos.apparent_zenith, solpos.azimuth,
solpos.apparent_zenith,
solpos.azimuth,
df.dni, df.ghi, df.dhi,
dni_extra=df.dni_extra,
model='perez-driesse')
Expand All @@ -105,10 +106,11 @@

start = time.process_time()

df['ghi_rev'] = rtranspose_driesse_2023(TILT, ORIENT,
solpos.apparent_zenith, solpos.azimuth,
df.poa_global,
dni_extra=df.dni_extra)
df['ghi_rev'] = ghi_from_poa_driesse_2023(TILT, ORIENT,
solpos.apparent_zenith,
solpos.azimuth,
df.poa_global,
dni_extra=df.dni_extra)
finish = time.process_time()

print('Elapsed time for reverse transposition: %.1f s' % (finish - start))
Expand Down
66 changes: 33 additions & 33 deletions pvlib/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,9 +1381,9 @@ def perez_driesse(surface_tilt, surface_azimuth, dhi, dni, dni_extra,

References
----------
.. [1] A. Driesse, A. Jensen, R. Perez, A Continuous Form of the Perez
Diffuse Sky Model for Forward and Reverse Transposition, accepted
for publication in the Solar Energy Journal.
.. [1] Driesse, A., Jensen, A., Perez, R., 2024. A Continuous form of the
Perez diffuse sky model for forward and reverse transposition.
Solar Energy vol. 267. :doi:`10.1016/j.solener.2023.112093`

.. [2] Perez, R., Ineichen, P., Seals, R., Michalsky, J., Stewart, R.,
1990. Modeling daylight availability and irradiance components from
Expand Down Expand Up @@ -1445,15 +1445,15 @@ def perez_driesse(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
return sky_diffuse


def _transpose(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
ghi,
dni_extra, airmass, albedo):
def _poa_from_ghi(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
ghi,
dni_extra, airmass, albedo):
'''
Transposition function that includes decomposition of GHI using the
continuous Erbs-Driesse model.

Helper function for rtranspose_driesse_2023.
Helper function for ghi_from_poa_driesse_2023.
'''
# Contributed by Anton Driesse (@adriesse), PV Performance Labs. Nov., 2023

Expand All @@ -1471,15 +1471,15 @@ def _transpose(surface_tilt, surface_azimuth,
return irrads['poa_global']


def _rtranspose(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
poa_global,
dni_extra, airmass, albedo,
xtol=0.01):
def _ghi_from_poa(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
poa_global,
dni_extra, airmass, albedo,
xtol=0.01):
'''
Reverse transposition function that uses the scalar bisection from scipy.

Helper function for rtranspose_driesse_2023.
Helper function for ghi_from_poa_driesse_2023.
'''
# Contributed by Anton Driesse (@adriesse), PV Performance Labs. Nov., 2023

Expand All @@ -1491,10 +1491,10 @@ def _rtranspose(surface_tilt, surface_azimuth,

# function whose root needs to be found
def poa_error(ghi):
poa_hat = _transpose(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
ghi,
dni_extra, airmass, albedo)
poa_hat = _poa_from_ghi(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
ghi,
dni_extra, airmass, albedo)
return poa_hat - poa_global

# calculate an upper bound for ghi using clearness index 1.25
Expand Down Expand Up @@ -1523,12 +1523,12 @@ def poa_error(ghi):
return ghi, conv, niter


def rtranspose_driesse_2023(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
poa_global,
dni_extra=None, airmass=None, albedo=0.25,
xtol=0.01,
full_output=False):
def ghi_from_poa_driesse_2023(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
poa_global,
dni_extra=None, airmass=None, albedo=0.25,
xtol=0.01,
full_output=False):
'''
Estimate global horizontal irradiance (GHI) from global plane-of-array
(POA) irradiance. This reverse transposition algorithm uses a bisection
Expand Down Expand Up @@ -1578,9 +1578,9 @@ def rtranspose_driesse_2023(surface_tilt, surface_azimuth,

References
----------
.. [1] A. Driesse, A. Jensen, R. Perez, A Continuous Form of the Perez
Diffuse Sky Model for Forward and Reverse Transposition, accepted
for publication in the Solar Energy Journal.
.. [1] Driesse, A., Jensen, A., Perez, R., 2024. A Continuous form of the
Perez diffuse sky model for forward and reverse transposition.
Solar Energy vol. 267. :doi:`10.1016/j.solener.2023.112093`

See also
--------
Expand All @@ -1590,13 +1590,13 @@ def rtranspose_driesse_2023(surface_tilt, surface_azimuth,
'''
# Contributed by Anton Driesse (@adriesse), PV Performance Labs. Nov., 2023

rtranspose_array = np.vectorize(_rtranspose)
ghi_from_poa_array = np.vectorize(_ghi_from_poa)

ghi, conv, niter = rtranspose_array(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
poa_global,
dni_extra, airmass, albedo,
xtol=0.01)
ghi, conv, niter = ghi_from_poa_array(surface_tilt, surface_azimuth,
solar_zenith, solar_azimuth,
poa_global,
dni_extra, airmass, albedo,
F5B5 xtol=0.01)

if isinstance(poa_global, pd.Series):
ghi = pd.Series(ghi, poa_global.index)
Expand Down
8 changes: 4 additions & 4 deletions pvlib/tests/test_irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def test_dirint_min_cos_zenith_max_zenith():
assert_series_equal(out, expected, check_less_precise=True)


def test_rtranspose_driesse():
def test_ghi_from_poa_driesse():
# inputs copied from test_gti_dirint
times = pd.DatetimeIndex(
['2014-06-24T06-0700', '2014-06-24T09-0700', '2014-06-24T12-0700'])
Expand All @@ -793,7 +793,7 @@ def test_rtranspose_driesse():
surface_azimuth = 180

# test core function
output = irradiance.rtranspose_driesse_2023(
output = irradiance.ghi_from_poa_driesse_2023(
surface_tilt, surface_azimuth, zenith, azimuth,
poa_global, dni_extra=1366.1)

Expand All @@ -803,7 +803,7 @@ def test_rtranspose_driesse():
# test series output
poa_global = pd.Series([20, 300, 1000], index=times)

output = irradiance.rtranspose_driesse_2023(
output = irradiance.ghi_from_poa_driesse_2023(
surface_tilt, surface_azimuth, zenith, azimuth,
poa_global, dni_extra=1366.1)

Expand All @@ -812,7 +812,7 @@ def test_rtranspose_driesse():
# test full_output option and special cases
poa_global = np.array([0, 1500, np.nan])

ghi, conv, niter = irradiance.rtranspose_driesse_2023(
ghi, conv, niter = irradiance.ghi_from_poa_driesse_2023(
surface_tilt, surface_azimuth, zenith, azimuth,
poa_global, dni_extra=1366.1, full_output=True)

Expand Down
0