Skip to content

BUG: fix kimber cleaning threshold and grace period off-by-one - #2814

Open
dgowdaan-cmyk wants to merge 3 commits into
pvlib:mainfrom
dgowdaan-cmyk:fix-kimber-threshold-grace
Open

BUG: fix kimber cleaning threshold and grace period off-by-one#2814
dgowdaan-cmyk wants to merge 3 commits into
pvlib:mainfrom
dgowdaan-cmyk:fix-kimber-threshold-grace

Conversation

@dgowdaan-cmyk

Copy link
Copy Markdown
Contributor

Fixes #2796.

pvlib.soiling.kimber used a strict > comparison against
cleaning_threshold, so rainfall exactly equal to the threshold did not
trigger cleaning, contrary to Kimber (2006). It also had an off-by-one
error in the grace period window: grace_period=1 effectively provided
zero days of protection because the rolling window excluded the rain
event's own day.

This PR:

  • Changes the comparison to >= so rainfall equal to the threshold cleans
    the panel.

  • Changes the grace period rolling window from closed='right' to
    closed='both' so the rain day itself is included, giving the full
    grace_period days of protection as documented.

  • Regenerates the recorded expected test data
    (greensboro_kimber_soil_nowash.dat, greensboro_kimber_soil_manwash.dat)
    to reflect the corrected behavior.

  • Adds two new tests covering the threshold-equal case and the
    grace_period=1 case.

  • Closes kimber grace and rain threshold implementation differences #2796

  • 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 description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:2796.

  • New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.

  • Pull request is nearly complete and ready for detailed review.

- rainfall equal to cleaning_threshold now triggers cleaning
- grace_period window now correctly includes the rain day itself
- regenerated greensboro nowash/manwash expected test data
- added tests for both cases

Fixes pvlib#2796
@dgowdaan-cmyk

Copy link
Copy Markdown
Contributor Author

@echedey-ls / @mikofski This is ready for review whenever you get a chance. Summary of the change:

  • Fixed pvlib.soiling.kimber: rainfall exactly equal to cleaning_threshold now triggers cleaning (was using strict >, now >=), matching Kimber (2006)
  • Fixed an off-by-one error in the grace period window: grace_period=N now correctly protects N full days after a rain event, by changing the rolling window from closed='right' to closed='both'
  • Regenerated the recorded expected test data (greensboro_kimber_soil_nowash.dat, greensboro_kimber_soil_manwash.dat) to reflect the corrected output
  • Added two new tests: one for rainfall exactly at the threshold, one for grace_period=1
  • Updated the whatsnew entry under Bug fixes

Let me know if anything else is needed on my end.

@mikofski mikofski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thx! @dgowdaan-cmyk please add your name to list of contributors. @cwhanse is this considered a breaking change? Anything special we need to do if it is?

@mikofski

mikofski commented Jul 9, 2026

Copy link
Copy Markdown
Member

@dgowdaan-cmyk can you fix the flake errors please? Thx!

@dgowdaan-cmyk

Copy link
Copy Markdown
Contributor Author

@mikofski Fixed the flake8 error (E127 continuation line indentation in test_soiling.py) and added my name to the contributors list. Let me know if anything else needs adjusting!

@cwhanse

cwhanse commented Jul 9, 2026

Copy link
Copy Markdown
Member

@mikofski do you recall the source of the greensboro_ files used in the tests?

@mikofski

Copy link
Copy Markdown
Member

@mikofski do you recall the source of the greensboro_ files used in the tests?

It’s from tmy3

@cwhanse

cwhanse commented Jul 11, 2026

Copy link
Copy Markdown
Member

@mikofski do you recall the source of the greensboro_ files used in the tests?

It’s from tmy3

The expected output from kimber was computed from TMY3 input, using the buggy code?

@mikofski

Copy link
Copy Markdown
Member

@cwhanse, yes, it’s what’s in this example. Guess I didn’t do a very good job getting it first 🤣

@cwhanse

cwhanse commented Jul 11, 2026

Copy link
Copy Markdown
Member

@cwhanse, yes, it’s what’s in this example. Guess I didn’t do a very good job getting it first 🤣

Thanks, now I understand why the expected output files are changing.

Comment thread pvlib/soiling.py

# grace periods windows during which ground is assumed damp, so no soiling
grace_windows = rain_events.rolling(grace_period, closed='right').sum() > 0
grace_windows = rain_events.rolling(grace_period, closed='both').sum() > 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not fix the off-by-one issue with grace periods. Grace periods are in days; closed='both' just adds the next timestamp to the grace period. In the case of the tests, it's adding one hour. rolling applies closed to the input data, not the output.

@dgowdaan-cmyk dgowdaan-cmyk Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yeah I see what you mean now @cwhanse
closed='both' doesn't solve it for daily grace periods.
We would need to shift the result forward by N-1 days instead.

I will take a look and push a fix for this. Thanks for catching it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants