Details

Type: Bug

Status: Done

Resolution: Done

Fix Version/s: None

Component/s: meas_algorithms

Labels:None

Story Points:0.5

Epic Link:

Sprint:Science Pipelines DMW162

Team:Data Release Production
Description
Old NumPy behaviour (tested on 1.6.2):
In [1]: import numpy


In [2]: a = numpy.array([])


In [3]: numpy.median(a)

/usr/lib64/python2.6/sitepackages/numpy/core/fromnumeric.py:2374: RuntimeWarning: invalid value encountered in double_scalars

return mean(axis, dtype, out)


Out[3]: nan

New NumPy behaviour (1.10.0):
In [1]: import numpy


In [2]: a = numpy.array([])


In [3]: numpy.median(a)

[...]

IndexError: index 1 is out of bounds for axis 0 with size 0

This breaks testPsfDeterminer and testPsfDeterminerSubimage, e.g.:
ERROR: testPsfDeterminerSubimage (__main__.SpatialModelPsfTestCase)

Test the (PCA) psfDeterminer on subImages



Traceback (most recent call last):

File "./testPsfDetermination.py", line 342, in testPsfDeterminerSubimage

trimCatalogToImage(subExp, self.catalog))

File "/Users/jds/Projects/Astronomy/LSST/src/meas_algorithms/python/lsst/meas/algorithms/objectSizeStarSelector.py", line 377, in selectStars

widthStdAllowed=self._widthStdAllowed)

File "/Users/jds/Projects/Astronomy/LSST/src/meas_algorithms/python/lsst/meas/algorithms/objectSizeStarSelector.py", line 195, in _kcenters

centers[i] = func(yvec[clusterId == i])

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sitepackages/numpy/lib/function_base.py", line 3084, in median

overwrite_input=overwrite_input)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sitepackages/numpy/lib/function_base.py", line 2997, in _ureduce

r = func(a, **kwargs)

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sitepackages/numpy/lib/function_base.py", line 3138, in _median

n = np.isnan(part[..., 1])

IndexError: index 1 is out of bounds for axis 0 with size 0

Here's a simple fix. Suggestions as to whether there's a more efficient way to do this with NumPy magic welcome.