Skip to content

scaling.wvm: return unchanged signal for a single site - #2896

Open
bfs2021 wants to merge 2 commits into
pvlib:mainfrom
bfs2021:fix/wvm-single-site
Open

bfs2021 wants to merge 2 commits into
pvlib:mainfrom
bfs2021:fix/wvm-single-site

Conversation

@bfs2021

@bfs2021 bfs2021 commented Oct 10, 2026 •

Copy link
Copy Markdown

Problem

pvlib.scaling.wvm returns an entirely NaN output for a layout with one coordinate pair. See #2895 for the full report, including the float-precision analysis (0.29 * 100 == 28.999...-style rounding is a separate symptom of the same rounder).

Root cause

With a single position, scipy.spatial.distance.pdist returns an empty distance array, so n_pairs = 0 and the effective-size objective has two roots (x=0 and x=1). The optimizer converges to n_dist = 0, which makes the Eq. 6 denominator 2 * sum(rho) + n_dist equal to zero — dividing by zero yields NaN for every timescale, and the reconstructed signal is all NaN.

Fix

_compute_vr now returns a variability reduction factor of 1 for every timescale when positions contains a single site. Per the WVM equations, one site has no pairwise correlations and therefore no variability reduction, so wvm passes the input signal through unchanged — the behavior the issue describes as expected.

Testing

  • test_compute_vr_single_site: _compute_vr with one position returns all ones for every timescale.
  • test_wvm_single_site: wvm with one position returns the input signal unchanged (previously all NaNs).
  • pytest tests/test_scaling.py → 18 passed (16 existing + 2 new), Python 3.12, Windows.

Fixes #2895

Checklist

  • Closes BUG: scaling.wvm returns all NaNs for a single-site layout #2895
  • I am familiar with the contributing guidelines
  • I attest that all AI-generated material has been vetted for accuracy and is in compliance with the pvlib license
  • Tests added
  • Adds a "what's new" entry in docs/sphinx/source/whatsnew/v0.16.2.rst (:issue:2895, :pull:2896, by :ghuser:bfs2021)
  • New code is fully documented. (no public API change; the single-site early return is commented in code with a link to this issue)
  • Pull request is nearly complete and ready for detailed review.

With one position, pdist returns an empty distance array and the
effective-size optimizer converges to n_dist=0, so _compute_vr divided
by zero and scaling.wvm returned an all-NaN signal. A single site has no
variability reduction, so _compute_vr now returns a reduction factor of
1 for every timescale and wvm passes the input through unchanged.

Fixes pvlib#2895

Signed-off-by: bfs2021 <101915083+bfs2021@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Hey @bfs2021! 🎉

Thanks for opening your first pull request! We appreciate your
contribution. Please ensure you have reviewed and understood the
contributing guidelines.

If AI is used for any portion of this PR, you must vet the content
for technical accuracy.

Finally, be sure the PR description includes the PR
checklist,
and complete the items you are able to.

Signed-off-by: bfs2021 <101915083+bfs2021@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: scaling.wvm returns all NaNs for a single-site layout

1 participant