Is this a bug in the source code for Calculating DHI?

Hi Mostapha and Chris,

While I was working on a research project using the “direct solar irradiance” component in Ladybug, I realized that the equation used to calculate diffuse irradiance for anisotropic sky is (0.313 * math.cos(vec_angle) * 0.313 * math.cos(vec_angle), in https://www.ladybug.tools/ladybug/docs/_modules/ladybug/wea.html , while in an ASHRAE document (page 7) the equation is 0.313 x cos^2(theta). I wonder if this is a bug or if there was a reason to use 0.313^2 instead of just 0.313?

ASHRAE document:

Good catch. The difference between 0.313 × cos²(theta) and 0.313² × cos²(theta) seems worth checking, especially since it can affect the calculated diffuse irradiance. Hopefully someone familiar with the implementation can clarify whether this was intentional or just a typo in the source code.

Thanks, @Alax_Morgan and @cdwu ,

Looks like it’s a bug that goes all of the way back to Ladybug Legacy.

I must have made the mistake 9 years ago when I added the anisotrophic sky model there:

… and then I must have copied into the new ladybug source code without double-checking the primary source. I’ll push a fix to the latest ladybug source code shortly.

The bug was fixed here:

.. .and the fix will be available via the LB Versioner component in an hour or so. Thanks again for reporting, @cdwu !

Thank you Chris for fixing the bug! Your contribution to the community is invaluable. Cheers! - Chengde.