adamdsouza1 / gheat

Automatically exported from code.google.com/p/gheat
0 stars 0 forks source link

Type error on tile.colorize #9

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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

Original issue reported on code.google.com by marco.de...@gmail.com on 5 May 2008 at 12:04

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
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

Original comment by marco.de...@gmail.com on 5 May 2008 at 4:29

GoogleCodeExporter commented 8 years ago
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.

Original comment by whit537@gmail.com on 5 May 2008 at 5:35

GoogleCodeExporter commented 8 years ago
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

Original comment by marco.de...@gmail.com on 5 May 2008 at 6:24

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

Original comment by whit537@gmail.com on 5 May 2008 at 7:06

GoogleCodeExporter commented 8 years ago

Original comment by whit537@gmail.com on 31 May 2008 at 1:55