pvlib / solarfactors

A community-maintained implementation of the pvfactors bifacial irradiance model
BSD 3-Clause "New" or "Revised" License
6 stars 4 forks source link

maximum recursion depth with perez_diffuse_luminance #6

Open kandersolar opened 1 year ago

kandersolar commented 1 year ago

Originally submitted as https://github.com/SunPower/pvfactors/issues/146 by @pasquierjb:

When calling perez_diffuse_luminance irradiance model with a panel configuration where the solar vector is almost orthogonal to the surface normal, the computation falls into an infinite recursion loop.

from pvfactors.irradiance.models import perez_diffuse_luminance

timestamps = ['2020-01-02 15:00:00+00:00']
surface_tilt=[86.43564127244697]
surface_azimuth=[312.7]
solar_zenith=[78.53023197697105]
solar_azimuth=[221.9758276910072]
DNI=[100]
DHI=[50]

perez_diffuse_luminance(
timestamps, surface_tilt, surface_azimuth, solar_zenith,
solar_azimuth, DNI, DHI)
RecursionError: maximum recursion depth exceeded while calling a Python object

This is probably because the dot product of the solar vector and both surface normal (front and back) is computed as negative by pvlib.

from pvlib import irradiance
surface_tilt = 86.43564127244697
surface_azimuth = 312.7
solar_azimuth = 221.9758276910072
solar_zenith = 78.53023197697105

irradiance.aoi_projection(surface_tilt, surface_azimuth, solar_zenith, solar_azimuth)
-3.642919299551295e-17

irradiance.aoi_projection(180-surface_tilt, surface_azimuth-180, solar_zenith, solar_azimuth)
-3.642919299551295e-17