Coverage for tests/test_compareToHotpants.py: 7%
300 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-02 11:54 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-02 11:54 +0000
1import unittest
4import lsst.utils.tests
5import lsst.afw.geom as afwGeom
6import lsst.afw.image as afwImage
7import lsst.afw.math as afwMath
8import lsst.afw.detection as afwDet
9import lsst.geom as geom
10import lsst.ip.diffim as ipDiffim
11import lsst.utils.logging as logUtils
12import lsst.pex.config as pexConfig
14logUtils.trace_set_at("lsst.ip.diffim", 4)
17class DiffimTestCases(lsst.utils.tests.TestCase):
19 def setUp(self):
20 self.config = ipDiffim.PsfMatchConfigAL()
22 # Test was put together before the min size went to 21
23 self.config.kernelSize = 19
25 self.config.scaleByFwhm = False
26 self.config.fitForBackground = True
27 self.config.spatialModelType = "polynomial"
28 self.ps = pexConfig.makePropertySet(self.config)
30 self.smi = afwImage.MaskedImageF('tests/compareToHotpants/scienceMI.fits')
31 self.tmi = afwImage.MaskedImageF('tests/compareToHotpants/templateMI.fits')
32 self.smi.setXY0(0, 0)
33 self.tmi.setXY0(0, 0)
35 # Run detection
36 # detConfig = self.config.detectionConfig
37 # Note here regarding detConfig:
38 #
39 # If I set detThresholdType = "pixel_stdev", I get slightly
40 # different centroids than if I use "stdev". These different
41 # centroids screw up the testing since hotpants was hardcoded to
42 # use the "stdev" centroids. For completeness these are:
43 #
44 # 32 32
45 # 96 32
46 # 160 32
47 # 96 95
48 # 31 96
49 # 160 96
50 # 96 160
51 # 160 160
52 # 32 160
54 # As of Winter2013, KernelCandidateDetectionF does not return
55 # these exact centroids anymore, so I need to hardcode them
56 # in.
57 self.footprints = []
58 for xc, yc in [(32, 32), (96, 32), (160, 32),
59 (96, 95), (31, 96), (160, 96),
60 (96, 160), (160, 160), (32, 160)]:
61 self.footprints.append(afwDet.Footprint(afwGeom.SpanSet(
62 geom.Box2I(geom.Point2I(xc, yc),
63 geom.Extent2I(1, 1)))))
65 # Make a basis list that hotpants has been run with
66 nGauss = 1
67 sGauss = [3.]
68 dGauss = [3]
69 self.config.alardNGauss = nGauss
70 self.config.alardSigGauss = sGauss
71 self.config.alardDegGauss = dGauss
72 basisList0 = ipDiffim.makeKernelBasisList(self.config)
74 # HP does things in a different order, and with different normalization, so reorder list
75 order = [0, 2, 5, 9, 1, 4, 8, 3, 7, 6]
76 scaling = [1.000000e+00,
77 8.866037e-02,
78 1.218095e+01,
79 5.099318e-03,
80 8.866037e-02,
81 4.179772e-02,
82 1.138120e-02,
83 1.218095e+01,
84 1.138120e-02,
85 5.099318e-03]
87 self.basisList = []
88 for i in range(len(order)):
89 im = afwImage.ImageD(basisList0[order[i]].getDimensions())
90 basisList0[order[i]].computeImage(im, False)
91 im /= scaling[i]
92 # im.writeFits('k%d.fits' % (i))
93 k = afwMath.FixedKernel(im)
94 self.basisList.append(k)
96 # And a place to put candidates
97 self.kernelCellSet = afwMath.SpatialCellSet(geom.Box2I(geom.Point2I(0, 0),
98 geom.Extent2I(self.smi.getWidth(),
99 self.smi.getHeight())),
100 self.ps["sizeCellX"],
101 self.ps["sizeCellY"])
103 # There are some -1 factors that come from differences in how
104 # convolution is done. Some resulting convovled images end up
105 # being a factor of -1 different, therefore the coefficients
106 # need to be a factor of -1 different as well.
107 self.parity = [1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1]
109 def tearDown(self):
110 del self.ps
111 del self.tmi
112 del self.smi
113 del self.basisList
114 del self.footprints
115 del self.kernelCellSet
117 def testSingleNoVariation(self):
118 self.ps['constantVarianceWeighting'] = True
119 self.ps['spatialKernelOrder'] = 0
120 self.ps['spatialBgOrder'] = 0
122 # Place candidate footprints within the spatial grid
123 for fp in self.footprints:
124 bbox = fp.getBBox()
126 # Grab the centers in the parent's coordinate system
127 xC = int(0.5 * (bbox.getMinX() + bbox.getMaxX()))
128 yC = int(0.5 * (bbox.getMinY() + bbox.getMaxY()))
130 bbox = geom.Box2I(geom.Point2I(int(xC)-24, int(yC)-24), geom.Extent2I(49, 49))
132 tsmi = afwImage.MaskedImageF(self.tmi, bbox, origin=afwImage.LOCAL)
133 ssmi = afwImage.MaskedImageF(self.smi, bbox, origin=afwImage.LOCAL)
135 # Hotpants centroids go from -1 to 1
136 # Only one passes
137 if xC > 150 and yC > 150:
138 cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
139 / (0.5 * self.smi.getWidth()),
140 (yC - 0.5 * self.smi.getHeight())
141 / (0.5 * self.smi.getHeight()),
142 tsmi, ssmi, self.ps)
143 self.kernelCellSet.insertCandidate(cand)
145 # Visitors
146 bbox = self.kernelCellSet.getBBox()
147 bsikv = ipDiffim.BuildSingleKernelVisitorF(self.basisList, self.ps)
148 bspkv = ipDiffim.BuildSpatialKernelVisitorF(self.basisList, bbox, self.ps)
150 for cell in self.kernelCellSet.getCellList():
151 for cand in cell.begin(False): # False = include bad candidates
152 bsikv.processCandidate(cand)
153 bspkv.processCandidate(cand)
155 HPsingleSolution = [0.959086,
156 -0.000344,
157 -0.197758,
158 0.000019,
159 -0.000172,
160 0.000053,
161 0.000018,
162 -0.192776,
163 0.000000,
164 0.000001,
165 0.602642]
167 HPspatialSolution = HPsingleSolution
169 singleSolution = cand.getKernel(ipDiffim.KernelCandidateF.RECENT).getKernelParameters()
170 for i in range(len(singleSolution)):
171 self.assertAlmostEqual(HPsingleSolution[i] * self.parity[i], singleSolution[i], 5)
173 bspkv.solveLinearEquation()
174 sk, sb = bspkv.getSolutionPair()
175 spatialSolution = sk.getKernelParameters()
176 for i in range(len(spatialSolution)):
177 self.assertAlmostEqual(HPspatialSolution[i] * self.parity[i], spatialSolution[i], 6)
179 self.assertAlmostEqual(sb.getParameters()[0], HPspatialSolution[-1], 5)
181 def testFourNoVariation(self):
182 self.ps['constantVarianceWeighting'] = True
183 self.ps['spatialKernelOrder'] = 0
184 self.ps['spatialBgOrder'] = 0
186 # Place candidate footprints within the spatial grid
187 for fp in self.footprints:
188 bbox = fp.getBBox()
190 # Grab the centers in the parent's coordinate system
191 xC = int(0.5 * (bbox.getMinX() + bbox.getMaxX()))
192 yC = int(0.5 * (bbox.getMinY() + bbox.getMaxY()))
194 bbox = geom.Box2I(geom.Point2I(int(xC)-24, int(yC)-24), geom.Extent2I(49, 49))
196 tsmi = afwImage.MaskedImageF(self.tmi, bbox, origin=afwImage.LOCAL)
197 ssmi = afwImage.MaskedImageF(self.smi, bbox, origin=afwImage.LOCAL)
199 # Hotpants centroids go from -1 to 1
200 if xC > 90 and yC > 90:
201 cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
202 / (0.5 * self.smi.getWidth()),
203 (yC - 0.5 * self.smi.getHeight())
204 / (0.5 * self.smi.getHeight()),
205 tsmi, ssmi, self.ps)
207 self.kernelCellSet.insertCandidate(cand)
209 # Visitors
210 bbox = self.kernelCellSet.getBBox()
211 bsikv = ipDiffim.BuildSingleKernelVisitorF(self.basisList, self.ps)
212 bspkv = ipDiffim.BuildSpatialKernelVisitorF(self.basisList, bbox, self.ps)
214 for cell in self.kernelCellSet.getCellList():
215 for cand in cell.begin(False): # False = include bad candidates
216 bsikv.processCandidate(cand)
217 bspkv.processCandidate(cand)
219 HPspatialSolution = [0.969559,
220 -0.000223,
221 -0.198374,
222 0.000012,
223 -0.000010,
224 0.000036,
225 -0.000004,
226 -0.206751,
227 0.000012,
228 0.000004,
229 0.452304]
231 bspkv.solveLinearEquation()
232 sk, sb = bspkv.getSolutionPair()
233 spatialSolution = sk.getKernelParameters()
234 for i in range(len(spatialSolution)):
235 self.assertAlmostEqual(HPspatialSolution[i] * self.parity[i], spatialSolution[i], 5)
237 self.assertAlmostEqual(sb.getParameters()[0], HPspatialSolution[-1], 5)
239 def testFourKernelVariation(self):
240 self.ps['constantVarianceWeighting'] = True
241 self.ps['spatialKernelOrder'] = 1
242 self.ps['spatialBgOrder'] = 0
244 # Place candidate footprints within the spatial grid
245 for fp in self.footprints:
246 bbox = fp.getBBox()
248 # Grab the centers in the parent's coordinate system
249 xC = int(0.5 * (bbox.getMinX() + bbox.getMaxX()))
250 yC = int(0.5 * (bbox.getMinY() + bbox.getMaxY()))
252 bbox = geom.Box2I(geom.Point2I(int(xC)-24, int(yC)-24), geom.Extent2I(49, 49))
254 tsmi = afwImage.MaskedImageF(self.tmi, bbox, origin=afwImage.LOCAL)
255 ssmi = afwImage.MaskedImageF(self.smi, bbox, origin=afwImage.LOCAL)
257 # Hotpants centroids go from -1 to 1
258 if xC > 90 and yC > 90:
259 cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
260 / (0.5 * self.smi.getWidth()),
261 (yC - 0.5 * self.smi.getHeight())
262 / (0.5 * self.smi.getHeight()),
263 tsmi, ssmi, self.ps)
264 self.kernelCellSet.insertCandidate(cand)
266 # Visitors
267 bbox = self.kernelCellSet.getBBox()
268 bsikv = ipDiffim.BuildSingleKernelVisitorF(self.basisList, self.ps)
269 bspkv = ipDiffim.BuildSpatialKernelVisitorF(self.basisList, bbox, self.ps)
271 for cell in self.kernelCellSet.getCellList():
272 for cand in cell.begin(False): # False = include bad candidates
273 bsikv.processCandidate(cand)
274 bspkv.processCandidate(cand)
276 HPspatialSolution = [[0.969559,
277 0.,
278 0.],
279 [-0.000082,
280 -0.000620,
281 0.000185],
282 [-0.197749,
283 0.001418,
284 -0.003321],
285 [0.000002,
286 0.000049,
287 -0.000016],
288 [0.000211,
289 -0.000283,
290 -0.000397],
291 [0.000034,
292 0.000002,
293 0.000006],
294 [-0.000013,
295 0.000041,
296 -0.000010],
297 [-0.220238,
298 0.028395,
299 0.013148],
300 [0.000019,
301 -0.000025,
302 0.000003],
303 [0.000003,
304 0.000000,
305 0.000005],
306 0.452304]
308 bspkv.solveLinearEquation()
309 sk, sb = bspkv.getSolutionPair()
310 spatialSolution = sk.getSpatialParameters()
312 for i in range(len(spatialSolution)):
313 # HP and LSST switch the order x<->y
314 self.assertAlmostEqual(HPspatialSolution[i][0] * self.parity[i], spatialSolution[i][0], 5)
315 self.assertAlmostEqual(HPspatialSolution[i][1] * self.parity[i], spatialSolution[i][2], 5)
316 self.assertAlmostEqual(HPspatialSolution[i][2] * self.parity[i], spatialSolution[i][1], 5)
318 self.assertAlmostEqual(sb.getParameters()[0], HPspatialSolution[-1], 5)
320 def testFourBgVariation(self):
322 # OK, so these can end up a bit different due to how HP and
323 # LSST represent the background in the matrix math. HP has
324 # each pixel have its own coordinate (which goes from -1 to 1
325 # across the entire image, by the way), whereas we give all
326 # the LSST pixels within a stamp the same coordinate.
328 # To make this comparison, I go ahead and edit the Hotpants
329 # code to give each pixel the same weight. For reference this
330 # is in fillStamp() and I replace:
331 #
332 # //xf = (i - rPixX2) / rPixX2;
333 # xf = (xi - rPixX2) / rPixX2;
334 #
335 # //yf = (j - rPixY2) / rPixY2;
336 # yf = (yi - rPixY2) / rPixY2;
338 self.ps['constantVarianceWeighting'] = True
339 self.ps['spatialKernelOrder'] = 0
340 self.ps['spatialBgOrder'] = 1
342 # Place candidate footprints within the spatial grid
343 for fp in self.footprints:
344 bbox = fp.getBBox()
346 # Grab the centers in the parent's coordinate system
347 xC = int(0.5 * (bbox.getMinX() + bbox.getMaxX()))
348 yC = int(0.5 * (bbox.getMinY() + bbox.getMaxY()))
350 bbox = geom.Box2I(geom.Point2I(int(xC)-24, int(yC)-24), geom.Extent2I(49, 49))
352 tsmi = afwImage.MaskedImageF(self.tmi, bbox, origin=afwImage.LOCAL)
353 ssmi = afwImage.MaskedImageF(self.smi, bbox, origin=afwImage.LOCAL)
355 # Hotpants centroids go from -1 to 1
356 if xC > 90 and yC > 90:
357 cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
358 / (0.5 * self.smi.getWidth()),
359 (yC - 0.5 * self.smi.getHeight())
360 / (0.5 * self.smi.getHeight()),
361 tsmi, ssmi, self.ps)
362 # print 'OBJECT', cand.getId(), 'AT', xC, yC, cand.getXCenter(), cand.getYCenter()
363 self.kernelCellSet.insertCandidate(cand)
365 # Visitors
366 bbox = self.kernelCellSet.getBBox()
367 bsikv = ipDiffim.BuildSingleKernelVisitorF(self.basisList, self.ps)
368 bspkv = ipDiffim.BuildSpatialKernelVisitorF(self.basisList, bbox, self.ps)
370 for cell in self.kernelCellSet.getCellList():
371 for cand in cell.begin(False): # False = include bad candidates
372 bsikv.processCandidate(cand)
373 bspkv.processCandidate(cand)
375 HPspatialSolution = [0.969559,
376 -0.000223,
377 -0.198374,
378 0.000012,
379 -0.000010,
380 0.000036,
381 -0.000004,
382 -0.206751,
383 0.000012,
384 0.000004,
385 [0.782113,
386 -0.910963,
387 -0.106636]]
389 bspkv.solveLinearEquation()
390 sk, sb = bspkv.getSolutionPair()
391 spatialSolution = sk.getKernelParameters()
392 for i in range(len(spatialSolution)):
393 self.assertAlmostEqual(HPspatialSolution[i] * self.parity[i], spatialSolution[i], 5)
395 self.assertAlmostEqual(sb.getParameters()[0], HPspatialSolution[-1][0], 5)
396 self.assertAlmostEqual(sb.getParameters()[1], HPspatialSolution[-1][2], 5) # x<->y
397 self.assertAlmostEqual(sb.getParameters()[2], HPspatialSolution[-1][1], 5) # x<->y
399 def testFourVariation(self):
400 self.ps['constantVarianceWeighting'] = True
401 self.ps['spatialKernelOrder'] = 1
402 self.ps['spatialBgOrder'] = 1
404 # Place candidate footprints within the spatial grid
405 for fp in self.footprints:
406 bbox = fp.getBBox()
408 # Grab the centers in the parent's coordinate system
409 xC = int(0.5 * (bbox.getMinX() + bbox.getMaxX()))
410 yC = int(0.5 * (bbox.getMinY() + bbox.getMaxY()))
412 bbox = geom.Box2I(geom.Point2I(int(xC)-24, int(yC)-24), geom.Extent2I(49, 49))
414 tsmi = afwImage.MaskedImageF(self.tmi, bbox, origin=afwImage.LOCAL)
415 ssmi = afwImage.MaskedImageF(self.smi, bbox, origin=afwImage.LOCAL)
417 # Hotpants centroids go from -1 to 1
418 if xC > 90 and yC > 90:
419 cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
420 / (0.5 * self.smi.getWidth()),
421 (yC - 0.5 * self.smi.getHeight())
422 / (0.5 * self.smi.getHeight()),
423 tsmi, ssmi, self.ps)
424 self.kernelCellSet.insertCandidate(cand)
426 # Visitors
427 bbox = self.kernelCellSet.getBBox()
428 bsikv = ipDiffim.BuildSingleKernelVisitorF(self.basisList, self.ps)
429 bspkv = ipDiffim.BuildSpatialKernelVisitorF(self.basisList, bbox, self.ps)
431 for cell in self.kernelCellSet.getCellList():
432 for cand in cell.begin(False): # False = include bad candidates
433 bsikv.processCandidate(cand)
434 bspkv.processCandidate(cand)
436 HPspatialSolution = [[0.969559,
437 0.,
438 0.],
439 [-0.000082,
440 -0.000620,
441 0.000185],
442 [-0.197749,
443 0.001418,
444 -0.003321],
445 [0.000002,
446 0.000049,
447 -0.000016],
448 [0.000211,
449 -0.000283,
450 -0.000397],
451 [0.000034,
452 0.000002,
453 0.000006],
454 [-0.000013,
455 0.000041,
456 -0.000010],
457 [-0.220238,
458 0.028395,
459 0.013148],
460 [0.000019,
461 -0.000025,
462 0.000003],
463 [0.000003,
464 0.000000,
465 0.000005],
466 [0.782113,
467 -0.910963,
468 -0.106636]]
470 bspkv.solveLinearEquation()
471 sk, sb = bspkv.getSolutionPair()
472 spatialSolution = sk.getSpatialParameters()
474 for i in range(len(spatialSolution)):
475 # HP and LSST switch the order x<->y
476 self.assertAlmostEqual(HPspatialSolution[i][0] * self.parity[i], spatialSolution[i][0], 5)
477 self.assertAlmostEqual(HPspatialSolution[i][1] * self.parity[i], spatialSolution[i][2], 5)
478 self.assertAlmostEqual(HPspatialSolution[i][2] * self.parity[i], spatialSolution[i][1], 5)
480 self.assertAlmostEqual(sb.getParameters()[0], HPspatialSolution[-1][0], 5)
481 self.assertAlmostEqual(sb.getParameters()[1], HPspatialSolution[-1][2], 5) # x<->y
482 self.assertAlmostEqual(sb.getParameters()[2], HPspatialSolution[-1][1], 5) # x<->y
484 def testAllBgVariation2(self):
485 # OK, I ran HP on all the things in this image. Enough for
486 # second order spatial variation
488 self.ps['constantVarianceWeighting'] = True
489 self.ps['spatialKernelOrder'] = 0
490 self.ps['spatialBgOrder'] = 2
492 # Ignore the whole kernelCellSet thing
493 cands = []
494 for fp in self.footprints:
495 bbox = fp.getBBox()
497 # Grab the centers in the parent's coordinate system
498 xC = int(0.5 * (bbox.getMinX() + bbox.getMaxX()))
499 yC = int(0.5 * (bbox.getMinY() + bbox.getMaxY()))
501 bbox = geom.Box2I(geom.Point2I(int(xC)-24, int(yC)-24), geom.Extent2I(49, 49))
503 tsmi = afwImage.MaskedImageF(self.tmi, bbox, origin=afwImage.LOCAL)
504 ssmi = afwImage.MaskedImageF(self.smi, bbox, origin=afwImage.LOCAL)
506 # Hotpants centroids go from -1 to 1
507 cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
508 / (0.5 * self.smi.getWidth()),
509 (yC - 0.5 * self.smi.getHeight())
510 / (0.5 * self.smi.getHeight()),
511 tsmi, ssmi, self.ps)
512 cands.append(cand)
514 # Visitors
515 bbox = self.kernelCellSet.getBBox()
516 bsikv = ipDiffim.BuildSingleKernelVisitorF(self.basisList, self.ps)
517 bspkv = ipDiffim.BuildSpatialKernelVisitorF(self.basisList, bbox, self.ps)
519 for cand in cands:
520 bsikv.processCandidate(cand)
521 bspkv.processCandidate(cand)
523 HPspatialSolution = [0.968505,
524 -0.000053,
525 -0.206505,
526 0.000005,
527 0.000062,
528 0.000028,
529 -0.000004,
530 -0.206135,
531 0.000005,
532 0.000001,
533 [0.812488,
534 0.096456,
535 -1.140900,
536 0.132670,
537 -0.571923,
538 -0.284670]]
540 bspkv.solveLinearEquation()
541 sk, sb = bspkv.getSolutionPair()
542 spatialSolution = sk.getKernelParameters()
544 # Kernel
545 for i in range(len(spatialSolution)):
546 self.assertAlmostEqual(HPspatialSolution[i] * self.parity[i], spatialSolution[i], 5)
548 # Bg
549 # Ordering of second order terms is just messy
550 spReorder = [0, 3, 1, 5, 4, 2]
551 spatialSolution = sb.getParameters()
552 for i in range(len(spatialSolution)):
553 self.assertAlmostEqual(HPspatialSolution[-1][spReorder[i]], spatialSolution[i], 5)
555 def testAllKernelVariation2(self):
556 # OK, I ran HP on all the things in this image. Enough for
557 # second order spatial variation
559 self.ps['constantVarianceWeighting'] = True
560 self.ps['spatialKernelOrder'] = 2
561 self.ps['spatialBgOrder'] = 0
563 # Ignore the whole kernelCellSet thing
564 cands = []
565 for fp in self.footprints:
566 bbox = fp.getBBox()
568 # Grab the centers in the parent's coordinate system
569 xC = int(0.5 * (bbox.getMinX() + bbox.getMaxX()))
570 yC = int(0.5 * (bbox.getMinY() + bbox.getMaxY()))
572 bbox = geom.Box2I(geom.Point2I(int(xC)-24, int(yC)-24), geom.Extent2I(49, 49))
574 tsmi = afwImage.MaskedImageF(self.tmi, bbox, origin=afwImage.LOCAL)
575 ssmi = afwImage.MaskedImageF(self.smi, bbox, origin=afwImage.LOCAL)
577 # Hotpants centroids go from -1 to 1
578 cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
579 / (0.5 * self.smi.getWidth()),
580 (yC - 0.5 * self.smi.getHeight())
581 / (0.5 * self.smi.getHeight()),
582 tsmi, ssmi, self.ps)
583 cands.append(cand)
585 # Visitors
586 bbox = self.kernelCellSet.getBBox()
587 bsikv = ipDiffim.BuildSingleKernelVisitorF(self.basisList, self.ps)
588 bspkv = ipDiffim.BuildSpatialKernelVisitorF(self.basisList, bbox, self.ps)
590 for cand in cands:
591 bsikv.processCandidate(cand)
592 bspkv.processCandidate(cand)
594 HPspatialSolution = [[0.968505,
595 0.,
596 0.,
597 0.,
598 0.,
599 0.,
600 0.],
601 [-0.000094,
602 -0.000206,
603 -0.000027,
604 0.000025,
605 -0.000705,
606 0.000162],
607 [-0.188375,
608 0.001801,
609 -0.027534,
610 0.008718,
611 0.016346,
612 -0.033879],
613 [0.000004,
614 0.000012,
615 0.000023,
616 0.000004,
617 0.000017,
618 -0.000020],
619 [0.000128,
620 -0.000218,
621 0.000304,
622 -0.000038,
623 -0.000151,
624 -0.000531],
625 [-0.000011,
626 -0.000013,
627 0.000038,
628 -0.000017,
629 0.000133,
630 0.000093],
631 [-0.000003,
632 0.000003,
633 0.000006,
634 0.000008,
635 0.000002,
636 -0.000010],
637 [-0.212235,
638 -0.000856,
639 0.012246,
640 -0.010893,
641 0.049302,
642 0.008249],
643 [0.000014,
644 -0.000002,
645 -0.000050,
646 -0.000001,
647 0.000030,
648 0.000020],
649 [-0.000001,
650 0.000010,
651 -0.000012,
652 -0.000007,
653 0.000015,
654 0.000019],
655 0.392482]
657 bspkv.solveLinearEquation()
658 sk, sb = bspkv.getSolutionPair()
659 spatialSolution = sk.getSpatialParameters()
661 # Kernel
662 spReorder = [0, 3, 1, 5, 4, 2]
663 for i in range(len(spatialSolution)):
664 for j in range(len(spReorder)):
665 self.assertAlmostEqual(HPspatialSolution[i][spReorder[j]] * self.parity[i],
666 spatialSolution[i][j], 5)
668 self.assertAlmostEqual(sb.getParameters()[0], HPspatialSolution[-1], 5)
670 def testAllVariation2(self):
671 # OK, I ran HP on all the things in this image. Enough for
672 # second order spatial variation
674 self.ps['constantVarianceWeighting'] = True
675 self.ps['spatialKernelOrder'] = 2
676 self.ps['spatialBgOrder'] = 2
678 # Ignore the whole kernelCellSet thing
679 cands = []
680 for fp in self.footprints:
681 bbox = fp.getBBox()
683 # Grab the centers in the parent's coordinate system
684 xC = int(0.5 * (bbox.getMinX() + bbox.getMaxX()))
685 yC = int(0.5 * (bbox.getMinY() + bbox.getMaxY()))
687 bbox = geom.Box2I(geom.Point2I(int(xC)-24, int(yC)-24), geom.Extent2I(49, 49))
689 tsmi = afwImage.MaskedImageF(self.tmi, bbox, origin=afwImage.LOCAL)
690 ssmi = afwImage.MaskedImageF(self.smi, bbox, origin=afwImage.LOCAL)
692 # Hotpants centroids go from -1 to 1
693 cand = ipDiffim.makeKernelCandidate((xC - 0.5 * self.smi.getWidth())
694 / (0.5 * self.smi.getWidth()),
695 (yC - 0.5 * self.smi.getHeight())
696 / (0.5 * self.smi.getHeight()),
697 tsmi, ssmi, self.ps)
698 cands.append(cand)
700 # Visitors
701 bbox = self.kernelCellSet.getBBox()
702 bsikv = ipDiffim.BuildSingleKernelVisitorF(self.basisList, self.ps)
703 bspkv = ipDiffim.BuildSpatialKernelVisitorF(self.basisList, bbox, self.ps)
705 for cand in cands:
706 bsikv.processCandidate(cand)
707 bspkv.processCandidate(cand)
709 HPspatialSolution = [[0.968505,
710 0.,
711 0.,
712 0.,
713 0.,
714 0.],
715 [-0.000094,
716 -0.000206,
717 -0.000027,
718 0.000025,
719 -0.000705,
720 0.000162],
721 [-0.188375,
722 0.001801,
723 -0.027534,
724 0.008718,
725 0.016346,
726 -0.033879],
727 [0.000004,
728 0.000012,
729 0.000023,
730 0.000004,
731 0.000017,
732 -0.000020],
733 [0.000128,
734 -0.000218,
735 0.000304,
736 -0.000038,
737 -0.000151,
738 -0.000531],
739 [-0.000011,
740 -0.000013,
741 0.000038,
742 -0.000017,
743 0.000133,
744 0.000093],
745 [-0.000003,
746 0.000003,
747 0.000006,
748 0.000008,
749 0.000002,
750 -0.000010],
751 [-0.212235,
752 -0.000856,
753 0.012246,
754 -0.010893,
755 0.049302,
756 0.008249],
757 [0.000014,
758 -0.000002,
759 -0.000050,
760 -0.000001,
761 0.000030,
762 0.000020],
763 [-0.000001,
764 0.000010,
765 -0.000012,
766 -0.000007,
767 0.000015,
768 0.000019],
769 [0.812488,
770 0.096456,
771 -1.140900,
772 0.132670,
773 -0.571923,
774 -0.284670]]
776 bspkv.solveLinearEquation()
777 sk, sb = bspkv.getSolutionPair()
778 spatialSolution = sk.getSpatialParameters()
780 # Kernel
781 spReorder = [0, 3, 1, 5, 4, 2]
782 for i in range(len(spatialSolution)):
783 for j in range(len(spReorder)):
784 self.assertAlmostEqual(HPspatialSolution[i][spReorder[j]] * self.parity[i],
785 spatialSolution[i][j], 5)
786 # Bg
787 spatialSolution = sb.getParameters()
788 for i in range(len(spatialSolution)):
789 self.assertAlmostEqual(HPspatialSolution[-1][spReorder[i]], spatialSolution[i], 5)
792class TestMemory(lsst.utils.tests.MemoryTestCase):
793 pass
796def setup_module(module):
797 lsst.utils.tests.init()
800if __name__ == "__main__": 800 ↛ 801line 800 didn't jump to line 801, because the condition on line 800 was never true
801 lsst.utils.tests.init()
802 unittest.main()