Skip to content

fix _delta_kt_prime_dirint end values #638

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 9 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
2 changes: 2 additions & 0 deletions docs/sphinx/source/whatsnew/v0.6.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Bug fixes
* Fix documentation errors when using IPython >= 7.0.
* Fix error in :func:`pvlib.modelchain.ModelChain.infer_spectral_model` (:issue:`619`)
* Fix error in ``pvlib.spa`` when using Python 3.7 on some platforms.
* Fix error in :func:`pvlib.irradiance._delta_kt_prime_dirint` (:issue: `637`). The error affects
the first and last values of DNI calculated by the function :func:`pvlib.irradiance.dirint`


Testing
Expand Down
14 changes: 10 additions & 4 deletions pvlib/irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,14 +1558,20 @@ def _dirint_from_dni_ktprime(dni, kt_prime, solar_zenith, use_delta_kt_prime,

def _delta_kt_prime_dirint(kt_prime, use_delta_kt_prime, times):
"""
Calculate delta kt prime (Perez eqn 2), or return a default value
Calculate delta_kt_prime (Perez eqn 2 and eqn 3), or return a default value
for use with :py:func:`_dirint_bins`.
"""
if use_delta_kt_prime:
# Perez eqn 2
delta_kt_prime = 0.5*((kt_prime - kt_prime.shift(1)).abs().add(
(kt_prime - kt_prime.shift(-1)).abs(),
fill_value=0))
kt_next = kt_prime.shift(-1)
kt_previous = kt_prime.shift(1)
# replace nan with values that implement Perez Eq 3 for first and last
# positions. Use kt_previous and kt_next to handle series of length 1
kt_next.iloc[-1] = kt_previous.iloc[-1]
kt_previous.iloc[0] = kt_next.iloc[0]
delta_kt_prime = 0.5 * ((kt_prime - kt_next).abs().add(
(kt_prime - kt_previous).abs(),
fill_value=0))
else:
# do not change unless also modifying _dirint_bins
delta_kt_prime = pd.Series(-1, index=times)
Expand Down
18 changes: 9 additions & 9 deletions pvlib/test/test_irradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,13 @@ def test_dirint_value():
pressure = 93193.
dirint_data = irradiance.dirint(ghi, zenith, times, pressure=pressure)
assert_almost_equal(dirint_data.values,
np.array([ 888. , 683.7]), 1)
np.array([868.8, 699.7]), 1)


def test_dirint_nans():
times = pd.DatetimeIndex(start='2014-06-24T12-0700', periods=5, freq='6H')
ghi = pd.Series([np.nan, 1038.62, 1038.62, 1038.62, 1038.62], index=times)
zenith = pd.Series([10.567, np.nan, 10.567, 10.567, 10.567,], index=times)
zenith = pd.Series([10.567, np.nan, 10.567, 10.567, 10.567], index=times)
pressure = pd.Series([93193., 93193., np.nan, 93193., 93193.], index=times)
temp_dew = pd.Series([10, 10, 10, np.nan, 10], index=times)
dirint_data = irradiance.dirint(ghi, zenith, times, pressure=pressure,
Expand All @@ -489,7 +489,7 @@ def test_dirint_tdew():
dirint_data = irradiance.dirint(ghi, zenith, times, pressure=pressure,
temp_dew=10)
assert_almost_equal(dirint_data.values,
np.array([892.9, 636.5]), 1)
np.array([882.1, 672.6]), 1)


def test_dirint_no_delta_kt():
Expand Down Expand Up @@ -559,7 +559,7 @@ def test_gti_dirint():
expected = pd.DataFrame(array(
[[ 21.05796198, 0. , 21.05796198],
[ 288.22574368, 60.59964218, 245.37532576],
[ 930.85454521, 695.8504884 , 276.96897609]]),
[ 931.04078010, 695.94965324, 277.06172442]]),
columns=expected_col_order, index=times)

assert_frame_equal(output, expected)
Expand All @@ -583,7 +583,7 @@ def test_gti_dirint():
expected = pd.DataFrame(array(
[[ 21.05796198, 0. , 21.05796198],
[ 289.81109139, 60.52460392, 247.01373353],
[ 932.22047435, 647.68716072, 323.59362885]]),
[ 932.46756378, 648.05001357, 323.49974813]]),
columns=expected_col_order, index=times)

assert_frame_equal(output, expected)
Expand All @@ -595,9 +595,9 @@ def test_gti_dirint():
albedo=albedo)

expected = pd.DataFrame(array(
[[ 21.3592591 , 0. , 21.3592591 ],
[ 292.5162373 , 64.42628826, 246.95997198],
[ 941.47847463, 727.07261187, 258.25370648]]),
[[ 21.3592591, 0. , 21.3592591 ],
[ 292.5162373, 64.42628826, 246.95997198],
[ 941.6753031, 727.16311901, 258.36548605]]),
columns=expected_col_order, index=times)

assert_frame_equal(output, expected)
Expand All @@ -611,7 +611,7 @@ def test_gti_dirint():
expected = pd.DataFrame(array(
[[ 21.05796198, 0. , 21.05796198],
[ 292.40468994, 36.79559287, 266.3862767 ],
[ 930.72198876, 712.36063132, 261.32196017]]),
[ 931.79627208, 689.81549269, 283.5817439]]),
columns=expected_col_order, index=times)

assert_frame_equal(output, expected)
Expand Down