Skip to content

Implement irradiance.complete_irradiance with component sum equations #1567

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 40 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
83f0990
added new irradiance function for component sum
Oct 3, 2022
5980930
added to docstrings
Oct 3, 2022
1b2e5ed
updated docstrings
Oct 3, 2022
08a18cf
updated methods with new component_sum_irradiance() function
Oct 4, 2022
21599f6
added associated unit test for the new component sum function
Oct 4, 2022
fbf0ee9
added units tests for the component_sum_irradiance() function
Oct 5, 2022
34344e9
added whatsnew file for v0.9.4
Oct 5, 2022
24771c0
Merge branch 'master' into component_sum_equations
kperrynrel Oct 5, 2022
533d63b
fixed modelchain error to stop unit test erroring
Oct 5, 2022
db45cae
updated modelchains to get rid of unit test error
Oct 5, 2022
1a554e8
removed clearsky_dni arg for cases where it's not used
Oct 5, 2022
73e9b55
updated naming conventions for component_sum_irradiance function in m…
Oct 5, 2022
789540f
updated the routines to remove pep8 errors, added to clearsky_dni doc…
Oct 5, 2022
06cb584
updated the routine to return dataframe after calculating component s…
Oct 6, 2022
b0ae6f4
updated the PR based on @kanderso-nrel review
Oct 10, 2022
e776928
made updates based on kanderso-nrel's suggestions
Oct 14, 2022
74c954d
updated all the unit tests to pass
Oct 14, 2022
bebf349
Update pvlib/irradiance.py
kperrynrel Oct 14, 2022
f35b8e0
Update pvlib/irradiance.py
kperrynrel Oct 17, 2022
98e531c
moved warning out of dni generation call (just ghi and dhi)
Oct 17, 2022
9255aa2
updated warning statement
Oct 17, 2022
ed6e106
fix sticklerci formatting errors
Oct 17, 2022
9cfde3b
Update pvlib/irradiance.py
kperrynrel Oct 25, 2022
7cc3485
updates to name-changed to 'complete_irradiance'
Oct 25, 2022
aff38d4
fixed over-indentation error
Oct 25, 2022
e595465
removed default none from function params
Oct 26, 2022
78a180d
Merge branch 'master' into component_sum_equations
kperrynrel Oct 26, 2022
4fac56f
Update docs/sphinx/source/whatsnew/v0.9.4.rst
kperrynrel Oct 28, 2022
b9ec987
made updates based on @cwhanse's recommendations
kperrynrel Oct 28, 2022
e07f516
integrate updates pull
kperrynrel Oct 28, 2022
7ce6fa6
Update pvlib/irradiance.py
kperrynrel Oct 31, 2022
881779e
Update pvlib/irradiance.py
kperrynrel Oct 31, 2022
a0d6b18
changed to pytest error raise based on @wholmgren's recommendation
kperrynrel Oct 31, 2022
99205b4
Made updates to code based on @wholmgren's recommendations
kperrynrel Oct 31, 2022
51272d4
Merge updates
kperrynrel Oct 31, 2022
01736b9
fix pep8 error 2
kperrynrel Oct 31, 2022
3958012
updated modelchains to use zenith instead of apparent zenith
kperrynrel Oct 31, 2022
f8dd098
Merge branch 'master' into component_sum_equations
kperrynrel Oct 31, 2022
725d859
check that unit tests run
kperrynrel Oct 31, 2022
65fde50
undo ModelChain.complete_irradiance test changes
kandersolar Nov 1, 2022
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
1 change: 1 addition & 0 deletions docs/sphinx/source/reference/irradiance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Decomposing and combining irradiance
irradiance.poa_components
irradiance.get_ground_diffuse
irradiance.dni
irradiance.complete_irradiance

Transposition models
--------------------
Expand Down
6 changes: 5 additions & 1 deletion docs/sphinx/source/whatsnew/v0.9.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ Deprecations
Enhancements
~~~~~~~~~~~~
* Multiple code style issues fixed that were reported by LGTM analysis. (:issue:`1275`, :pull:`1559`)
* Added a function to calculate one of GHI, DHI, and DNI from values of the other two.
:py:func:`~pvlib.irradiance.complete_irradiance`
(:issue:`1565`, :pull:`1567`)
* Add optional ``return_components`` parameter to :py:func:`pvlib.irradiance.haydavies` to return
individual diffuse irradiance components (:issue:`1553`, :pull:`1568`)


Bug fixes
~~~~~~~~~



Testing
~~~~~~~
* Corrected a flawed test for :py:func:`~pvlib.irradiance.get_ground_diffuse` (:issue:`1569`, :pull:`1575`)
Expand All @@ -36,6 +39,7 @@ Requirements

Contributors
~~~~~~~~~~~~
* Kirsten Perry (:ghuser:`kperrynrel`)
* Christian Orner (:ghuser:`chrisorner`)
* Saurabh Aneja (:ghuser:`spaneja`)
* Marcus Boumans (:ghuser:`bowie2211`)
65 changes: 65 additions & 0 deletions pvlib/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pandas as pd

from pvlib import atmosphere, solarposition, tools
import pvlib # used to avoid dni name collision in complete_irradiance


