Coverage for tests/test_coaddPsf.py: 8%

331 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-11 03:52 -0700

1# 

2# LSST Data Management System 

3# 

4# Copyright 2008-2017 AURA/LSST. 

5# 

6# This product includes software developed by the 

7# LSST Project (http://www.lsst.org/). 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the LSST License Statement and 

20# the GNU General Public License along with this program. If not, 

21# see <https://www.lsstcorp.org/LegalNotices/>. 

22# 

23import unittest 

24 

25import lsst.geom 

26import lsst.afw.geom as afwGeom 

27import lsst.afw.math as afwMath 

28import lsst.afw.table as afwTable 

29import lsst.meas.algorithms as measAlg 

30import lsst.pex.exceptions as pexExceptions 

31import lsst.utils.tests 

32from lsst.afw.detection import InvalidPsfError 

33 

34 

35def getPsfMoments(psf, point): 

36 image = psf.computeImage(point) 

37 array = image.getArray() 

38 sumx2 = 0.0 

39 sumy2 = 0.0 

40 sumy = 0.0 

41 sumx = 0.0 

42 sum = 0.0 

43 for x in range(image.getWidth()): 

44 for y in range(image.getHeight()): 

45 f = array[y][x] 

46 sumx2 += x*x*f 

47 sumy2 += y*y*f 

48 sumx += x*f 

49 sumy += y*f 

50 sum += f 

51 xbar = sumx/sum 

52 ybar = sumy/sum 

53 mxx = sumx2 - 2*xbar*sumx + xbar*xbar*sum 

54 myy = sumy2 - 2*ybar*sumy + ybar*ybar*sum 

55 return sum, xbar, ybar, mxx, myy, image.getX0(), image.getY0() 

56 

57 

58def getPsfSecondMoments(psf, point): 

59 sum, xbar, ybar, mxx, myy, x0, y0 = getPsfMoments(psf, point) 

60 return mxx, myy 

61 

62 

63def makeBiaxialGaussianPsf(sizex, sizey, sigma1, sigma2, theta): 

64 kernel = afwMath.AnalyticKernel(sizex, sizey, afwMath.GaussianFunction2D(sigma1, sigma2, theta)) 

65 return measAlg.KernelPsf(kernel) 

66 

67# This is a mock method for coadding the moments of the component Psfs at a point 

68# Check that the coaddpsf passed in is really using the correct components and weighting them properly 

69# The components in this case are all single gaussians, and we will just add the moments 

70# If useValidPolygon = True then the exposures are expected to have validPolygons defined, otherwise 

71# it will set the whoe region as valid 

72 

73 

74def getCoaddSecondMoments(coaddpsf, point, useValidPolygon=False): 

75 count = coaddpsf.getComponentCount() 

76 coaddWcs = coaddpsf.getCoaddWcs() 

77 weight_sum = 0.0 

78 m1_sum = 0.0 

79 m2_sum = 0.0 

80 for i in range(count): 

81 wcs = coaddpsf.getWcs(i) 

82 psf = coaddpsf.getPsf(i) 

83 bbox = lsst.geom.Box2D(coaddpsf.getBBox(i)) 

84 if useValidPolygon: 

85 validPolygon = coaddpsf.getValidPolygon(i) 

86 else: 

87 validPolygon = afwGeom.Polygon(bbox) 

88 

89 point_rel = wcs.skyToPixel(coaddWcs.pixelToSky(lsst.geom.Point2D(point))) 

90 if bbox.contains(point_rel) and validPolygon.contains(point_rel): 

91 weight = coaddpsf.getWeight(i) 

92 m0, xbar, ybar, mxx, myy, x0, y0 = getPsfMoments(psf, point) # , extent) 

93 m1_sum += mxx*weight 

94 m2_sum += myy*weight 

95 weight_sum += weight 

96 if weight_sum == 0.0: 

97 return 0, 0 

98 else: 

