[Python-modules-commits] [python-pysolar] 11/11: Updated sun path code, added __init__.py
Wolfgang Borgert
debacle at moszumanska.debian.org
Fri Oct 3 23:36:18 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to annotated tag 0.4.0
in repository python-pysolar.
commit a627996677a9a19d335c250269a5d40425c5833c
Author: pingswept <brandon at pingswept.org>
Date: Thu Jun 18 17:42:42 2009 -0400
Updated sun path code, added __init__.py
---
__init__.py | 1 +
horizon.py | 48 ++++++++++++++--------------
spherical.jpg | Bin 0 -> 844711 bytes
sun_path_widget.py | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 116 insertions(+), 23 deletions(-)
diff --git a/__init__.py b/__init__.py
index e69de29..276ca2c 100644
--- a/__init__.py
+++ b/__init__.py
@@ -0,0 +1 @@
+from solar import *
diff --git a/horizon.py b/horizon.py
index e5a1ac9..10d1df8 100644
--- a/horizon.py
+++ b/horizon.py
@@ -61,6 +61,7 @@ def despherifyImage(im):
(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
@@ -115,35 +116,36 @@ def getAzimuthZero():
def getAltitudeZero():
return 380
-horizon = []
+if __name__ == '__main__':
+ horizon = []
-im = Image.open('spherical.jpg').convert("L")
-im = squareImage(im)
+ im = Image.open('spherical.jpg').convert("L")
+ im = squareImage(im)
-print 'Starting despherification . . .'
-lin = despherifyImage(im)
+ print 'Starting despherification . . .'
+ lin = despherifyImage(im)
-print 'Despherification complete. Calculating horizon . . .'
-d = differentiateImageColumns(lin).convert("RGB")
-r, horizon = redlineImage(d)
-print 'Horizon calculated.'
+ 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
+ (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
+ 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'
+ 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)
+ 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.show()
-#sp3.save('sun_path.jpg')
+# sp3.save('sun_path.jpg')
diff --git a/spherical.jpg b/spherical.jpg
new file mode 100644
index 0000000..96fe108
Binary files /dev/null and b/spherical.jpg differ
diff --git a/sun_path_widget.py b/sun_path_widget.py
new file mode 100755
index 0000000..6f8da51
--- /dev/null
+++ b/sun_path_widget.py
@@ -0,0 +1,90 @@
+#!/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