# see References section of get_ground_diffuse function
Expand Down Expand Up @@ -2948,3 +2949,67 @@ def dni(ghi, dhi, zenith, clearsky_dni=None, clearsky_tolerance=1.1,
(zenith < zenith_threshold_for_zero_dni) &
(dni > max_dni)] = max_dni
return dni


def complete_irradiance(solar_zenith,
ghi=None,
dhi=None,
dni=None,
dni_clear=None):
r"""
Use the component sum equations to calculate the missing series, using
the other available time series. One of the three parameters (ghi, dhi,
dni) is passed as None, and the other associated series passed are used to
calculate the missing series value.

The "component sum" or "closure" equation relates the three
primary irradiance components as follows:

.. math::

GHI = DHI + DNI \cos(\theta_z)

Parameters
----------
solar_zenith : Series
Zenith angles in decimal degrees, with datetime index.
Angles must be >=0 and <=180. Must have the same datetime index
as ghi, dhi, and dni series, when available.
ghi : Series, optional
Pandas series of dni data, with datetime index. Must have the same
datetime index as dni, dhi, and zenith series, when available.
dhi : Series, optional
Pandas series of dni data, with datetime index. Must have the same
datetime index as ghi, dni, and zenith series, when available.
dni : Series, optional
Pandas series of dni data, with datetime index. Must have the same
datetime index as ghi, dhi, and zenith series, when available.
dni_clear : Series, optional
Pandas series of clearsky dni data. Must have the same datetime index
as ghi, dhi, dni, and zenith series, when available. See
:py:func:`dni` for details.

Returns
-------
component_sum_df : Dataframe
Pandas series of 'ghi', 'dhi', and 'dni' columns with datetime index
"""
if ghi is not None and dhi is not None and dni is None:
dni = pvlib.irradiance.dni(ghi, dhi, solar_zenith,
clearsky_dni=dni_clear,
clearsky_tolerance=1.1)
elif dni is not None and dhi is not None and ghi is None:
ghi = (dhi + dni * tools.cosd(solar_zenith))
elif dni is not None and ghi is not None and dhi is None:
dhi = (ghi - dni * tools.cosd(solar_zenith))
else:
raise ValueError(
"Please check that exactly one of ghi, dhi and dni parameters "
"is set to None"
)
# Merge the outputs into a master dataframe containing 'ghi', 'dhi',
# and 'dni' columns
component_sum_df = pd.DataFrame({'ghi': ghi,
'dhi': dhi,
'dni': dni})
return component_sum_df
36 changes: 21 additions & 15 deletions pvlib/modelchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,13 +1289,13 @@ def complete_irradiance(self, weather):
self._assign_times()
self.results.solar_position = self.location.get_solarposition(
self.results.times, method=self.solar_position_method)

# Calculate the irradiance using the component sum equations,
# if needed
if isinstance(weather, tuple):
for w in self.results.weather:
self._complete_irradiance(w)
else:
self._complete_irradiance(self.results.weather)

return self

def _complete_irradiance(self, weather):
Expand All @@ -1304,26 +1304,32 @@ def _complete_irradiance(self, weather):
"Results can be too high or negative.\n" +
"Help to improve this function on github:\n" +
"https://github.com/pvlib/pvlib-python \n")

if {'ghi', 'dhi'} <= icolumns and 'dni' not in icolumns:
clearsky = self.location.get_clearsky(
weather.index, solar_position=self.results.solar_position)
weather.loc[:, 'dni'] = pvlib.irradiance.dni(
weather.loc[:, 'ghi'], weather.loc[:, 'dhi'],
self.results.solar_position.zenith,
clearsky_dni=clearsky['dni'],
clearsky_tolerance=1.1)
complete_irrad_df = pvlib.irradiance.complete_irradiance(
solar_zenith=self.results.solar_position.zenith,
ghi=weather.ghi,
dhi=weather.dhi,
dni=None,
dni_clear=clearsky.dni)
weather.loc[:, 'dni'] = complete_irrad_df.dni
elif {'dni', 'dhi'} <= icolumns and 'ghi' not in icolumns:
warnings.warn(wrn_txt, UserWarning)
weather.loc[:, 'ghi'] = (
weather.dhi + weather.dni *
tools.cosd(self.results.solar_position.zenith)
)
complete_irrad_df = pvlib.irradiance.complete_irradiance(
solar_zenith=self.results.solar_position.zenith,
ghi=None,
dhi=weather.dhi,
dni=weather.dni)
weather.loc[:, 'ghi'] = complete_irrad_df.ghi
elif {'dni', 'ghi'} <= icolumns and 'dhi' not in icolumns:
warnings.warn(wrn_txt, UserWarning)
weather.loc[:, 'dhi'] = (
weather.ghi - weather.dni *
tools.cosd(self.results.solar_position.zenith))
complete_irrad_df = pvlib.irradiance.complete_irradiance(
solar_zenith=self.results.solar_position.zenith,
ghi=weather.ghi,
dhi=None,
dni=weather.dni)
weather.loc[:, 'dhi'] = complete_irrad_df.dhi

def _prep_inputs_solar_pos(self, weather):
"""
Expand Down
Loading