Closed piyushrpt closed 6 months ago
You can test the density tiler with the following example:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from spurt.utils import DensityTiler
shape = (5000, 7000)
ii = np.random.beta(1, 1, size=50000)
jj = np.random.beta(1, 1, size=50000)
jj = ii * 0.7 + jj * 0.3
ii = ii * shape[0]
jj = jj * shape[1]
points = np.column_stack((ii, jj))
tiler = DensityTiler(points, shape=shape, max_tiles=16)
print(tiler.tiles.shape, tiler.neighbors.shape)
fig, ax = plt.subplots(1, 1, figsize=(7, 7))
ax.set_ylim(0, shape[0])
ax.set_xlim(0, shape[1])
sum_diag = 0
sum_diag2 = 0
for p in tiler.tiles:
ax.add_patch(Rectangle((p[1], p[0]), p[3] - p[1], p[2] - p[0],
facecolor='none', linewidth=1, edgecolor='k'))
ax.scatter(jj, ii, color='grey',alpha=0.1)
plt.show()