jjguy / heatmap

Python module to create heatmaps
MIT License
142 stars 52 forks source link

Weighted Heatmap #14

Open wrousseau opened 10 years ago

wrousseau commented 10 years ago

Hi there,

Great tool, thanks a lot for it. Because I needed "weighted heatmaps" support (the possibility to add "cold" points but also the possibility to specify the dot size for each point), I have forked your project (https://github.com/wrousseau/heatmap).

Two things :

Cheers

kwauchope commented 10 years ago

Hi,

I've done the same thing with my own install, not on git as yet. I did it slightly different than you. Two main things:

I didn't have a separate float array for the weights, just a flag that defaulted to False in the main heatmap python. This is then pushed through to the C lib so it knows to increment by 3 rather than 2 each loop. This means it was compatible with the original usage of the library.

The second and main change was the weight itself. I just normalised the weights from 0-1 using weight/maxWeight. For negative or if you wanted the lowest weight to equal zero you could try (weight-minWeight)/(maxWeight-minWeight). Dividing pixVal by the normlised weight for each point seemed to work well. I normalised the weights before calling heatmap but you could add your own normalising function in heatmap as well.

Happy to add weights to my fork if you are interested.

Cheers

wrousseau commented 10 years ago

Hey there,

I don't really need this anymore, but I can only guess some other people will be interested eventually as I was unable to find any weighted heatmap in Python.

I think you should definatly add this feature to your fork. If it does not break compatibility, you might even want to try a pull request (not sure the original author still plans on updating this but still...).

Cheers

BryceHarlan commented 10 years ago

@kwauchope Weighted heat-maps would help with a project that I've been working on. I would love for you to add weights to your fork

kwauchope commented 10 years ago

@BryceHarlan I'll throw it in next week if that works for you.

BryceHarlan commented 10 years ago

@kwauchope Not a problem! Thanks for sharing!

kwauchope commented 10 years ago

Rough code is up, added some basic tests and getting results that look ok at least. Weights between 0 and 1 as discussed in my previous post. Not tested in anger so let me know how you go :)

BryceHarlan commented 10 years ago

@kwauchope Thank you so much! You may not be the best person to ask, but how exactly is the coordinate system set up? My data is ultimately mapping to a 2048 px square image, so if I wanted to log one point at pixel (1500,1500) (assuming the origin is in the bottom left and x_right and y_up are positive) would I enter (1500/2048,1500/2048, )?

BryceHarlan commented 10 years ago

@kwauchope Nevermind. Figured out the issue I was having after playing around with it some more. Thanks again!

jjguy commented 10 years ago

@BryceHarlan @kwauchope @wrousseau sorry for ignoring the thread here for so long, balancing too much in life these days.

I'm happy to merge back into the core, as long as the switches/options/etc are tight. If I need to polish them up it'll get pushed to the back burner for a while.

FWIW, I've been slow rolling changes in this area, the next block of time sink into heatmap will probably get invested in a normalization layer, so density of points is independent of the visual representation. As it exists today, if you've got a large number of points, the heatmap image is completely saturated.

kwauchope commented 10 years ago

Off topic from the original thread but I like the idea of normalisation, I was looking at that for one of the next things to add. Not only for high density but also to keep track of the maximum and perhaps have some sort of scale. It also means really strong points still stand out rather than all converging to 255.

BryceHarlan commented 10 years ago

@kwauchope @jjguy Normalization was the next layer that I was looking to add as well, so I'd love to contribute!

jjguy commented 10 years ago

@BryceHarlan @kwauchope see #22 for my thoughts to date on implementation. we can move this topic to that ticket.