Skip to content

Commit

Permalink
Only take median position when points exist.
Browse files Browse the repository at this point in the history
Previously, when we attempted to take the median position of a list of points we
relied on the (old, pre-1.10) NumPy behaviour of providing NaN as the median
of an empty array. Newer NumPy will raise an IndexError instead. Here, we
explicitly check that we have at least one point before taking the median.
  • Loading branch information
jdswinbank committed Oct 12, 2015
1 parent b8b8ce7 commit ab1f342
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion python/lsst/meas/algorithms/objectSizeStarSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ def _kcenters(yvec, nCluster, useMedian=False, widthStdAllowed=0.15):
break

for i in range(nCluster):
centers[i] = func(yvec[clusterId == i])
# Only compute func if some points are available; otherwise, default to NaN.
pointsInCluster = (clusterId == i)
if numpy.any(pointsInCluster):
centers[i] = func(yvec[clusterId == i])
else:
centers[i] = numpy.nan

return centers, clusterId

Expand Down

0 comments on commit ab1f342

Please sign in to comment.