99 return m1_sum/weight_sum, m2_sum/weight_sum 

100 

101 

102class CoaddPsfTest(lsst.utils.tests.TestCase): 

103 

104 def setUp(self): 

105 scale = 5.55555555e-05*lsst.geom.degrees 

106 self.cdMatrix = afwGeom.makeCdMatrix(scale=scale, flipX=True) 

107 self.crpix = lsst.geom.PointD(1000, 1000) 

108 self.crval = lsst.geom.SpherePoint(0.0, 0.0, lsst.geom.degrees) 

109 self.wcsref = afwGeom.makeSkyWcs(crpix=self.crpix, crval=self.crval, cdMatrix=self.cdMatrix) 

110 

111 schema = afwTable.ExposureTable.makeMinimalSchema() 

112 self.weightKey = schema.addField("weight", type="D", doc="Coadd weight") 

113 self.mycatalog = afwTable.ExposureCatalog(schema) 

114 

115 def tearDown(self): 

116 del self.crpix 

117 del self.crval 

118 del self.wcsref 

119 del self.weightKey 

120 del self.mycatalog 

121 

122 # This is a test which checks to see that all of the ExposureCatalog rows are correctly 

123 # ingested by the CoaddPsf constructor, and that they can be read back in the right order 

124 # and with the right values 

125 # The weightname mechanism is also tested. Whatever input column name is used should be 

126 # mapped to "weight" 

127 

128 def testCreate(self): 

129 """Check that we can create a CoaddPsf with 9 elements.""" 

130 

131 # also test that the weight field name is correctly observed 

132 schema = afwTable.ExposureTable.makeMinimalSchema() 

133 schema.addField("customweightname", type="D", doc="Coadd weight") 

134 mycatalog = afwTable.ExposureCatalog(schema) 

135 

136 # Each of the 9 has its peculiar Psf, Wcs, weight, and bounding box. 

137 for i in range(1, 10, 1): 

138 record = mycatalog.getTable().makeRecord() 

139 psf = measAlg.DoubleGaussianPsf(100, 100, i, 1.00, 0.0) 

140 record.setPsf(psf) 

141 crpix = lsst.geom.PointD(i*1000.0, i*1000.0) 

142 wcs = afwGeom.makeSkyWcs(crpix=crpix, crval=self.crval, cdMatrix=self.cdMatrix) 

143 

144 record.setWcs(wcs) 

145 record['customweightname'] = 1.0 * (i+1) 

146 record['id'] = i 

147 bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(i*1000, i*1000)) 

148 record.setBBox(bbox) 

149 mycatalog.append(record) 

150 

151 # create the coaddpsf 

152 mypsf = measAlg.CoaddPsf(mycatalog, self.wcsref, 'customweightname') 

153 

154 # check to be sure that we got the right number of components, in the right order 

155 self.assertEqual(mypsf.getComponentCount(), 9) 

156 for i in range(1, 10, 1): 

157 wcs = mypsf.getWcs(i-1) 

158 psf = mypsf.getPsf(i-1) 

159 bbox = mypsf.getBBox(i-1) 

160 weight = mypsf.getWeight(i-1) 

161 id = mypsf.getId(i-1) 

162 self.assertEqual(i, id) 

163 self.assertEqual(weight, 1.0*(i+1)) 

164 self.assertEqual(bbox.getBeginX(), 0) 

165 self.assertEqual(bbox.getBeginY(), 0) 

166 self.assertEqual(bbox.getEndX(), 1000 * i) 

167 self.assertEqual(bbox.getEndY(), 1000 * i) 

168 self.assertAlmostEqual(wcs.getPixelOrigin().getX(), (1000.0 * i)) 

169 self.assertAlmostEqual(wcs.getPixelOrigin().getY(), (1000.0 * i)) 

170 m0, xbar, ybar, mxx, myy, x0, y0 = getPsfMoments(psf, lsst.geom.Point2D(0, 0)) 

