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.orgEither 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.