Export to GitHub

gheat - issue #9

Type error on tile.colorize


Posted on May 5, 2008 by Massive Bird

My system:

Windows XP SP2 full updated python-2.5.2 pygame-1.8.0.win32-py2.5 numpy-1.0.4.win32-p3-py2.5 aspen-0.8 gheat-0.2

when i try to create the sample heatmap with:

http://localhost:8080/classic/4/4,6.png

i obtain this error:

Traceback (most recent call last): File "\python25\lib\site-packages\aspen\wsgiserver.py", line 625, in communicate req.respond() File "\python25\lib\site-packages\aspen\wsgiserver.py", line 357, in respond response = self.wsgi_app(self.environ, self.start_response) File "\python25\lib\site-packages\aspen\website.py", line 53, in call response = app(environ, start_response) # WSGI File "\Python25\Scripts__\lib\python\gheat__init__.py", line 169, in wsgi tile.rebuild() File "\Python25\Scripts__\lib\python\gheat\base.py", line 248, in rebuild self.img = self.hook_rebuild(points()) File "\Python25\Scripts__\lib\python\gheat\pygame_.py", line 69, in hook_rebuild tile = self.colorize(tile) File "\Python25\Scripts_\lib\python\gheat\pygame_.py", line 126, in _colorize if (conf, pixel) not in _computed_opacities: TypeError: unhashable type: 'array'

after some tests (i'm not a python dev) i've found that the problem is in:

def _colorize(self, tile): ..... .....

if (conf, pixel) not in _computed_opacities: opacity = int(( (conf/255.0) # from configuration * (pixel/255.0) # from per-pixel alpha ) * 255) _computed_opacities[(conf, pixel)] = opacity

            pix[x,y] = self.color_scheme.color_map[key]
            alp[x,y] = _computed_opacities[(conf, pixel)]

..... .....

if i remove the above code that compute the colors, everything was fine but the map is (obviously) gray scale

this is the code with some problem....

Bye

Comment #1

Posted on May 5, 2008 by Massive Bird

Comment deleted

Comment #2

Posted on May 5, 2008 by Massive Bird

Comment deleted

Comment #3

Posted on May 5, 2008 by Massive Bird

after isolating the problem exposed on previous post, I've tried to make some debug on code...(remember that I'm not native python dev) after some hours on try to understand the real problem, I've found that the code :

conf, pixel = self.opacity, self.color_scheme.alpha_map[key]

is the real problem... the instruction

self.color_scheme.alpha_map[key]

SEEMS return an array instead a int if i make a cast on this with conf, pixel = self.opacity, int(self.color_scheme.alpha_map[key]) the map as been created but the opacity is wrong (is really dark). So, after some other check i've see that the code:

pygame.surfarray.pixels_alpha(colors)[0]

return every time an array of 255 element with 255 as value for all elements as i can understand, seem that the opacity is set every time to the most dark value.

i hope this can help on debug the problem and on finding a solution

TIA

Comment #4

Posted on May 5, 2008 by Helpful Rhino

Hrm ... try the nightly build of PyGame:

http://thorbrian.com/pygame/builds.php

Actually, you've reminded me that there is another problem in 1.8.0 (saving to PNG is broken!) that means you need a dev version of PyGame. I will add a note to the homepage about that.

Comment #5

Posted on May 5, 2008 by Massive Bird

thank you for your reply, i thought that the problem can be the library because I've checked the image created by gheat with a binary editor (because irfanview say that the file are not a png but a jpg) and i found a jpg file instead a png file! (with png extension) i think that, as you say, the problem is the library that create a jpg instead a png file. Another information that you can add on installation documents is that (almost under winxp) you need to install numpy or you receive an obscure exception like this :

raise ImportError("Neither Pygame nor PIL could be imported.")

ImportError: Neither Pygame nor PIL could be imported. [apps.conf, line 1]

this seems a problem with pygame or PIL but is a missing numpy library error.. i spent 1 hour to understand this :)

P.s. many many thanks for this great pieces of software, is really useful for me and with this tool I've the opportunity to try a great language like python

Comment #6

Posted on May 5, 2008 by Helpful Rhino

Thanks for your persistence and feedback. I've added notes to the project page regarding Pygame installation gotchas.

Comment #7

Posted on May 31, 2008 by Helpful Rhino

(No comment was entered for this change.)

Status: Closed