171 self.assertAlmostEqual(i*i, mxx, delta=0.01) 

172 self.assertAlmostEqual(i*i, myy, delta=0.01) 

173 

174 def testFractionalPixel(self): 

175 """Check that we can create a CoaddPsf with 10 elements.""" 

176 cdMatrix = afwGeom.makeCdMatrix( 

177 scale=5.55555555e-05*lsst.geom.degrees, 

178 orientation=90*lsst.geom.degrees, 

179 ) 

180 wcs = afwGeom.makeSkyWcs(crpix=self.crpix, crval=self.crval, cdMatrix=cdMatrix) 

181 

182 # make a single record with an oblong Psf 

183 record = self.mycatalog.getTable().makeRecord() 

184 psf = makeBiaxialGaussianPsf(100, 100, 6.0, 6.0, 0.0) 

185 record.setPsf(psf) 

186 record.setWcs(wcs) 

187 record['weight'] = 1.0 

188 record['id'] = 1 

189 bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(2000, 2000)) 

190 record.setBBox(bbox) 

191 self.mycatalog.append(record) 

192 mypsf = measAlg.CoaddPsf(self.mycatalog, self.wcsref) 

193 psf.computeImage(lsst.geom.PointD(0.25, 0.75)) 

194 psf.computeImage(lsst.geom.PointD(0.25, 0.75)) 

195 psf.computeImage(lsst.geom.PointD(1000, 1000)) 

196 m0, xbar, ybar, mxx, myy, x0, y0 = getPsfMoments(psf, lsst.geom.Point2D(0.25, 0.75)) 

197 cm0, cxbar, cybar, cmxx, cmyy, cx0, cy0 = getPsfMoments(mypsf, lsst.geom.Point2D(0.25, 0.75)) 

198 self.assertAlmostEqual(x0+xbar, cx0+cxbar, delta=0.01) 

199 self.assertAlmostEqual(y0+ybar, cy0+cybar, delta=0.01) 

200 

201 def testRotatePsf(self): 

202 """Check that we can create a CoaddPsf with 10 elements.""" 

203 cdMatrix = afwGeom.makeCdMatrix( 

204 scale=5.55555555e-05*lsst.geom.degrees, 

205 orientation=90*lsst.geom.degrees, 

206 flipX=True, 

207 ) 

208 wcs = afwGeom.makeSkyWcs(crpix=self.crpix, crval=self.crval, cdMatrix=cdMatrix) 

209 

210 # make a single record with an oblong Psf 

211 record = self.mycatalog.getTable().makeRecord() 

212 psf = makeBiaxialGaussianPsf(100, 100, 1.0, 6.0, 0.0) 

213 record.setPsf(psf) 

214 record.setWcs(wcs) 

215 record['weight'] = 1.0 

216 record['id'] = 1 

217 bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(2000, 2000)) 

218 record.setBBox(bbox) 

219 self.mycatalog.append(record) 

220 mypsf = measAlg.CoaddPsf(self.mycatalog, self.wcsref) 

221 m0, xbar, ybar, mxx, myy, x0, y0 = getPsfMoments(psf, lsst.geom.Point2D(0.25, 0.75)) 

222 cm0, cxbar, cybar, cmxx, cmyy, cx0, cy0 = getPsfMoments(mypsf, lsst.geom.Point2D(0.25, 0.75)) 

223 self.assertAlmostEqual(mxx, cmyy, delta=0.01) 

224 self.assertAlmostEqual(myy, cmxx, delta=0.01) 

225 

226 def testDefaultSize(self): 

227 """Test of both default size and specified size.""" 

228 sigma0 = 5 

229 # set the peak of the outer guassian to 0 so this is really a single gaussian. 

230 

231 psf = measAlg.DoubleGaussianPsf(60, 60, 1.5*sigma0, 1, 0.0) 

232 

233 # Now make the catalog 

