Coverage for tests/test_strayFlux.py : 54%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# # LSST Data Management System # # Copyright 2008-2016 AURA/LSST. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <https://www.lsstcorp.org/LegalNotices/>. #
import matplotlib matplotlib.use('Agg') import pylab as plt import os.path plotpat = os.path.join(os.path.dirname(__file__), 'stray%i.png') print('Writing plots to', plotpat) else:
# Lower the level to Log.DEBUG to see debug messages
bbox = img.getBBox() return [bbox.getMinX(), bbox.getMaxX(), bbox.getMinY(), bbox.getMaxY()]
''' A simple example: three overlapping blobs (detected as 1 footprint with three peaks). We artificially omit one of the peaks, meaning that its flux is "stray". Assert that the stray flux assigned to the other two peaks accounts for all the flux in the parent. '''
afwGeom.Point2I(W-1, H-1))
bbb.getMinX():bbb.getMaxX()+1] += flux * bim2
bbb.getMinX():bbb.getMaxX()+1] += flux * bim2
# Run the detection code to get a ~ realistic footprint
# The first peak in this list is the one we want to omit.
vmin=0, vmax=1e3)
plt.figure(figsize=(12, 6))
plt.clf() plt.suptitle('strayFlux.py: test1 input') plt.subplot(2, 2, 1) plt.title('Image') plt.imshow(img, **ima) ax = plt.axis() plt.plot([x for x, y in XY], [y for x, y in XY], 'r.') plt.axis(ax) for i, (b, (x, y)) in enumerate(zip(blobimgs, XY)): plt.subplot(2, 2, 2+i) plt.title('Blob %i' % i) plt.imshow(b, **ima) ax = plt.axis() plt.plot(x, y, 'r.') plt.axis(ax) plt.savefig(plotpat % 1)
# Change verbose to False to quiet down the meas_deblender.baseline logger
def myimshow(*args, **kwargs): plt.imshow(*args, **kwargs) plt.xticks([]) plt.yticks([]) plt.axis(imExt(afwimg))
plt.clf() plt.suptitle('strayFlux.py: test1 results') #R,C = 3,5 R, C = 3, 4 plt.subplot(R, C, (2*C) + 1) plt.title('Image') myimshow(img, **ima) ax = plt.axis() plt.plot([x for x, y in XY], [y for x, y in XY], 'r.') plt.axis(ax)
plt.subplot(R, C, (2*C) + 2) plt.title('Parent footprint') myimshow(parent_img.getArray(), **ima) ax = plt.axis() plt.plot([pk.getIx() for pk in fakefp.getPeaks()], [pk.getIy() for pk in fakefp.getPeaks()], 'r.') plt.axis(ax)
sumimg = None for i, dpk in enumerate(deb.peaks): plt.subplot(R, C, i*C + 1) plt.title('ch%i symm' % i) symm = dpk.templateImage myimshow(symm.getArray(), extent=imExt(symm), **ima)
plt.subplot(R, C, i*C + 2) plt.title('ch%i portion' % i) port = dpk.fluxPortion.getImage() myimshow(port.getArray(), extent=imExt(port), **ima)
himg = afwImage.ImageF(fpbb) heavy = dpk.getFluxPortion(strayFlux=False) heavy.insert(himg)
# plt.subplot(R, C, i*C + 3) # plt.title('ch%i heavy' % i) # myimshow(himg.getArray(), **ima) # ax = plt.axis() # plt.plot([x for x,y in XY], [y for x,y in XY], 'r.') # plt.axis(ax)
simg = afwImage.ImageF(fpbb) dpk.strayFlux.insert(simg)
plt.subplot(R, C, i*C + 3) plt.title('ch%i stray' % i) myimshow(simg.getArray(), **ima) ax = plt.axis() plt.plot([x for x, y in XY], [y for x, y in XY], 'r.') plt.axis(ax)
himg2 = afwImage.ImageF(fpbb) heavy = dpk.getFluxPortion(strayFlux=True) heavy.insert(himg2)
if sumimg is None: sumimg = himg2.getArray().copy() else: sumimg += himg2.getArray()
plt.subplot(R, C, i*C + 4) myimshow(himg2.getArray(), **ima) plt.title('ch%i total' % i) ax = plt.axis() plt.plot([x for x, y in XY], [y for x, y in XY], 'r.') plt.axis(ax)
plt.subplot(R, C, (2*C) + C) myimshow(sumimg, **ima) ax = plt.axis() plt.plot([x for x, y in XY], [y for x, y in XY], 'r.') plt.axis(ax) plt.title('Sum of deblends')
plt.savefig(plotpat % 2)
# Compute the sum-of-children image else:
# Sum of children ~= Original image inside footprint (parent_img)
''' A 1-d example, to test the stray-flux assignment. '''
afwGeom.Point2I(W-1, H-1))
# Run the detection code to get a ~ realistic footprint
# WORKAROUND: the detection alg produces ONE peak, at (1,0), # rather than two. # print 'Added peak; peaks:', len(fp.getPeaks()) # for pk in fp.getPeaks(): # print ' ', pk.getFx(), pk.getFy()
# Change verbose to False to quiet down the meas_deblender.baseline logger fitPsfs=False, )
XX = np.arange(W+1).repeat(2)[1:-1]
plt.clf() p1 = plt.plot(XX, img[y, :].repeat(2), 'g-', lw=3, alpha=0.3)
for i, dpk in enumerate(deb.peaks): print(dpk) port = dpk.fluxPortion.getImage() bb = port.getBBox() YY = np.zeros(XX.shape) YY[bb.getMinX()*2: (bb.getMaxX()+1)*2] = port.getArray()[0, :].repeat(2) p2 = plt.plot(XX, YY, 'r-')
simg = afwImage.ImageF(fpbb) dpk.strayFlux.insert(simg) p3 = plt.plot(XX, simg.getArray()[y, :].repeat(2), 'b-')
plt.legend((p1[0], p2[0], p3[0]), ('Parent Flux', 'Child portion', 'Child stray flux')) plt.ylim(-2, 22) plt.savefig(plotpat % 3)
p4 = plt.plot(XX, s1.repeat(2), 'm-') plt.plot(XX, s2.repeat(2), 'm-')
plt.legend((p1[0], p2[0], p3[0], p4[0]), ('Parent Flux', 'Child portion', 'Child stray flux', 'Expected stray flux')) plt.ylim(-2, 22) plt.savefig(plotpat % 4)
# test abs diff
# test relative diff
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
lsst.utils.tests.init() unittest.main() |