Skip to content

invalid value warning when calculating diffuse fraction in infinite_sheds #2450

@kandersolar

Description

@kandersolar

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions