Open jovan-actdigital opened 3 weeks ago
Hi @jovan-actdigit, I'm glad to hear of your interest in fastKDE.
At first glance, what you describe looks a lot like the first example from the README:
'''python
""" Demonstrate the first README example. """ import numpy as np import fastkde import matplotlib.pyplot as plt
N = int(1e5) x = 50np.random.normal(size=N) + 0.1 y = 0.01np.random.normal(size=N) - 300
PDF = fastkde.pdf(x, y, var_names = ['x', 'y'])
PDF.plot(); '''
Could you please check whether this accomplishes what you're hoping?
What i want is to create heatmap over a floormap given an array of x,y coordinates. The code that worked best so far is:
cov = np.eye(2)*64
N = 10
x_points = np.array([])
y_points = np.array([])
for center in centers:
x, y = np.random.multivariate_normal(center, cov, N).T
# print(x)
x_points = np.append(x_points, x)
y_points = np.append(y_points,y)
fig, ax = plt.subplots()
density, grid_points = fastKDE.pdf(x_points, y_points)
# For visualization (optional)
bg = mpimg.imread('floorplan.png')
bg = cv2.resize(bg, (1920 , 1080))
plt.imshow(bg)
ax.contourf(grid_points[0], grid_points[1], density,levels=100, cmap='jet', alpha=0.7)
Problem is I would like for the generated heatmap to be smoother, like one i get with the code i posted above. Do you know what should I change/fix to get the same result?
Can you post example images of your code vs fastKDE? I’m not in a place where I can easily run code right now
From: jovan-skoric-act @.> Sent: Wednesday, August 28, 2024 6:48:37 AM To: LBL-EESA/fastkde @.> Cc: taobrienlbl @.>; Comment @.> Subject: Re: [LBL-EESA/fastkde] Question about heatmap creation (Issue #40)
What i want is to create heatmap over a floormap given an array of x,y coordinates. The code that worked best so far is:
cov = np.eye(2)*64 N = 10 x_points = np.array([]) y_points = np.array([]) for center in centers: x, y = np.random.multivariate_normal(center, cov, N).T
x_points = np.append(x_points, x)
y_points = np.append(y_points,y)
fig, ax = plt.subplots()
density, grid_points = fastKDE.pdf(x_points, y_points)
# For visualization (optional)
bg = mpimg.imread('floorplan.png')
bg = cv2.resize(bg, (1920 , 1080))
plt.imshow(bg)
ax.contourf(grid_points[0], grid_points[1], density,levels=100, cmap='jet', alpha=0.7)
Problem is I would like for the generated heatmap to be smoother, like one i get with the code i posted above. Do you know what should I change/fix to get the same result?
— Reply to this email directly, view it on GitHubhttps://github.com/LBL-EESA/fastkde/issues/40#issuecomment-2314974703, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACDDUFVTSEXGGGBOYDLM3Z3ZTWTILAVCNFSM6AAAAABNH3ACDGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJUHE3TINZQGM. You are receiving this because you commented.Message ID: @.***>
My code heatmap: FastKDE code heatmap:
Thanks! What I'm seeing is about what I'd expect from fastKDE--I just wanted to make sure this wasn't an edge case that caused fastKDE to behave oddly (doesn't look like it). That's as good as it will likely be able to do.
In comparing your two images, they look almost equivalent to me. The main difference seems to be transparency in the top one but not the bottom; you should be able to add alpha=0.7 when plotting a heatmap with fastKDE too.
You mean lowering alpha value in plt.contour or something specific for fastKDE?
yes, exactly: lowering in plt.contour
Yes: you can set the num_points argument. It has to be a power of 2, plus one: so try 257, 513, or 1025
From: jovan-skoric-act @.> Sent: Thursday, August 29, 2024 6:50:29 AM To: LBL-EESA/fastkde @.> Cc: taobrienlbl @.>; Comment @.> Subject: Re: [LBL-EESA/fastkde] Question about heatmap creation (Issue #40)
Is it possible to make it more smooth when zoomed in? Its to pixelated.
— Reply to this email directly, view it on GitHubhttps://github.com/LBL-EESA/fastkde/issues/40#issuecomment-2317307885, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACDDUFWRL6D64MX6WIORTQLZT34HLAVCNFSM6AAAAABNH3ACDGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJXGMYDOOBYGU. You are receiving this because you commented.Message ID: @.***>
Is it possible to get the same result as this code, using fastkde: