Hide keyboard shortcuts

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

# 

# LSST Data Management System 

# 

# Copyright 2008-2017 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 unittest 

 

import lsst.geom 

import lsst.afw.geom as afwGeom 

import lsst.afw.math as afwMath 

import lsst.afw.table as afwTable 

import lsst.meas.algorithms as measAlg 

import lsst.pex.exceptions as pexExceptions 

import lsst.utils.tests 

 

 

def getPsfMoments(psf, point): 

# import os, pdb; print "PID =", os.getpid(); pdb.set_trace() 

image = psf.computeImage(point) 

array = image.getArray() 

sumx2 = 0.0 

sumy2 = 0.0 

sumy = 0.0 

sumx = 0.0 

sum = 0.0 

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

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

f = array[y][x] 

sumx2 += x*x*f 

sumy2 += y*y*f 

sumx += x*f 

sumy += y*f 

sum += f 

xbar = sumx/sum 

ybar = sumy/sum 

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

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

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

 

 

def getPsfSecondMoments(psf, point): 

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

return mxx, myy 

 

 

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

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

return measAlg.KernelPsf(kernel) 

 

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

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

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

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

# it will set the whoe region as valid 

 

 

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

count = coaddpsf.getComponentCount() 

coaddWcs = coaddpsf.getCoaddWcs() 

weight_sum = 0.0 

m1_sum = 0.0 

m2_sum = 0.0 

for i in range(count): 

wcs = coaddpsf.getWcs(i) 

psf = coaddpsf.getPsf(i) 

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

if useValidPolygon: 

validPolygon = coaddpsf.getValidPolygon(i) 

else: 

validPolygon = afwGeom.Polygon(bbox) 

 

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

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

weight = coaddpsf.getWeight(i) 

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

m1_sum += mxx*weight 

m2_sum += myy*weight 

weight_sum += weight 

96 ↛ 97line 96 didn't jump to line 97, because the condition on line 96 was never true if weight_sum == 0.0: 

return 0, 0 

else: 

return m1_sum/weight_sum, m2_sum/weight_sum 

 

 

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

 

def setUp(self): 

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

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

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

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

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

 

schema = afwTable.ExposureTable.makeMinimalSchema() 

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

self.mycatalog = afwTable.ExposureCatalog(schema) 

 

def tearDown(self): 

del self.crpix 

del self.crval 

del self.wcsref 

del self.weightKey 

del self.mycatalog 

 

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

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

# and with the right values 

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

# mapped to "weight" 

 

def testCreate(self): 

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

print("CreatePsfTest") 

 

# also test that the weight field name is correctly observed 

schema = afwTable.ExposureTable.makeMinimalSchema() 

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

mycatalog = afwTable.ExposureCatalog(schema) 

 

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

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

record = mycatalog.getTable().makeRecord() 

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

record.setPsf(psf) 

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

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

 

record.setWcs(wcs) 

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

record['id'] = i 

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

record.setBBox(bbox) 

mycatalog.append(record) 

 

# create the coaddpsf 

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

 

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

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

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

wcs = mypsf.getWcs(i-1) 

psf = mypsf.getPsf(i-1) 

bbox = mypsf.getBBox(i-1) 

weight = mypsf.getWeight(i-1) 

id = mypsf.getId(i-1) 

self.assertEqual(i, id) 

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

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

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

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

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

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

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

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

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

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

 

def testFractionalPixel(self): 

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

print("FractionalPixelTest") 

cdMatrix = afwGeom.makeCdMatrix( 

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

orientation=90*lsst.geom.degrees, 

) 

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

 

# make a single record with an oblong Psf 

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

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

record.setPsf(psf) 

record.setWcs(wcs) 

record['weight'] = 1.0 

record['id'] = 1 

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

record.setBBox(bbox) 

self.mycatalog.append(record) 

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

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

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

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

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

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

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

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

 

def testRotatePsf(self): 

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

print("RotatePsfTest") 

cdMatrix = afwGeom.makeCdMatrix( 

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

orientation=90*lsst.geom.degrees, 

flipX=True, 

) 

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

 

# make a single record with an oblong Psf 

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

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

record.setPsf(psf) 

record.setWcs(wcs) 

record['weight'] = 1.0 

record['id'] = 1 

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

record.setBBox(bbox) 

self.mycatalog.append(record) 

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

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

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

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

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

 

def testDefaultSize(self): 

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

print("DefaultSizeTest") 

sigma0 = 5 

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

 

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

 

# Now make the catalog 

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

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

record.setPsf(psf) 

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

record.setWcs(wcs) 

record['weight'] = 1.0 

record['id'] = 1 

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

record.setBBox(bbox) 

self.mycatalog.append(record) 

 

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

 

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

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

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

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

 

def testSimpleGaussian(self): 

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

print("SimpleGaussianTest") 

sigma0 = 5 

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

 

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

 

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

 

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

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

 

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

for i in range(4): 

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

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

record.setPsf(psf) 

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

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

record.setWcs(wcs) 

record['weight'] = 1.0 

record['id'] = i 

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

record.setBBox(bbox) 

self.mycatalog.append(record) 

 

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

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

 

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

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

 

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

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

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

 

 

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

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

# and be sure that the resulting moments are correct 

 

def testWeight(self): 

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

print("WeightTest") 

sigma0 = 5 

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

 

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

 

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

 

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

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

 

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

for i in range(4): 

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

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

record.setPsf(psf) 

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

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

 

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

record.setWcs(wcs) 

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

record['id'] = i 

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

record.setBBox(bbox) 

self.mycatalog.append(record) 

 

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

 

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

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

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

 

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

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

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

 

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

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

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

 

def testTicket2872(self): 

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

we can call computeImage(). 

""" 

scale = 0.2*lsst.geom.arcseconds 

cdMatrix = afwGeom.makeCdMatrix(scale=scale) 

wcs = afwGeom.makeSkyWcs( 

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

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

cdMatrix=cdMatrix, 

) 

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

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

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

record1 = self.mycatalog.addNew() 

record1.setPsf(psf1) 

record1.setWcs(wcs) 

record1.setD(self.weightKey, 1.0) 

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

record2 = self.mycatalog.addNew() 

record2.setPsf(psf2) 

record2.setWcs(wcs) 

record2.setD(self.weightKey, 1.0) 

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

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

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

with self.assertRaises(pexExceptions.InvalidParameterError): 

coaddPsf.computeKernelImage(naiveAvgPos) 

# important test is that this doesn't throw: 

coaddPsf.computeKernelImage() 

 

def testValidPolygonPsf(self): 

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

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

# weight, bounding box, and valid region. 

for i in range(1, 10): 

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

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

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

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

record.setWcs(wcs) 

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

record['id'] = i 

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

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

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

record.setValidPolygon(validPolygon) 

self.mycatalog.append(record) 

 

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

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

 

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

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

m1, m2 = getPsfSecondMoments(mypsf, position) 

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

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

 

def testGoodPix(self): 

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

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

schema = afwTable.ExposureTable.makeMinimalSchema() 

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

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

mycatalog = afwTable.ExposureCatalog(schema) 

 

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

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

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

# weighted mean position. 

xwsum = 0 

ywsum = 0 

wsum = 0 

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

(30.0, -20.0, 25), 

(32.0, -21.0, 10), 

(28.0, -19.0, 30), 

)): 

xwsum -= xOff * numGoodPix 

ywsum -= yOff * numGoodPix 

wsum += numGoodPix 

record = mycatalog.getTable().makeRecord() 

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

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

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

record.setWcs(wcs) 

record['weight'] = 1.0 

record['id'] = i 

record['goodpix'] = numGoodPix 

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

mycatalog.append(record) 

 

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

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

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

 

def testBBox(self): 

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

 

and resized raises a Not Implemented Error""" 

sigma0 = 5 

size = [50, 60, 70, 80] 

 

for i in range(4): 

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

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

record.setPsf(psf) 

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

record.setWcs(wcs) 

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

record['id'] = i 

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

record.setBBox(bbox) 

self.mycatalog.append(record) 

 

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

 

self.assertEqual(mypsf.computeKernelImage().getBBox(), mypsf.computeBBox()) 

 

with self.assertRaises(pexExceptions.LogicError): 

mypsf.resized(100, 100) 

 

def testLargeTransform(self): 

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

multiplier = 1000.0 # CD matrix multiplier for bad input 

badId = 1 # ID of bad input 

for ii in range(3): 

record = self.mycatalog.addNew() 

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

cdMatrix = self.cdMatrix 

if ii == badId: 

# This image has bad astrometry: 

cdMatrix *= multiplier 

record['id'] = ii 

record['weight'] = 1.0 

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

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

 

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

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

coaddPsf.computeKernelImage() 

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

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

493 ↛ 494line 493 didn't jump to line 494, because the condition on line 493 was never trueif __name__ == "__main__": 

lsst.utils.tests.init() 

unittest.main()