Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
pts = []
for x in range(400):
pts.append((random.random(), random.random()))
print "Processing %d points..." % len(pts)
print("Processing %d points..." % len(pts))
hm = heatmap.Heatmap()
img = hm.heatmap(pts).save("classic.png")
4 changes: 2 additions & 2 deletions heatmap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
try:
__version__ = __import__('pkg_resources').get_distribution(__name__).version
except Exception, e:
except Exception as e:
__version__ = 'unknown'

from heatmap import Heatmap
from .heatmap import Heatmap
31 changes: 21 additions & 10 deletions heatmap/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import sys
import ctypes
import platform
import math
import glob

import colorschemes
from .colorschemes import schemes, valid_schemes

from PIL import Image

Expand Down Expand Up @@ -65,12 +65,21 @@ def __init__(self, libpath=None):
libname = "cHeatmap-x86.dll"
if "64" in platform.architecture()[0]:
libname = "cHeatmap-x64.dll"

# to support multiple Python versions
libname_search_string = '*'.join(libname.split('.'))

# now rip through everything in sys.path to find 'em. Should be in site-packages
# or local dir
for d in sys.path:
if os.path.isfile(os.path.join(d, libname)):
self._heatmap = ctypes.cdll.LoadLibrary(
os.path.join(d, libname))
# search for matching file names
for f in glob.glob(os.path.join(d, libname_search_string)):
self._heatmap = ctypes.cdll.LoadLibrary(f)

break

if self._heatmap is not None:
break

if not self._heatmap:
raise Exception("Heatmap shared library not found in PYTHONPATH.")
Expand Down Expand Up @@ -122,7 +131,7 @@ def heatmap(self, points, dotsize=150, opacity=128, size=(1024, 1024), scheme="c
if not ret:
raise Exception("Unexpected error during processing.")

self.img = Image.frombuffer('RGBA', (self.size[0], self.size[1]),
self.img = Image.frombuffer('RGBA', (self.size[0], self.size[1]),
arrFinalImage, 'raw', 'RGBA', 0, 1)
return self.img

Expand All @@ -146,12 +155,12 @@ def _convertScheme(self, scheme):

#TODO is there a better way to do this??
flat = []
for r, g, b in colorschemes.schemes[scheme]:
for r, g, b in schemes[scheme]:
flat.append(r)
flat.append(g)
flat.append(b)
arr_cs = (
ctypes.c_int * (len(colorschemes.schemes[scheme]) * 3))(*flat)
ctypes.c_int * (len(schemes[scheme]) * 3))(*flat)
return arr_cs

def _ranges(self, points):
Expand Down Expand Up @@ -189,10 +198,12 @@ def saveKML(self, kmlFile):
((east, south), (west, north)) = self._ranges(self.points)

bytes = self.KML % (tilePath, north, south, east, west)
file(kmlFile, "w").write(bytes)

with open(kmlFile, 'w') as f:
f.write(bytes)

def schemes(self):
"""
Return a list of available color scheme names.
"""
return colorschemes.valid_schemes()
return valid_schemes()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class mybuild(build_ext):
def run(self):
if "nt" in os.name:
print "On Windows, skipping build_ext."
print("On Windows, skipping build_ext.")
return
build_ext.run(self)

Expand Down