[Python-modules-commits] [python-pysolar] 10/42: Remove weird cruft from when Pysolar was Brandon's personal project

Wolfgang Borgert debacle at moszumanska.debian.org
Fri Oct 3 23:36:59 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to tag 0.6
in repository python-pysolar.

commit 3fc43e96f22a12ab6de51228e9d2cf1fd0110215
Author: Brandon Stafford <brandon at pingswept.org>
Date:   Thu Mar 20 10:28:30 2014 -0400

    Remove weird cruft from when Pysolar was Brandon's personal project
---
 Pysolar/horizon.py    | 157 --------------------------------------------------
 Pysolar/shade.py      |  42 --------------
 Pysolar/shade_test.py |  71 -----------------------
 sun_path_widget.py    |  90 -----------------------------
 4 files changed, 360 deletions(-)

diff --git a/Pysolar/horizon.py b/Pysolar/horizon.py
deleted file mode 100644
index 8011c18..0000000
--- a/Pysolar/horizon.py
+++ /dev/null
@@ -1,157 +0,0 @@
-#!/usr/bin/python
- 
-# Copyright 2009-2010 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/>.
-
-"""This script rectifies spherically distorted images in order to detect the
-angle to solar obstructions. It is not used in Pysolar's ephemeris
-calculations.
-
-An example of this script in action appears here:
-
-http://pingswept.org/2009/03/16/calculating-solar-panel-shading-in-python/
-
-"""
-from PIL import Image
-from math import *
-import numpy as np
-import solar
-import datetime as dt
-import simulate as sim
-import radiation as rad
-
-def squareImage(im):
-    (width, height) = im.size
-    box = ((width - height)/2, 0, (width + height)/2, height)
-    return im.crop(box)
-
-def despherifyImage(im):
-    (width, height) = im.size
-    half_width = im.size[0]/2
-    half_height = im.size[1]/2
-
-    inpix = im.load()
-    out = Image.new("L", (width, half_height))
-    outpix = out.load()
-
-    full_circle = 1000.0 * 2 * pi
-
-#    for r in range(half_width):
-#        for theta in range(int(full_circle)):
-#            (inx, iny) = (round(r * cos(theta/1000.0)) + half_width, round(r * sin(theta/1000.0)) + half_width)
-#            (outx, outy) = (width - width * (theta/full_circle) - 1, r)
-#            outpix[outx, outy] = inpix[inx, iny]
-
-    theta_range = range(int(full_circle))
-    t_1000_range = [t / 1000.0 for t in theta_range]
-    thetas = zip([cos(t) for t in t_1000_range],
-    [sin(t) for t in t_1000_range],
-    [t / full_circle for t in theta_range])
-
-    for r in range(half_width):
-        for t_cos, t_sin, t_full_circle in thetas:
-            (inx, iny) = (round(r * t_cos) + half_width,
-            round(r * t_sin) + half_width)
-            outx = width - width * (t_full_circle) - 1
-#            print inpix, outx, r, inx, iny
-            outpix[outx, r] = inpix[inx, iny]
-    return out
-
-
-
-def differentiateImageColumns(im):
-    (width, height) = im.size
-    pix = im.load()
-
-    for x in range(width):
-        for y in range(height - 1):
-            pix[x, y] = min(10 * abs(pix[x, y] - pix[x, y + 1]), 255)
-
-    return im
-
-def redlineImage(im):
-    (width, height) = im.size
-    pix = im.load()
-
-    threshold = 300
-    horizon = []
-
-    for x in range(width):
-        for y in range(height - 1):
-            (R, G, B) = pix[x, y]
-            if R + G + B > threshold:
-                pix[x, y] = (255, 0, 0)
-                horizon.append(y)
-                break
-    return (im, horizon)
-
-def addSunPaths(im, latitude_deg, longitude_deg, horizon, d):
-    pix = im.load()
-
-    alt_zero = getAltitudeZero()
-    az_zero = getAzimuthZero()
-
-    for m in range(24 * 60):
-        alt = solar.GetAltitude(latitude_deg, longitude_deg, d + dt.timedelta(minutes = m))
-        az = solar.GetAzimuth(latitude_deg, longitude_deg, d + dt.timedelta(minutes = m))
-
-        x = az_zero + int(az * 1944.0/360.0)
-        y = alt_zero - int(alt_zero * sin(radians(alt)))
-        if y < horizon[x]:
-            pix[x % 1944, y] = (255, 193, 37)
-    
-    return im
-
-def getAzimuthZero():
-    return 1100
-
-def getAltitudeZero():
-    return 380
-
-if __name__ == '__main__':
-    horizon = []
-
-    im = Image.open('spherical.jpg').convert("L")
-    im = squareImage(im)
-
-    print 'Starting despherification . . .'
-    lin = despherifyImage(im)
-
-    print 'Despherification complete. Calculating horizon . . .'
-    d = differentiateImageColumns(lin).convert("RGB")
-    r, horizon = redlineImage(d)
-    print 'Horizon calculated.'
-
-    (latitude_deg, longitude_deg) = (42.206, -71.382)
-    summer = dt.datetime(2009, 6, 21, 5, 0, 0, 0)
-    fall = dt.datetime(2009, 9, 21, 5, 0, 0, 0)
-    winter = dt.datetime(2009, 12, 21, 5, 0, 0, 0)
-    step_minutes = 5
-
-    power_densities = [radiation for (time, alt, az, radiation, shade) in sim.SimulateSpan(latitude_deg, longitude_deg, horizon, summer, winter, step_minutes)]
-    print power_densities
-
-    energy = sum(power_densities) * step_minutes * 60
-    print str(energy/1000000) + ' MJ per m^2 per year'
-
-    sp = addSunPaths(r, latitude_deg, longitude_deg, horizon, summer)
-    sp2 = addSunPaths(r, latitude_deg, longitude_deg, horizon, fall)
-    sp3 = addSunPaths(r, latitude_deg, longitude_deg, horizon, winter)
-
-    sp3.show()
-
-#   sp3.save('sun_path.jpg')
diff --git a/Pysolar/shade.py b/Pysolar/shade.py
deleted file mode 100644
index d8d03a7..0000000
--- a/Pysolar/shade.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/python
-
-#    Copyright 2007-2010 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/>.
-
-"""Shade calculation functions
-
-"""
-import math
-
-def GetSideByLawOfCosines(side_a, side_b, included_angle_deg):
-    return math.sqrt(pow((side_a), 2) + pow(side_b, 2) - (2 * side_a * side_b * math.cos(math.radians(included_angle_deg))))
-
-def GetXShade(width, x_spacing, azimuth_deg):
-    n = GetSideByLawOfCosines(width/2, x_spacing, azimuth_deg)
-    p = (width/2) * math.sin(math.radians(azimuth_deg))
-    theta_deg = math.degrees(math.asin(p/n))
-    alpha_deg = azimuth_deg + theta_deg
-    d = GetSideByLawOfCosines(width/2, n, alpha_deg)
-    gamma_deg = math.degrees(math.asin((n * math.sin(math.radians(alpha_deg)))/d))
-    shaded_width = d * math.cos(math.radians(gamma_deg))
-    if(pow(d, 2) + pow(width/2, 2) < pow(n, 2)): # check for obtuse triangle
-        shaded_width = 0
-    #print "theta in deg:", theta_deg, "gamma in deg:", gamma_deg, "shaded width:", shaded_width
-    return min(shaded_width, width)
-
-def GetYShade(height, y_spacing, altitude_deg):
-    return GetXShade(height, y_spacing, 90 - altitude_deg)
diff --git a/Pysolar/shade_test.py b/Pysolar/shade_test.py
deleted file mode 100644
index 65d6bb0..0000000
--- a/Pysolar/shade_test.py
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/python
-
-#    Copyright 2007-2010 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/>.
-
-"""A test module for shading calculations
-
-"""
-import solar
-import shade
-import datetime
-import radiation
-import pylab
-#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 = radiation.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
-	
-	pylab.plot(times, shaded_powers, times, powers)   # plot ends up with a line across it because x values wrap around
-	pylab.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
diff --git a/sun_path_widget.py b/sun_path_widget.py
deleted file mode 100755
index 6f8da51..0000000
--- a/sun_path_widget.py
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/env python
-
-import pygtk
-pygtk.require('2.0')
-import gtk
-import horizon
-
-class Base:
-
-    def __init__(self):
-        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
-        self.window.connect('delete_event', self.delete_event)
-        self.window.connect('destroy', self.destroy)
-
-        self.top_level_hbox = gtk.HBox()
-        self.button_column = gtk.VButtonBox()
-        self.image_column = gtk.VBox()
-        self.load_image_button = gtk.Button('Load image')
-        self.despherify_button = gtk.Button('Despherify')
-        self.horizon_button = gtk.Button('Find horizon')
-        self.add_sun_paths_button = gtk.Button('Add sun paths')
-
-#        self.chooser = gtk.FileChooserDialog(title=None, action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
-
-        self.load_image_button.connect('clicked', FileSelectionExample)
-        self.despherify_button.connect('clicked', horizon.despherifyImage)
-#        self.horizon_button.connect('clicked', horizon)
-        self.add_sun_paths_button.connect('clicked', horizon.addSunPaths)
-
-        self.image = gtk.Image()
-
-        self.window.add(self.top_level_hbox)
-        self.top_level_hbox.pack_start(self.button_column)
-        self.top_level_hbox.pack_end(self.image_column)
-        self.button_column.pack_start(self.load_image_button)
-        self.button_column.pack_start(self.despherify_button)
-        self.button_column.pack_start(self.horizon_button)
-        self.button_column.pack_start(self.add_sun_paths_button)
-        self.image_column.pack_start(self.image)
-
-        self.image.set_from_file('images/sun_path_2009-03-19_800x400.jpg')
-
-        self.image.show()
-        self.load_image_button.show()
-        self.despherify_button.show()
-        self.horizon_button.show()
-        self.add_sun_paths_button.show()
-        self.image_column.show()
-        self.button_column.show()
-        self.top_level_hbox.show()
-        self.window.show()
-
-    def delete_event(self, widget, event, data=None):
-        # could intercept and add "Are you sure?" dialog here
-        return False
-
-    def destroy(self, widget, data=None):
-        gtk.main_quit()
-
-    def main(self):
-        gtk.main()
-
-class FileSelectionExample:
-    # Get the selected filename and print it to the console
-    def file_ok_sel(self, w):
-        print "%s" % self.filew.get_filename()
-
-    def destroy(self, widget):
-        gtk.main_quit()
-
-    def __init__(self, Data):
-        # Create a new file selection widget
-        self.filew = gtk.FileSelection("File selection")
-
-        self.filew.connect("destroy", self.destroy)
-
-        # Connect the ok_button to file_ok_sel method
-        self.filew.ok_button.connect("clicked", self.file_ok_sel)
-                                                                            
-        # Connect the cancel_button to destroy the widget
-        self.filew.cancel_button.connect("clicked", lambda w: self.filew.destroy())
-
-        # Lets set the filename, as if this were a save dialog,
-        # and we are giving a default filename
-        self.filew.set_filename('penguin.png')
-        self.filew.show()
-
-if __name__  == '__main__':
-    base = Base()
-    base.main()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pysolar.git



More information about the Python-modules-commits mailing list