Skip to content

Commit

Permalink
Updated sun path code, added __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pingswept committed Jun 18, 2009
1 parent cfd2cd4 commit a627996
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 23 deletions.
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from solar import *
48 changes: 25 additions & 23 deletions horizon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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')
Binary file added spherical.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 90 additions & 0 deletions sun_path_widget.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a627996

Please sign in to comment.