Hi,guys. I want to develop a simplify compotent to calculate the sunlight hour and solar radiation using Grasshooper Python. Would you like to tell me which method sunlight hour and solar radiation used?

# Which method are sunlight hour and radiation using?

Hi Minggang, can you be more specific about what you are looking for?

If you are referring to methodology, Annual radiation is using the gencumulative sky approach, sun light hours in Ladybug are using sunvectors whose positions are derived from time-stamps in EPW files, sunlight hours in the [+] libraries are using the rcontrib approach with Radiance and so on.

It’s been a while since I dug up the source code, so @AbrahamYezioro or @mostapha will be able to provide a more definitive (and correct) answer.

Sarith

Hi @sarith,

I think you pretty much said what is need to say. At least i don’t have something to add.

-A.

Hi,@sarith @AbrahamYezioro Thanks for your reply. I just want to how to calculate the sun vector. I have read the Python code of sunpath, it is hard to understand it. Is there any detailed method to calculate the sun vector? And how to use sunvector to calculate the sunlight hour？

The Python code of Sunpath for Ladybug[+] is clearer to understand (,than that for Ladybug legacy,) as it is written without any reference to the methods from Grasshopper or Rhinocommon. This code is based on the methodology followed by NOAA. You should be able to dig up the formulae from their example spreadsheets here.

I think the spreadsheets stop at the calculation of azimuth and altitude angles. However, once you have those, the calculation of sun vectors are fairly simple. See here or below.

```
def _calculate_sun_vector(self):
"""Calculate sun vector for this sun."""
z_axis = Vector3D(0., 0., -1.)
x_axis = Vector3D(1., 0., 0.)
north_vector = Vector3D(0., 1., 0.)
# rotate north vector based on azimuth, altitude, and north
_sun_vector = north_vector \
.rotate(x_axis, self.altitude_in_radians) \
.rotate(z_axis, self.azimuth_in_radians) \
.rotate(z_axis, math.radians(-1 * self.north_angle))
_sun_vector.normalize()
_sun_vector = _sun_vector.reverse()
return _sun_vector
```

Sarith

(Edit: PS: The above reply is based on what I remember of the code… in case I am off, please correct me @mostapha !)

PS:PS: Probably this is a better reference for the methodology than the spreadsheet… http://www.nrel.gov/docs/fy08osti/34302.pdf

@minggangyin,

if you can please elaborate on why do you need to develop a new component people would be able to help you better.

As @sarith pointed out, based on NOAA methods, azimuth and altitude are derived. That gives you the location of the sun in a three dimensional cordinate system [Point 2]. You already have the location of the center point of the sunpath [Point 1]. By joining these two points you can create a line and a vector.

This is happening at line 1581 in Ladybug_Ladybug