Skip to content
Open
Show file tree
Hide file tree
Changes from all 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.16.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Bug fixes
~~~~~~~~~
* :py:func:`pvlib.tracking.calc_surface_orientation` returns scalar when input
is scalar (:issue:`2881`, :pull:`2882`)
* :py:func:`pvlib.scaling.wvm` no longer returns all NaNs when ``positions``
contains a single site (:issue:`2895`, :pull:`2896`) by :ghuser:`bfs2021`

Enhancements
~~~~~~~~~~~~
Expand Down
5 changes: 5 additions & 0 deletions pvlib/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def _compute_vr(positions, cloud_speed, tmscales):
# Added by Joe Ranalli (@jranalli), Penn State Hazleton, 2021

pos = np.array(positions)
if len(pos) <= 1:
# A single site has no pairwise distances, so the variability
# reduction is 1; the effective-size optimizer below would converge
# to n_dist=0 and divide by zero. See GH #2895.
return np.ones(tmscales.shape)
dist = pdist(pos, 'euclidean')

# Find effective length of position vector, 'dist' is full pairwise
Expand Down
14 changes: 14 additions & 0 deletions tests/test_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,17 @@ def test_wvm_series_xyaslist(clear_sky_index, time, positions,
def test_wvm_invalid(clear_sky_index, positions):
with pytest.raises(ValueError):
scaling.wvm(clear_sky_index, positions, cloud_speed)


def test_compute_vr_single_site(expect_tmscale):
vr = scaling._compute_vr(np.array([(0., 0.)]), cloud_speed,
np.array(expect_tmscale))
assert_almost_equal(vr, np.ones(len(expect_tmscale)))


def test_wvm_single_site(clear_sky_index):
# A single site has no variability reduction: the smoothed signal is the
# input unchanged. Previously returned all NaNs. See GH #2895.
single_site = np.array([(0., 0.)])
cs_sm, _, _ = scaling.wvm(clear_sky_index, single_site, cloud_speed, dt=dt)
assert_almost_equal(cs_sm[5000:5005], clear_sky_index[5000:5005])