Skip to content

Add irradiance.clearsky_index #571

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 19 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f0a10ab
basic code for irradiance.clearsky_index, still needs full docstring …
kevinsa5 Sep 11, 2018
1350d2a
Add a float conversion to irradiance.clearsky_index to allow integer …
kevinsa5 Nov 18, 2018
cd7a596
added tests for irradiance.clearsky_index
kevinsa5 Nov 18, 2018
0099762
fix typo in irradiance.clearsky_index test
kevinsa5 Nov 18, 2018
4b208e9
fix typo in irradiance.clearsky_index test
kevinsa5 Nov 18, 2018
4a215f5
Merge branch 'master' of https://github.com/pvlib/pvlib-python
kevinsa5 Nov 18, 2018
c57892a
Update pvlib/test/test_irradiance.py to remove extra spaces
kevinsa5 Nov 22, 2018
9ae594c
fixed incorrect documentation for irradiance.clearsky_index
kevinsa5 Jan 26, 2019
8f601ad
Merge branch 'master' of https://github.com/kevinsa5/pvlib-python
kevinsa5 Jan 26, 2019
96d0cf3
rename poorly-named variables in irradiance.clearsky_index
kevinsa5 Jan 27, 2019
dc5b9ca
truncate nan/inf values to zero in irradiance.clearsky_index
kevinsa5 Jan 30, 2019
86e4531
update whatsnew and api.rst
kevinsa5 Jan 30, 2019
cc0120f
Merge branch 'master' into master
kevinsa5 Jan 30, 2019
6fbe8a3
improved formatting to satisfy stickler
kevinsa5 Jan 30, 2019
6fb9a33
Merge branch 'master' of https://github.com/kevinsa5/pvlib-python
kevinsa5 Jan 30, 2019
20f189a
preserve input nans for irradiance.clearsky_index
kevinsa5 Jan 30, 2019
f9f6079
remove trailing whitespace
kevinsa5 Jan 30, 2019
329d0ca
refactor irradiance.clearsky_index to simplify type-handling logic. …
kevinsa5 Jan 31, 2019
a6e1940
revert change to inf/nan handling; input infs yield clearsky_index=nan
kevinsa5 Jan 31, 2019
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/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Clearness index models

irradiance.clearness_index
irradiance.clearness_index_zenith_independent
irradiance.clearsky_index


PV Modeling
Expand Down
3 changes: 3 additions & 0 deletions docs/sphinx/source/whatsnew/v0.6.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Enhancements
* Created :py:func:`pvlib.pvsystem.pvsyst_celltemp` to implement PVsyst's cell temperature model. (:issue:`552`)
* Created :py:func:`pvlib.bifacial.pvfactors_timeseries` to use open-source `pvfactors` package to calculate back surface irradiance (:issue:`421`)
* Add `PVSystem` class method :py:func:`~pvlib.pvsystem.PVSystem.pvsyst_celltemp` (:issue:`633`)
* Add :py:func:`pvlib.irradiance.clearsky_index` to calculate clear-sky index
from measured GHI and modeled clear-sky GHI. (:issue:`551`)


Bug fixes
Expand Down Expand Up @@ -102,3 +104,4 @@ Contributors
* Jonathan Gaffiot (:ghuser:`jgaffiot`)
* Marc Anoma (:ghuser:`anomam`)
* Anton Driesse (:ghuser:`adriesse`)
* Kevin Anderson (:ghuser:`kevinsa5`)
42 changes: 42 additions & 0 deletions pvlib/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,48 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
return sky_diffuse


def clearsky_index(ghi, clearsky_ghi, max_clearsky_index=2.0):
"""
Calculate the clearsky index.

The clearsky index is the ratio of global to clearsky global irradiance.
Negative and non-finite clearsky index values will be truncated to zero.

Parameters
----------
ghi : numeric
Global horizontal irradiance in W/m^2.

clearsky_ghi : numeric
Modeled clearsky GHI

max_clearsky_index : numeric, default 2.0
Maximum value of the clearsky index. The default, 2.0, allows
for over-irradiance events typically seen in sub-hourly data.

Returns
-------
clearsky_index : numeric
Clearsky index
"""
clearsky_index = ghi / clearsky_ghi
# set +inf, -inf, and nans to zero
clearsky_index = np.where(~np.isfinite(clearsky_index), 0,
clearsky_index)
# but preserve nans in the input arrays
input_is_nan = ~np.isfinite(ghi) | ~np.isfinite(clearsky_ghi)
clearsky_index = np.where(input_is_nan, np.nan, clearsky_index)

clearsky_index = np.maximum(clearsky_index, 0)
clearsky_index = np.minimum(clearsky_index, max_clearsky_index)

# preserve input type
if isinstance(ghi, pd.Series):
clearsky_index = pd.Series(clearsky_index, index=ghi.index)

return clearsky_index


def clearness_index(ghi, solar_zenith, extra_radiation, min_cos_zenith=0.065,
max_clearness_index=2.0):
"""
Expand Down
39 changes: 39 additions & 0 deletions pvlib/test/test_irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,45 @@ def test_kt_kt_prime_factor(airmass_kt):
assert_allclose(out, expected, atol=1e-5)


def test_clearsky_index():
ghi = np.array([-1., 0., 1., 500., 1000., np.nan])
ghi_measured, ghi_modeled = np.meshgrid(ghi, ghi)
# default max_clearsky_index
with np.errstate(invalid='ignore', divide='ignore'):
out = irradiance.clearsky_index(ghi_measured, ghi_modeled)
expected = np.array(
[[1. , 0. , 0. , 0. , 0. , np.nan],
[0. , 0. , 0. , 0. , 0. , np.nan],
[0. , 0. , 1. , 2. , 2. , np.nan],
[0. , 0. , 0.002 , 1. , 2. , np.nan],
[0. , 0. , 0.001 , 0.5 , 1. , np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]])
assert_allclose(out, expected, atol=0.001)
# specify max_clearsky_index
with np.errstate(invalid='ignore', divide='ignore'):
out = irradiance.clearsky_index(ghi_measured, ghi_modeled,
max_clearsky_index=1.5)
expected = np.array(
[[1. , 0. , 0. , 0. , 0. , np.nan],
[0. , 0. , 0. , 0. , 0. , np.nan],
[0. , 0. , 1. , 1.5 , 1.5 , np.nan],
[0. , 0. , 0.002 , 1. , 1.5 , np.nan],
[0. , 0. , 0.001 , 0.5 , 1. , np.nan],
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]])
assert_allclose(out, expected, atol=0.001)
# scalars
out = irradiance.clearsky_index(10, 1000)
expected = 0.01
assert_allclose(out, expected, atol=0.001)
# series
times = pd.DatetimeIndex(start='20180601', periods=2, freq='12H')
ghi_measured = pd.Series([100, 500], index=times)
ghi_modeled = pd.Series([500, 1000], index=times)
out = irradiance.clearsky_index(ghi_measured, ghi_modeled)
expected = pd.Series([0.2, 0.5], index=times)
assert_series_equal(out, expected)


def test_clearness_index():
ghi = np.array([-1, 0, 1, 1000])
solar_zenith = np.array([180, 90, 89.999, 0])
Expand Down