iam.schlick_diffuse returns inf and nan at surface_tilt=180

Open Beginner friendly
#2,939 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start by reading pvlib.iam.schlick_diffuse and its tests for the existing surface_tilt=0 ground-term special case. Reproduce the reported result at surface_tilt=180, then check both diffuse components at the endpoints and nearby tilts. Done when the function returns the expected sky and ground values without a divide-by-zero warning, with regression tests covering the behavior.

Written by the indexing model from the issue text.

Description

Describe the bug
pvlib.iam.schlick_diffuse(180) returns {'sky': inf, 'ground': nan} with a RuntimeWarning: divide by zero. Eq 4 for the sky term divides by 1 + cos(surface_tilt), which is 0/0 at 180. The ground term is already special-cased at tilt 0 (surface_tilt < 1e-6); the sky term has no equivalent at 180.

To Reproduce

import pvlib
pvlib.iam.schlick_diffuse(180)
# {'sky': inf, 'ground': nan}

Expected behavior
sky is 0 (a surface facing straight down sees no sky; the value tends to 0 as the tilt approaches 180) and ground is 20/21 = 0.9524, the same as sky at tilt 0. marion_diffuse('schlick', surface_tilt=180) gives 0 and 0.95236.

Versions:

  • pvlib.__version__: 0.16.2.dev19+gc5de586d7
  • pandas.__version__: 3.1.1
  • python: 3.12.12

Additional context
Found while reading the code. PVSystem.get_iam_diffuse(180, iam_model='schlick_diffuse') returns the same. I can open a PR that applies the same 1e-6 clamp to the sky term.

Dominant language
Python
Stars
1.7k
Forks
1.2k
Avg merge
3d 4h
Merged PRs (30d)
8

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pvlib/pvlib-python

All issues in pvlib/pvlib-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.