Closed bluescarni closed 9 years ago
@astrofrog I ran some tests to verify that the output makes sense. For instance, let's take a grid with 1000 sites and 1E6 sampling points requested (with no minimum number of samples per cell):
>>> from hyperion.grid import voronoi_helpers as vh
>>> import numpy as np
>>> N = 1000
>>> x,y,z = [np.random.uniform(size=N) for _ in range(3)]
>>> sites_arr = np.array([x, y, z]).transpose()
>>> g = vh.voronoi_grid(sites_arr, np.array([[0, 1.], [0, 1], [0, 1]]),n_samples=1000000,min_cell_samples=0)
Now:
>>> len(g.samples)
1000000
In order to verify the consistency:
>>> np.diff(g.samples_idx) / g.neighbours_table['volume']
<Column name='volume' unit=None format=None description=None>
array([ 1018694.15040659, 1080715.16884351, 976212.09429447,
1098848.13745834, 1008257.2629003 , 1032139.54447319,
1018753.84790525, 1005302.99701911, 1078185.42701527,
991726.70469929, 976558.35358736, 978557.28966799,
1072755.41271036, 904619.75511727, 1043178.37164639,
985434.55154042, 1074977.81301676, 978790.20543328,
972130.46901091, 1068138.72618046, 1035370.55618304,
999640.36688186, 1037506.31109164, 970565.7576943 ,
1010189.57693786, 996529.92285498, 1021826.53152044,
984787.45982084, 1021248.37949541, 989204.98248675,
That is, the ratio between cell volume and number of samples in that cell is more or less constant.
Does this make sense to you?
@bluescarni - looks great, thanks!
This should guarantee that exactly the number of samples requested is generated, if no minimum number of samples per cell is specified.