234 record = self.mycatalog.getTable().makeRecord() 

235 psf = measAlg.DoubleGaussianPsf(100, 100, 10.0, 1.00, 1.0) 

236 record.setPsf(psf) 

237 wcs = afwGeom.makeSkyWcs(crpix=self.crpix, crval=self.crval, cdMatrix=self.cdMatrix) 

238 record.setWcs(wcs) 

239 record['weight'] = 1.0 

240 record['id'] = 1 

241 bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(2000, 2000)) 

242 record.setBBox(bbox) 

243 self.mycatalog.append(record) 

244 

245 mypsf = measAlg.CoaddPsf(self.mycatalog, self.wcsref) # , 'weight') 

246 

247 m1coadd, m2coadd = getCoaddSecondMoments(mypsf, lsst.geom.Point2D(0, 0)) 

248 m1, m2 = getPsfSecondMoments(mypsf, lsst.geom.Point2D(1000, 1000)) 

249 self.assertAlmostEqual(m1, m1coadd, delta=.01) 

250 self.assertAlmostEqual(m2, m2coadd, delta=.01) 

251 

252 def testSimpleGaussian(self): 

253 """Check that we can measure a single Gaussian's attributes.""" 

254 sigma0 = 5 

255 # set the peak of the outer guassian to 0 so this is really a single gaussian. 

256 

257 psf = measAlg.DoubleGaussianPsf(60, 60, 1.5*sigma0, 1, 0.0) 

258 

259 sigma = [5, 6, 7, 8] # 5 pixels is the same as a sigma of 1 arcsec. 

260 

261 # lay down a simple pattern of four ccds, set in a pattern of 1000 pixels around the center 

262 offsets = [(1999, 1999), (1999, 0), (0, 0), (0, 1999)] 

263 

264# Imagine a ccd in each of positions +-1000 pixels from the center 

265 for i in range(4): 

266 record = self.mycatalog.getTable().makeRecord() 

267 psf = measAlg.DoubleGaussianPsf(100, 100, sigma[i], 1.00, 1.0) 

268 record.setPsf(psf) 

269 crpix = lsst.geom.PointD(offsets[i][0], offsets[i][1]) 

270 wcs = afwGeom.makeSkyWcs(crpix=crpix, crval=self.crval, cdMatrix=self.cdMatrix) 

271 record.setWcs(wcs) 

272 record['weight'] = 1.0 

273 record['id'] = i 

274 bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(2000, 2000)) 

275 record.setBBox(bbox) 

276 self.mycatalog.append(record) 

277 

278 mypsf = measAlg.CoaddPsf(self.mycatalog, self.wcsref) # , 'weight') 

279 m1coadd, m2coadd = getCoaddSecondMoments(mypsf, lsst.geom.Point2D(1000, 1000)) 

280 

281 m1, m2 = getPsfSecondMoments(mypsf, lsst.geom.Point2D(1000, 1000)) 

282 self.assertAlmostEqual(m1, m1coadd, delta=.01) 

283 

284 m1, m2 = getPsfSecondMoments(mypsf, lsst.geom.Point2D(1000, 1001)) 

285 m1coadd, m2coadd = getCoaddSecondMoments(mypsf, lsst.geom.Point2D(1000, 1001)) 

286 self.assertAlmostEqual(m1, m1coadd, delta=0.01) 

287 

288# This test checks to be sure that the weights are being applied correctly in doComputeImage 

289# Since the 2nd moments are linear in the function value, we can simply weight the moments 

290# and be sure that the resulting moments are correct 

291 

292 def testWeight(self): 

293 """Check that we can measure a single Gaussian's attributes.""" 

294 sigma0 = 5 

295 # set the peak of the outer guassian to 0 so this is really a single gaussian. 

296 

297 psf = measAlg.DoubleGaussianPsf(60, 60, 1.5*sigma0, 1, 0.0) 

298 

