Skip to content

Commit a6995c3

Browse files
cwhansekandersolar
andauthored
Accept float in PVSystem.get_irradiance (#2227)
* accept floats in PVSystem.get_irradiance * add note * docstring edits, check for DatetimeIndex * format and docstring edits * pacify linter * play nice now * whatsnew * edit docstring * review * Update docs/sphinx/source/whatsnew/v0.11.2.rst * true up docstring * Update pvlib/pvsystem.py Co-authored-by: Kevin Anderson <[email protected]> * float not int * tab * pacify the linter --------- Co-authored-by: Kevin Anderson <[email protected]>
1 parent 0781787 commit a6995c3

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

docs/sphinx/source/whatsnew/v0.11.2.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Deprecations
1111
Enhancements
1212
~~~~~~~~~~~~
1313

14+
Bug Fixes
15+
~~~~~~~~~
16+
* :py:meth:`~pvlib.pvsystem.PVSystem.get_irradiance` accepts float inputs.
17+
(:issue:`1338`, :pull:`2227`)
1418

1519
Bug fixes
1620
~~~~~~~~~

pvlib/pvsystem.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def get_irradiance(self, solar_zenith, solar_azimuth, dni, ghi, dhi,
312312
dni_extra=None, airmass=None, albedo=None,
313313
model='haydavies', **kwargs):
314314
"""
315-
Uses the :py:func:`irradiance.get_total_irradiance` function to
315+
Uses :py:func:`pvlib.irradiance.get_total_irradiance` to
316316
calculate the plane of array irradiance components on the tilted
317317
surfaces defined by each array's ``surface_tilt`` and
318318
``surface_azimuth``.
@@ -323,11 +323,11 @@ def get_irradiance(self, solar_zenith, solar_azimuth, dni, ghi, dhi,
323323
Solar zenith angle.
324324
solar_azimuth : float or Series
325325
Solar azimuth angle.
326-
dni : float or Series or tuple of float or Series
326+
dni : float, Series, or tuple of float or Series
327327
Direct Normal Irradiance. [W/m2]
328-
ghi : float or Series or tuple of float or Series
328+
ghi : float, Series, or tuple of float or Series
329329
Global horizontal irradiance. [W/m2]
330-
dhi : float or Series or tuple of float or Series
330+
dhi : float, Series, or tuple of float or Series
331331
Diffuse horizontal irradiance. [W/m2]
332332
dni_extra : float, Series or tuple of float or Series, optional
333333
Extraterrestrial direct normal irradiance. [W/m2]
@@ -339,15 +339,22 @@ def get_irradiance(self, solar_zenith, solar_azimuth, dni, ghi, dhi,
339339
Irradiance model.
340340
341341
kwargs
342-
Extra parameters passed to :func:`irradiance.get_total_irradiance`.
342+
Extra parameters passed to
343+
:py:func:`pvlib.irradiance.get_total_irradiance`.
343344
344345
Notes
345346
-----
346-
Each of `dni`, `ghi`, and `dni` parameters may be passed as a tuple
347-
to provide different irradiance for each array in the system. If not
348-
passed as a tuple then the same value is used for input to each Array.
349-
If passed as a tuple the length must be the same as the number of
350-
Arrays.
347+
Each of ``dni``, ``ghi``, and ``dni`` may be passed as a float, Series,
348+
or tuple of float or Series. If passed as a float or Series, these
349+
values are used for all Arrays. If passed as a tuple, the tuple length
350+
must be the same as the number of Arrays. The first tuple element is
351+
used for the first Array, the second tuple element for the second
352+
Array, and so forth.
353+
354+
Some sky irradiance models require ``dni_extra``. For these models,
355+
if ``dni_extra`` is not provided and ``solar_zenith`` has a
356+
``DatetimeIndex``, then ``dni_extra`` is calculated.
357+
Otherwise, ``dni_extra=1367`` is assumed.
351358
352359
Returns
353360
-------
@@ -1077,7 +1084,7 @@ def get_irradiance(self, solar_zenith, solar_azimuth, dni, ghi, dhi,
10771084
"""
10781085
Get plane of array irradiance components.
10791086
1080-
Uses the :py:func:`pvlib.irradiance.get_total_irradiance` function to
1087+
Uses :py:func:`pvlib.irradiance.get_total_irradiance` to
10811088
calculate the plane of array irradiance components for a surface
10821089
defined by ``self.surface_tilt`` and ``self.surface_azimuth``.
10831090
@@ -1112,16 +1119,30 @@ def get_irradiance(self, solar_zenith, solar_azimuth, dni, ghi, dhi,
11121119
Column names are: ``'poa_global', 'poa_direct', 'poa_diffuse',
11131120
'poa_sky_diffuse', 'poa_ground_diffuse'``.
11141121
1122+
Notes
1123+
-----
1124+
Some sky irradiance models require ``dni_extra``. For these models,
1125+
if ``dni_extra`` is not provided and ``solar_zenith`` has a
1126+
``DatetimeIndex``, then ``dni_extra`` is calculated.
1127+
Otherwise, ``dni_extra=1367`` is assumed.
1128+
11151129
See also
11161130
--------
11171131
:py:func:`pvlib.irradiance.get_total_irradiance`
11181132
"""
11191133
if albedo is None:
11201134
albedo = self.albedo
11211135

1122-
# not needed for all models, but this is easier
1136+
# dni_extra is not needed for all models, but this is easier
11231137
if dni_extra is None:
1124-
dni_extra = irradiance.get_extra_radiation(solar_zenith.index)
1138+
if (hasattr(solar_zenith, 'index') and
1139+
isinstance(solar_zenith.index, pd.DatetimeIndex)):
1140+
# calculate extraterrestrial irradiance
1141+
dni_extra = irradiance.get_extra_radiation(
1142+
solar_zenith.index)
1143+
else:
1144+
# use the solar constant
1145+
dni_extra = 1367.0
11251146

11261147
if airmass is None:
11271148
airmass = atmosphere.get_relative_airmass(solar_zenith)

pvlib/tests/test_pvsystem.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,6 @@ def test_PVSystem_get_irradiance(solar_pos):
18701870
irrads['dni'],
18711871
irrads['ghi'],
18721872
irrads['dhi'])
1873-
18741873
expected = pd.DataFrame(data=np.array(
18751874
[[883.65494055, 745.86141676, 137.79352379, 126.397131, 11.39639279],
18761875
[0., -0., 0., 0., 0.]]),
@@ -1881,6 +1880,23 @@ def test_PVSystem_get_irradiance(solar_pos):
18811880
assert_frame_equal(irradiance, expected, check_less_precise=2)
18821881

18831882

1883+
def test_PVSystem_get_irradiance_float():
1884+
system = pvsystem.PVSystem(surface_tilt=32, surface_azimuth=135)
1885+
irrads = {'dni': 900., 'ghi': 600., 'dhi': 100.}
1886+
zenith = 55.366831
1887+
azimuth = 172.320038
1888+
irradiance = system.get_irradiance(zenith,
1889+
azimuth,
1890+
irrads['dni'],
1891+
irrads['ghi'],
1892+
irrads['dhi'])
1893+
expected = {'poa_global': 884.80903423, 'poa_direct': 745.84258835,
1894+
'poa_diffuse': 138.96644588, 'poa_sky_diffuse': 127.57005309,
1895+
'poa_ground_diffuse': 11.39639279}
1896+
for k, v in irradiance.items():
1897+
assert np.isclose(v, expected[k], rtol=1e-6)
1898+
1899+
18841900
def test_PVSystem_get_irradiance_albedo(solar_pos):
18851901
system = pvsystem.PVSystem(surface_tilt=32, surface_azimuth=135)
18861902
irrads = pd.DataFrame({'dni': [900, 0], 'ghi': [600, 0], 'dhi': [100, 0],

0 commit comments

Comments
 (0)