heatmap icon indicating copy to clipboard operation
heatmap copied to clipboard

Weighted Heatmap

Open wrousseau opened this issue 12 years ago • 12 comments

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 :

  • It's a quick hack, would you be interested in such feature for a merge ?
  • I think the only thing a bit dodgy I did is for the blending in "calcDensity". I obviously could not used your formula to compute pixel values, so I added my own but I'm not quite satisfied with the visual result. The formula I use is a result of several tries, but there is no theory behind that. If you have a better idea, I'm a taker !

Cheers

wrousseau avatar Nov 01 '13 14:11 wrousseau

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

kwauchope avatar May 05 '14 11:05 kwauchope

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

wrousseau avatar May 05 '14 12:05 wrousseau

@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

BryceHarlan avatar Jul 25 '14 22:07 BryceHarlan

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

kwauchope avatar Jul 26 '14 04:07 kwauchope

@kwauchope Not a problem! Thanks for sharing!

BryceHarlan avatar Jul 26 '14 04:07 BryceHarlan

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 :)

kwauchope avatar Jul 28 '14 12:07 kwauchope

@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 avatar Jul 28 '14 20:07 BryceHarlan

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

BryceHarlan avatar Jul 28 '14 20:07 BryceHarlan

@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.

jjguy avatar Jul 30 '14 19:07 jjguy

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.

kwauchope avatar Jul 31 '14 12:07 kwauchope

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

BryceHarlan avatar Jul 31 '14 17:07 BryceHarlan

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

jjguy avatar Jul 31 '14 18:07 jjguy