299 sigma = [5, 6, 7, 8] # 5 pixels is the same as a sigma of 1 arcsec. 

300 

301 # lay down a simple pattern of four ccds, set in a pattern of 1000 pixels around the center 

302 offsets = [(1999, 1999), (1999, 0), (0, 0), (0, 1999)] 

303 

304# Imagine a ccd in each of positions +-1000 pixels from the center 

305 for i in range(4): 

306 record = self.mycatalog.getTable().makeRecord() 

307 psf = measAlg.DoubleGaussianPsf(100, 100, sigma[i], 1.00, 0.0) 

308 record.setPsf(psf) 

309 crpix = lsst.geom.PointD(offsets[i][0], offsets[i][1]) 

310 wcs = afwGeom.makeSkyWcs(crpix=crpix, crval=self.crval, cdMatrix=self.cdMatrix) 

311 

312 # print out the coorinates of this supposed 2000x2000 ccd in wcsref coordinates 

313 record.setWcs(wcs) 

314 record['weight'] = 1.0 * (i+1) 

315 record['id'] = i 

316 bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(2000, 2000)) 

317 record.setBBox(bbox) 

318 self.mycatalog.append(record) 

319 

320 mypsf = measAlg.CoaddPsf(self.mycatalog, self.wcsref) # , 'weight') 

321 

322 m1, m2 = getPsfSecondMoments(mypsf, lsst.geom.Point2D(1000, 1000)) 

323 m1coadd, m2coadd = getCoaddSecondMoments(mypsf, lsst.geom.Point2D(1000, 1000)) 

324 self.assertAlmostEqual(m1, m1coadd, delta=0.01) 

325 

326 m1, m2 = getPsfSecondMoments(mypsf, lsst.geom.Point2D(1000, 1001)) 

327 m1coadd, m2coadd = getCoaddSecondMoments(mypsf, lsst.geom.Point2D(1000, 1001)) 

328 self.assertAlmostEqual(m1, m1coadd, delta=0.01) 

329 

330 m1, m2 = getCoaddSecondMoments(mypsf, lsst.geom.Point2D(1001, 1000)) 

331 m1coadd, m2coadd = getCoaddSecondMoments(mypsf, lsst.geom.Point2D(1001, 1000)) 

332 self.assertAlmostEqual(m1, m1coadd, delta=0.01) 

333 

334 def testTicket2872(self): 

335 """Test that CoaddPsf.getAveragePosition() is always a position at which 

336 we can call computeImage(). 

337 """ 

338 scale = 0.2*lsst.geom.arcseconds 

339 cdMatrix = afwGeom.makeCdMatrix(scale=scale) 

340 wcs = afwGeom.makeSkyWcs( 

341 crpix=lsst.geom.Point2D(50, 50), 

342 crval=lsst.geom.SpherePoint(45.0, 45.0, lsst.geom.degrees), 

343 cdMatrix=cdMatrix, 

344 ) 

345 kernel = measAlg.DoubleGaussianPsf(7, 7, 2.0).getKernel() 

346 psf1 = measAlg.KernelPsf(kernel, lsst.geom.Point2D(0, 50)) 

347 psf2 = measAlg.KernelPsf(kernel, lsst.geom.Point2D(100, 50)) 

348 record1 = self.mycatalog.addNew() 

349 record1.setPsf(psf1) 

350 record1.setWcs(wcs) 

351 record1.setD(self.weightKey, 1.0) 

352 record1.setBBox(lsst.geom.Box2I(lsst.geom.Point2I(-40, 0), lsst.geom.Point2I(40, 100))) 

353 record2 = self.mycatalog.addNew() 

354 record2.setPsf(psf2) 

355 record2.setWcs(wcs) 

356 record2.setD(self.weightKey, 1.0) 

357 record2.setBBox(lsst.geom.Box2I(lsst.geom.Point2I(60, 0), lsst.geom.Point2I(140, 100))) 

