Permalink
Browse files

heat map appearance improved, with support for color_scheme files

  • Loading branch information...
1 parent 0cf5bb6 commit de56cf6a948e11121b6e54acf133109e2838207c @lehrblogger committed Nov 30, 2009
View
@@ -1,5 +1,5 @@
application: where-do-you-go
-version: 2-3
+version: 2-4
runtime: python
api_version: 1
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,8 +1,10 @@
import pngcanvas
+from google.appengine.api import urlfetch
+import os
TRANSPARENCY = 100
-def createScheme(steps=255, r_start=255, g_start=255, b_start=255,
+def createScheme(steps=255, r_start=255, g_start=255, b_start=255,
r_step=-3.0, g_step=-1.0, b_step=-1.0):
img = pngcanvas.PNGCanvas(30, steps)
r_cur = r_start
@@ -22,4 +24,21 @@ def createScheme(steps=255, r_start=255, g_start=255, b_start=255,
if b_cur < 0: b_step *= -1; b_cur = 0 + b_step;
return img
-cyan_red = createScheme()
+def loadScheme(name, steps=255):
+ ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
+ file_loc = os.path.join(ROOT_DIR, 'color-schemes/' + name + '.png')
+ f = open(file_loc, "rb")
+ img = pngcanvas.PNGCanvas(24, steps, bgcolor=[0xff,0xff,0xff,TRANSPARENCY])
+ img.load(f)
+ f.close()
+ return img
+
+
+cyan_red = createScheme()
+classic = loadScheme("classic")
+fire = loadScheme("fire")
+omg = loadScheme("omg")
+pbj = loadScheme("pbj")
+pgaitch = loadScheme("pgaitch")
+sjl_classic = loadScheme("sjl_classic")
+sjl_fire = loadScheme("sjl_fire")
@@ -198,6 +198,7 @@ def load(self,f):
j = 0
for x in range(width):
pixel = rgb[j:j+3]
+ pixel.append(100)
row.append(pixel)
j = j + 3
self.canvas.append(row)
@@ -251,8 +252,9 @@ def chunks(self,f):
crc = struct.unpack("!i",f.read(4))[0]
except:
return
- if zlib.crc32(tag + data) != crc:
- raise IOError
+ #SJL http://conceptualadvantage.com/grow-your-concept/using-google-appengine-and-the-pure-python-pngcanvas/
+ # if zlib.crc32(tag + data) != crc:
+ # raise IOError
yield [tag,data]
if __name__ == '__main__':
View
@@ -12,16 +12,18 @@
rdm = Random()
-LEVEL_MAX = 500
+LEVEL_MAX = 450
cache = None
cache_levels = []
-for i in range(LEVEL_MAX):
+for i in range(LEVEL_MAX - 1, -1, -1):
cache_levels.append(int(((-(pow(float(i) - LEVEL_MAX, 2))/LEVEL_MAX) + LEVEL_MAX) / LEVEL_MAX * 255))
class BasicTile(object):
def __init__(self, lat_north, lng_west, range_lat, range_lng):
+ self.color_scheme = color_scheme.sjl_classic#classic#cyan_red
+
self.tile_img = self.plot_image(globalvars.provider.get_user_data(users.get_current_user(), #self.layer,
lat_north, lng_west,range_lat, range_lng))
@@ -67,25 +69,20 @@ def __merge_point_in_space(self, space_level, point):
# logging.debug("incrementing space_level[%d][%d] to %f" % (x,y,space_level[y - y_off][x - x_off]))
def scale_space_level(self, space_level, x, y):
- logs = math.log(max(space_level[y][x] / 50, 1), 1.01)
- return int(logs)
+ #ret_float = math.log(max((space_level[y][x] + 50) / 50, 1), 1.01) + 30
+ ret_float = math.log(max((space_level[y][x] + 30) / 40, 1), 1.01) + 30
+ return int(ret_float)
def convert_image(self, space_level):
tile = PNGCanvas(len(space_level[0]), len(space_level), bgcolor=[0xff,0xff,0xff,0])
color_scheme = []
+ logging.warning(self.color_scheme.canvas)
for i in range(LEVEL_MAX):
color_scheme.append(self.color_scheme.canvas[cache_levels[i]][0])
-
- spacemax = 0
for y in xrange(len(space_level[0])):
for x in xrange(len(space_level[0])):
tile.canvas[y][x] = color_scheme[min(len(color_scheme) - 1, self.scale_space_level(space_level, x, y))]
- if self.scale_space_level(space_level, x, y) > spacemax: spacemax = self.scale_space_level(space_level, x, y)
-
- logging.warning("spacemax=" + str(spacemax))
- logging.warning("len of color_scheme=" + str(len(color_scheme)))
-
return tile
def get_dot(self, point):
@@ -125,7 +122,6 @@ def image_out(self):
class CustomTile(BasicTile):
def __init__(self, zoom, lat_north, lng_west, offset_x_px, offset_y_px):
self.zoom = zoom
- self.color_scheme = color_scheme.cyan_red
self.decay = 0.5
dot_radius = int(math.ceil(len(dot[self.zoom]) / 2))
@@ -148,7 +144,6 @@ class GoogleTile(BasicTile):
def __init__(self, layer, zoom, x_tile, y_tile):
self.layer = layer
self.zoom = zoom
- self.color_scheme = color_scheme.cyan_red
self.decay = 0.5
dot_radius = int(math.ceil(len(dot[self.zoom]) / 2))
View
@@ -233,7 +233,7 @@ def get(self):
# color_scheme = color_schemes[color_scheme]
# try:
new_tile = tile.GoogleTile(layer, zoom, x, y)
- logging.info("Start-B1: %2.2f" % (time.clock() - st))
+ #logging.info("Start-B1: %2.2f" % (time.clock() - st))
# except Exception, err:
# self.respondError(err)
# raise err

0 comments on commit de56cf6

Please sign in to comment.