Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

heat map appearance improved, with support for color_scheme files

  • Loading branch information...
commit de56cf6a948e11121b6e54acf133109e2838207c 1 parent 0cf5bb6
Steven Lehrburger authored November 30, 2009
2  app.yaml
... ...
@@ -1,5 +1,5 @@
1 1
 application: where-do-you-go
2  
-version: 2-3
  2
+version: 2-4
3 3
 runtime: python
4 4
 api_version: 1
5 5
 
BIN  gheatae/color-schemes/master.psd
Binary file not shown
BIN  gheatae/color-schemes/sjl_classic.png
BIN  gheatae/color-schemes/sjl_fire.png
23  gheatae/color_scheme.py
... ...
@@ -1,8 +1,10 @@
1 1
 import pngcanvas
  2
+from google.appengine.api import urlfetch
  3
+import os
2 4
 
3 5
 TRANSPARENCY = 100
4 6
 
5  
-def createScheme(steps=255, r_start=255, g_start=255, b_start=255, 
  7
+def createScheme(steps=255, r_start=255, g_start=255, b_start=255,
6 8
     r_step=-3.0, g_step=-1.0, b_step=-1.0):
7 9
   img = pngcanvas.PNGCanvas(30, steps)
8 10
   r_cur = r_start
@@ -22,4 +24,21 @@ def createScheme(steps=255, r_start=255, g_start=255, b_start=255,
22 24
     if b_cur < 0: b_step *= -1; b_cur = 0 + b_step;
23 25
   return img
24 26
 
25  
-cyan_red = createScheme()
  27
+def loadScheme(name, steps=255):
  28
+  ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
  29
+  file_loc = os.path.join(ROOT_DIR, 'color-schemes/' + name + '.png')
  30
+  f = open(file_loc, "rb")
  31
+  img = pngcanvas.PNGCanvas(24, steps, bgcolor=[0xff,0xff,0xff,TRANSPARENCY])
  32
+  img.load(f)
  33
+  f.close()
  34
+  return img
  35
+
  36
+
  37
+cyan_red    = createScheme()
  38
+classic     = loadScheme("classic")
  39
+fire        = loadScheme("fire")
  40
+omg         = loadScheme("omg")
  41
+pbj         = loadScheme("pbj")
  42
+pgaitch     = loadScheme("pgaitch")
  43
+sjl_classic = loadScheme("sjl_classic")
  44
+sjl_fire    = loadScheme("sjl_fire")
6  gheatae/pngcanvas.py
@@ -198,6 +198,7 @@ def load(self,f):
198 198
           j = 0
199 199
           for x in range(width):
200 200
             pixel = rgb[j:j+3]
  201
+            pixel.append(100)
201 202
             row.append(pixel)
202 203
             j = j + 3
203 204
           self.canvas.append(row)
@@ -251,8 +252,9 @@ def chunks(self,f):
251 252
         crc = struct.unpack("!i",f.read(4))[0]
252 253
       except:
253 254
         return
254  
-      if zlib.crc32(tag + data) != crc:
255  
-        raise IOError
  255
+      #SJL http://conceptualadvantage.com/grow-your-concept/using-google-appengine-and-the-pure-python-pngcanvas/
  256
+      # if zlib.crc32(tag + data) != crc:
  257
+      #   raise IOError
256 258
       yield [tag,data]
257 259
 
258 260
 if __name__ == '__main__':
21  gheatae/tile.py
@@ -12,16 +12,18 @@
12 12
 
13 13
 rdm = Random()
14 14
 
15  
-LEVEL_MAX = 500
  15
+LEVEL_MAX = 450
16 16
 
17 17
 cache = None
18 18
 cache_levels = []
19  
-for i in range(LEVEL_MAX):
  19
+for i in range(LEVEL_MAX - 1, -1, -1):
20 20
   cache_levels.append(int(((-(pow(float(i) - LEVEL_MAX, 2))/LEVEL_MAX) + LEVEL_MAX) / LEVEL_MAX * 255))
21 21
 
22 22
 class BasicTile(object):
23 23
 
24 24
   def __init__(self, lat_north, lng_west, range_lat, range_lng):
  25
+    self.color_scheme = color_scheme.sjl_classic#classic#cyan_red
  26
+
25 27
     self.tile_img = self.plot_image(globalvars.provider.get_user_data(users.get_current_user(), #self.layer,
26 28
                             lat_north, lng_west,range_lat, range_lng))
27 29
 
@@ -67,25 +69,20 @@ def __merge_point_in_space(self, space_level, point):
67 69
       #     logging.debug("incrementing space_level[%d][%d] to %f" % (x,y,space_level[y - y_off][x - x_off]))
68 70
 
69 71
   def scale_space_level(self, space_level, x, y):
70  
-    logs = math.log(max(space_level[y][x] / 50, 1), 1.01)
71  
-    return int(logs)
  72
+    #ret_float = math.log(max((space_level[y][x] + 50) / 50, 1), 1.01) + 30
  73
+    ret_float = math.log(max((space_level[y][x] + 30) / 40, 1), 1.01) + 30
  74
+    return int(ret_float)
72 75
 
73 76
   def convert_image(self, space_level):
74 77
     tile = PNGCanvas(len(space_level[0]), len(space_level), bgcolor=[0xff,0xff,0xff,0])
75 78
     color_scheme = []
  79
+    logging.warning(self.color_scheme.canvas)
76 80
     for i in range(LEVEL_MAX):
77 81
       color_scheme.append(self.color_scheme.canvas[cache_levels[i]][0])
78  
-
79  
-    spacemax = 0
80 82
     for y in xrange(len(space_level[0])):
81 83
       for x in xrange(len(space_level[0])):
82 84
         tile.canvas[y][x] = color_scheme[min(len(color_scheme) - 1, self.scale_space_level(space_level, x, y))]
83 85
 
84  
-        if self.scale_space_level(space_level, x, y) > spacemax: spacemax = self.scale_space_level(space_level, x, y)
85  
-
86  
-    logging.warning("spacemax=" + str(spacemax))
87  
-    logging.warning("len of color_scheme=" + str(len(color_scheme)))
88  
-
89 86
     return tile
90 87
 
91 88
   def get_dot(self, point):
@@ -125,7 +122,6 @@ def image_out(self):
125 122
 class CustomTile(BasicTile):
126 123
   def __init__(self, zoom, lat_north, lng_west, offset_x_px, offset_y_px):
127 124
     self.zoom = zoom
128  
-    self.color_scheme = color_scheme.cyan_red
129 125
     self.decay = 0.5
130 126
     dot_radius = int(math.ceil(len(dot[self.zoom]) / 2))
131 127
 
@@ -148,7 +144,6 @@ class GoogleTile(BasicTile):
148 144
   def __init__(self, layer, zoom, x_tile, y_tile):
149 145
     self.layer = layer
150 146
     self.zoom = zoom
151  
-    self.color_scheme = color_scheme.cyan_red
152 147
     self.decay = 0.5
153 148
     dot_radius = int(math.ceil(len(dot[self.zoom]) / 2))
154 149
 
2  handlers.py
@@ -233,7 +233,7 @@ def get(self):
233 233
     # color_scheme = color_schemes[color_scheme]
234 234
     # try:
235 235
     new_tile = tile.GoogleTile(layer, zoom, x, y)
236  
-    logging.info("Start-B1: %2.2f" % (time.clock() - st))
  236
+    #logging.info("Start-B1: %2.2f" % (time.clock() - st))
237 237
     # except Exception, err:
238 238
     #   self.respondError(err)
239 239
     #   raise err

0 notes on commit de56cf6

Please sign in to comment.
Something went wrong with that request. Please try again.