358 coaddPsf = measAlg.CoaddPsf(self.mycatalog, wcs) 

359 naiveAvgPos = lsst.geom.Point2D(50, 50) 

360 with self.assertRaises(pexExceptions.InvalidParameterError): 

361 coaddPsf.computeKernelImage(naiveAvgPos) 

362 with self.assertRaises(InvalidPsfError): 

363 coaddPsf.computeKernelImage(naiveAvgPos) 

364 with self.assertRaises(pexExceptions.InvalidParameterError): 

365 coaddPsf.computeBBox(naiveAvgPos) 

366 with self.assertRaises(InvalidPsfError): 

367 coaddPsf.computeBBox(naiveAvgPos) 

368 

369 # important test is that this doesn't throw: 

370 coaddPsf.computeKernelImage(coaddPsf.getAveragePosition()) 

371 

372 def testValidPolygonPsf(self): 

373 """Demonstrate that we can use the validPolygon on Exposures in the CoaddPsf.""" 

374 # Create 9 separate records, each with its own peculiar Psf, Wcs, 

375 # weight, bounding box, and valid region. 

376 for i in range(1, 10): 

377 record = self.mycatalog.getTable().makeRecord() 

378 record.setPsf(measAlg.DoubleGaussianPsf(100, 100, i, 1.00, 0.0)) 

379 crpix = lsst.geom.PointD(1000-10.0*i, 1000.0-10.0*i) 

380 wcs = afwGeom.makeSkyWcs(crpix=crpix, crval=self.crval, cdMatrix=self.cdMatrix) 

381 record.setWcs(wcs) 

382 record['weight'] = 1.0*(i + 1) 

383 record['id'] = i 

384 record.setBBox(lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(1000, 1000))) 

385 validPolygon = afwGeom.Polygon(lsst.geom.Box2D(lsst.geom.Point2D(0, 0), 

386 lsst.geom.Extent2D(i*100, i*100))) 

387 record.setValidPolygon(validPolygon) 

388 self.mycatalog.append(record) 

389 

390 # Create the CoaddPsf and check at three different points to ensure that the validPolygon is working 

391 mypsf = measAlg.CoaddPsf(self.mycatalog, self.wcsref, 'weight') 

392 

393 for position in [lsst.geom.Point2D(50, 50), lsst.geom.Point2D(500, 500), lsst.geom.Point2D(850, 850)]: 

394 m1coadd, m2coadd = getCoaddSecondMoments(mypsf, position, True) 

395 m1, m2 = getPsfSecondMoments(mypsf, position) 

396 self.assertAlmostEqual(m1, m1coadd, delta=0.01) 

397 self.assertAlmostEqual(m2, m2coadd, delta=0.01) 

398 

399 def testGoodPix(self): 

400 """Demonstrate that we can goodPix information in the CoaddPsf.""" 

401 bboxSize = lsst.geom.Extent2I(2000, 2000) 

402 schema = afwTable.ExposureTable.makeMinimalSchema() 

403 schema.addField("weight", type="D", doc="Coadd weight") 

404 schema.addField("goodpix", type="I", doc="Number of good pixels") 

405 mycatalog = afwTable.ExposureCatalog(schema) 

406 

407 # Create several records, each with its own peculiar center and numGoodPixels. 

408 # Each PSF has the same shape and size, and the position offsets are small 

409 # relative to the FWHM, in order to make it easy to predict the resulting 

410 # weighted mean position. 

411 xwsum = 0 

412 ywsum = 0 

413 wsum = 0 

414 for i, (xOff, yOff, numGoodPix) in enumerate(( 

415 (30.0, -20.0, 25), 

416 (32.0, -21.0, 10), 

417 (28.0, -19.0, 30), 

418 )): 

419 xwsum -= xOff * numGoodPix 

420 ywsum -= yOff * numGoodPix 

421 wsum += numGoodPix 

