Skip to content

Commit

Permalink
min_location_count applies before knn
Browse files Browse the repository at this point in the history
  • Loading branch information
François Laurent committed Feb 22, 2018
1 parent e6c68af commit 375f828
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
8 changes: 5 additions & 3 deletions tramway/helper/tessellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ def cell_plot(cells, xy_layer=None, output_file=None, fig_format=None, \
labels = ()
elif not isinstance(labels, (tuple, list)):
labels = (labels, )
if isinstance(input_file, (tuple, list)):
if input_file[1:]:
warn('can only process a single file', RuntimeWarning)
input_file = input_file[0]
try:
analyses = load_rwa(input_file)
if labels:
Expand All @@ -580,8 +584,6 @@ def cell_plot(cells, xy_layer=None, output_file=None, fig_format=None, \
if e.args and 'analyses' not in e.args[0]:
raise
# legacy code
if isinstance(input_file, list):
input_file = input_file[0]
imt_path = input_file
if imt_path is None:
raise ValueError('undefined input file')
Expand Down Expand Up @@ -685,7 +687,7 @@ def cell_plot(cells, xy_layer=None, output_file=None, fig_format=None, \
plot_points(cells, min_count=min_location_count, **locations)
if aspect is not None:
fig.gca().set_aspect(aspect)
if xy_layer == 'voronoi' or voronoi:
if xy_layer != 'delaunay' and voronoi:
if not isinstance(voronoi, dict):
voronoi = {}
plot_voronoi(cells, **voronoi)
Expand Down
19 changes: 9 additions & 10 deletions tramway/tessellation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,13 @@ def cell_index(self, points, format=None, select=None, knn=None,
x = points[cell]
if not filter(self, c, x):
K[cell] = -1
# min_location_count:
# set K[i] = -1 for all point i in cells that are too small
if min_location_count:
excluded_cells = positive_count < min_location_count
if np.any(excluded_cells):
for c in nonempty[excluded_cells]:
K[K == c] = -1
# max_nn:
# set K[i] = -1 for all point i in cells that are too large
if max_nn:
Expand Down Expand Up @@ -751,18 +758,10 @@ def cell_index(self, points, format=None, select=None, knn=None,
Ic = np.logical_not(point_in_small_cells)
Jc = K[Ic]
Ic, = Ic.nonzero()
if max_nn:
Ic = Ic[0 <= Jc]
Jc = Jc[0 <= Jc]
Ic = Ic[0 <= Jc]
Jc = Jc[0 <= Jc]
#
K = (np.concatenate((I, Ic)), np.concatenate((J, Jc)))
# min_location_count:
# set K[i] = -1 for all point i in cells that are too small
elif min_location_count:
excluded_cells = positive_count < min_location_count
if np.any(excluded_cells):
for c in nonempty[excluded_cells]:
K[K == c] = -1
else:
K = np.argmin(D, axis=1) # cell indices
point_count = points.shape[0]
Expand Down

0 comments on commit 375f828

Please sign in to comment.