Page 1 of 1

Solar incidence angle calculation, anyone?

PostPosted: Thu May 16, 2013 12:50 pm
by Perry The Cynic
Does anyone have Python code handy to calculate the solar incidence angles (essentially, which direction the sun shines from at a given point in time at a given spot)? For my application, just "here and now" would be sufficient.

Why? I want to command venetian blinds to block out the sun only while it's shining onto that particular window.

Indigo already knows about sunrise and sunset; is there enough data inside to track the sun? All it would take is two wee little numbers... :-)

Cheers
-- perry

Re: Solar incidence angle calculation, anyone?

PostPosted: Wed May 22, 2013 10:24 am
by bschollnick2
Perry The Cynic wrote:
Does anyone have Python code handy to calculate the solar incidence angles (essentially, which direction the sun shines from at a given point in time at a given spot)? For my application, just "here and now" would be sufficient.

Why? I want to command venetian blinds to block out the sun only while it's shining onto that particular window.

Indigo already knows about sunrise and sunset; is there enough data inside to track the sun? All it would take is two wee little numbers... :-)


Perry,

This is probably overkill, but it's the closest that I could find.

Pysolar
http://pysolar.org

Either of these might help:

Estimate of clear-sky radiation

Once you calculate azimuth and altitude of the sun, you can predict the direct irradiation from the sun using solar.GetRadiationDirect(), which returns a value in watts per square meter. As of version 0.2, the function is not smart enough to return zeros at night (thus the crazy 1814 W/m^2^ output below). It does account for the scattering of light by the atmosphere, though it uses an atmospheric model based on data taken in the United States.

>>> latitude_deg = 42.3 # positive in the northern hemisphere
>>> longitude_deg = -71.4 # negative reckoning west from prime meridian in Greenwich, England
>>> altitude_deg = solar.GetAltitude(latitude_deg, longitude_deg, d)
>>> azimuth_deg = solar.GetAzimuth(latitude_deg, longitude_deg, d)
>>> solar.radiation.GetRadiationDirect(d, altitude_deg)
1814.2039909409739
Shading calculation

For a row of rectangular photovoltaic panels that track the sun, adjacent panels will shade each other in the morning and afternoon, reducing power output. You can create a power estimate that takes into account the shading of adjacent panels.

>>> import shade
>>> width = 100
>>> height = 200
>>> x_spacing = 120
>>> y_spacing = 120
>>> xs = shade.GetXShade(width, x_spacing, azimuth_deg)
>>> ys = shade.GetYShade(height, y_spacing, altitude_deg)
>>> shaded_area = xs * ys
>>> shaded_percentage = shaded_area/(width * height)
Need to add graph of power vs. time here

The graph above was created by calculating the power, including attenuation due to shading, at an interval of 30 minutes. The attenuation is assumed to be linearly proportional to area, which is probably optimistic, even if bypass diodes are used. The graph was created with matplotlib; see shade_test.py for usage.

Re: Solar incidence angle calculation, anyone?

PostPosted: Wed May 22, 2013 1:53 pm
by Perry The Cynic
This is probably overkill, but it's the closest that I could find.

Thanks. That one's definitely overkill - I don't need <0.1deg precision (no Nutation Compensation required :-)), and really no solar incidence power data either. (It's also GPL3-licensed, which means I can't actually stick it inside my code without being taken over by the Borg.)

I was sort of hoping someone had a rough-and-ready 50-line Python fragment stashed away somewhere; but it looks like all the authors are very concerned with the irregular shape of the Earth... I'll probably just end up pulling out a textbook and writing a simple (+/- 2 degrees or so) approximation.

Cheers
-- perry