422 record = mycatalog.getTable().makeRecord() 

423 record.setPsf(measAlg.DoubleGaussianPsf(25, 25, 10, 1.00, 0.0)) 

424 offPix = self.crpix + lsst.geom.Extent2D(xOff, yOff) 

425 wcs = afwGeom.makeSkyWcs(crpix=offPix, crval=self.crval, cdMatrix=self.cdMatrix) 

426 record.setWcs(wcs) 

427 record['weight'] = 1.0 

428 record['id'] = i 

429 record['goodpix'] = numGoodPix 

430 record.setBBox(lsst.geom.Box2I(lsst.geom.Point2I(0, 0), bboxSize)) 

431 mycatalog.append(record) 

432 

433 mypsf = measAlg.CoaddPsf(mycatalog, self.wcsref, 'weight') 

434 predPos = lsst.geom.Point2D(xwsum/wsum, ywsum/wsum) 

435 self.assertPairsAlmostEqual(predPos, mypsf.getAveragePosition()) 

436 

437 def testBBox(self): 

438 """Check that computeBBox returns same BBox as realized Kernel Image 

439 

440 and resized raises a Not Implemented Error""" 

441 sigma0 = 5 

442 size = [50, 60, 70, 80] 

443 

444 for i in range(4): 

445 record = self.mycatalog.getTable().makeRecord() 

446 psf = measAlg.DoubleGaussianPsf(size[i], size[i], sigma0, 1.00, 0.0) 

447 record.setPsf(psf) 

448 wcs = afwGeom.makeSkyWcs(crpix=self.crpix, crval=self.crval, cdMatrix=self.cdMatrix) 

449 record.setWcs(wcs) 

450 record['weight'] = 1.0 * (i + 1) 

451 record['id'] = i 

452 bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(2000, 2000)) 

453 record.setBBox(bbox) 

454 self.mycatalog.append(record) 

455 

456 mypsf = measAlg.CoaddPsf(self.mycatalog, self.wcsref, 'weight') 

457 

458 self.assertEqual( 

459 mypsf.computeKernelImage(mypsf.getAveragePosition()).getBBox(), 

460 mypsf.computeBBox(mypsf.getAveragePosition()) 

461 ) 

462 

463 with self.assertRaises(pexExceptions.LogicError): 

464 mypsf.resized(100, 100) 

465 

466 def testLargeTransform(self): 

467 """Test that images with bad astrometry are identified""" 

468 multiplier = 1000.0 # CD matrix multiplier for bad input 

469 badId = 1 # ID of bad input 

470 for ii in range(3): 

471 record = self.mycatalog.addNew() 

472 record.setPsf(measAlg.DoubleGaussianPsf(50, 50, 5.0, 1.00, 0.0)) 

473 cdMatrix = self.cdMatrix 

474 if ii == badId: 

475 # This image has bad astrometry: 

476 cdMatrix *= multiplier 

477 record['id'] = ii 

478 record['weight'] = 1.0 

479 record.setWcs(afwGeom.makeSkyWcs(crpix=self.crpix, crval=self.crval, cdMatrix=cdMatrix)) 

480 record.setBBox(lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Extent2I(2000, 2000))) 

481 

482 coaddPsf = measAlg.CoaddPsf(self.mycatalog, self.wcsref) 

483 with self.assertRaises(pexExceptions.RangeError) as cm: 

484 coaddPsf.computeKernelImage(coaddPsf.getAveragePosition()) 

485 self.assertIn("id=%d" % (badId,), str(cm.exception)) 

486 

487 

488class TestMemory(lsst.utils.tests.MemoryTestCase): 

489 pass 

490 

491 

492def setup_module(module): 

493 lsst.utils.tests.init() 

494 

495 

496if __name__ == "__main__": 496 ↛ 497line 496 didn't jump to line 497, because the condition on line 496 was never true

497 lsst.utils.tests.init() 

498 unittest.main()