public
Description: Pysolar is a collection of Python libraries for simulating the irradiation of any point on earth by the sun. It includes code for extremely precise ephemeris calculations.
Homepage: http://pysolar.org
Clone URL: git://github.com/pingswept/pysolar.git
pingswept (author)
Thu Jun 18 20:29:58 -0700 2009
commit  6f7f4be3a27d393f3672040748d7a5d63707a735
tree    ed6689e60a90b22944e547c6a54289d1152df1f1
parent  a627996677a9a19d335c250269a5d40425c5833c
pysolar / shade_test.py
100644 70 lines (63 sloc) 2.361 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python
 
# Test of solar panel shading calculations
 
# Copyright 2007 Brandon Stafford
#
# This file is part of Pysolar.
#
# Pysolar is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Pysolar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Pysolar. If not, see <http://www.gnu.org/licenses/>.
 
import solar
import shade
import datetime
from pylab import *
#from itertools import izip
 
def ShadeTest():
latitude_deg = 42.364908
longitude_deg = -71.112828
width = 100
height = 200
area = width * height
d = datetime.datetime.utcnow()
thirty_minutes = datetime.timedelta(hours = 0.5)
times = []
powers = []
shade_x = []
shade_y = []
shaded_powers = []
for i in range(48):
timestamp = d.ctime()
altitude_deg = solar.GetAltitude(latitude_deg, longitude_deg, d)
azimuth_deg = solar.GetAzimuth(latitude_deg, longitude_deg, d)
power = solar.GetRadiationDirect(d, altitude_deg)
xs = shade.GetXShade(width, 120, azimuth_deg)
ys = shade.GetYShade(height, 120, altitude_deg)
shaded_area = xs * ys
shaded_percentage = shaded_area/area
if (altitude_deg > 0):
times.append(float(d.hour) + (float(d.minute)/60) - 5) # - 5 to adjust to EST
powers.append(power)
shade_x.append(xs)
shade_y.append(ys)
shaded_powers.append(power * (1 - shaded_percentage))
#print timestamp, "UTC", altitude_deg, azimuth_deg, power
d = d + thirty_minutes
print times
print powers
print shade_x
 
plot(times, shaded_powers, times, powers) # plot ends up with a line across it because x values wrap around
show() # could fix that with sort function below
 
#def sort(list_to_sort, order): # based on a function by Ron Adam on some Python mailing list
# d = dict(izip(order, list_to_sort))
# assert len(d) == len(list_to_sort)
# list_to_sort[:] = list(d[v] for v in sorted(d))
# return list_to_sort