Skip to content

invalid value warning when calculating diffuse fraction in infinite_sheds #2450

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

Open
kandersolar opened this issue Apr 30, 2025 · 1 comment · May be fixed by #2451
Open

invalid value warning when calculating diffuse fraction in infinite_sheds #2450

kandersolar opened this issue Apr 30, 2025 · 1 comment · May be fixed by #2451
Milestone

Comments

@kandersolar
Copy link
Member

When supplying numpy arrays for ghi and dhi that have zeros (e.g. for nighttime), a warning is emitted:

import pvlib
import pandas as pd

times = pd.date_range("2019-06-01", freq="1min", periods=1440, tz="Etc/GMT+5")
location = pvlib.location.Location(40, -80)

sp = location.get_solarposition(times)
cs = location.get_clearsky(times)

ret = pvlib.bifacial.infinite_sheds.get_irradiance(
    surface_tilt=20,
    surface_azimuth=180,
    solar_zenith=sp['zenith'],
    solar_azimuth=sp['azimuth'],
    gcr=0.5,
    height=2.0,
    pitch=0.5,
    ghi=cs['ghi'].values,  # arrays
    dhi=cs['dhi'].values,
    dni=cs['dni'].values,
    albedo=0.2,
)
\lib\site-packages\pvlib\bifacial\infinite_sheds.py:345: RuntimeWarning: invalid value encountered in divide
  diffuse_fraction = np.clip(dhi / ghi, 0., 1.)

We could simply suppress the warning, but I think a better solution is to do away with the calculation entirely. This diffuse fraction is used only in the _poa_ground_shadows function, which computes the average irradiance reflected from the ground, accounting for the shadows cast by rows and the restricted ground->sky view factor:

return poa_ground * (f_gnd_beam*(1 - df) + df*vf_gnd_sky)

where df is the diffuse fraction and poa_ground is ghi * albedo. The math is equivalent to the following:

albedo * (f_gnd_beam * (ghi - dhi) + vf_gnd_sky * dhi)

This alternative means we don't need to calculate the diffuse fraction at all, and (to me) is an improvement in clarity as well. I propose dropping diffuse_fraction and using the above calculation instead. Note that the line in question is in a private function, so it is no issue to change the relevant function signature.

@kandersolar kandersolar added this to the v0.12.1 milestone Apr 30, 2025
@kandersolar kandersolar linked a pull request Apr 30, 2025 that will close this issue
7 tasks
@cwhanse
Copy link
Member

cwhanse commented Apr 30, 2025

The original implementation was likely trying to hew close to the paper, from which we've departed already, so no harm now.

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

Successfully merging a pull request may close this issue.

2 participants