24 Test utility code for shapelets library; here so it can be used
25 in multiple test scripts and tests in downstream packages.
42 v = numpy.zeros(n, dtype=float)
48 z = numpy.zeros((y.size, x.size), dtype=float)
49 e = function.evaluate()
50 for i, py
in enumerate(y):
51 for j, px
in enumerate(x):
52 z[i, j] = e(float(px), float(py))
63 float(numpy.random.uniform(low=1, high=2)),
64 float(numpy.random.uniform(low=1, high=2)),
65 float(numpy.random.uniform(low=0, high=numpy.pi))
71 result.setEllipse(ellipse)
72 result.getEllipse().
scale(scale)
78 for n
in range(nComponents):
79 components.append(ShapeletTestCase.makeRandomShapeletFunction(ellipse=ellipse))
83 atolEllipse=1E-14, atolCoeff=1E-14):
84 self.assertEqual(a.getOrder(), b.getOrder())
85 self.assertEqual(a.getBasisType(), b.getBasisType())
86 self.assertFloatsAlmostEqual(a.getEllipse().getParameterVector(),
87 b.getEllipse().getParameterVector(),
88 rtol=rtolEllipse, atol=atolEllipse)
89 self.assertFloatsAlmostEqual(a.getCoefficients(), b.getCoefficients(),
90 rtol=rtolCoeff, atol=atolCoeff)
94 for s
in msf.getComponents():
95 if not numpy.allclose(s.getCoefficients(), 0.0):
96 params = tuple(s.getEllipse().getParameterVector()) + tuple(s.getCoefficients())
97 keep.append((params, s))
99 keep.sort(key=
lambda t: t[0])
100 for params, s
in keep:
105 atolEllipse=1E-14, atolCoeff=1E-14):
109 self.assertEqual(len(a.getComponents()), len(b.getComponents()))
110 for sa, sb
in zip(a.getComponents(), b.getComponents()):
112 atolEllipse=atolEllipse, atolCoeff=atolCoeff)
115 gx, gy = numpy.meshgrid(x, y)
121 (gx**2 * z).sum() / m,
122 (gy**2 * z).sum() / m,
123 (gx * gy * z).sum() / m
126 shapeletMoments = function.evaluate().computeMoments()
127 self.assertFloatsAlmostEqual(imageMoments.getCenter().getX(),
128 shapeletMoments.getCenter().getX(), rtol=1E-3)
129 self.assertFloatsAlmostEqual(imageMoments.getCenter().getY(),
130 shapeletMoments.getCenter().getY(), rtol=1E-3)
131 self.assertFloatsAlmostEqual(imageMoments.getCore().getIxx(),
132 shapeletMoments.getCore().getIxx(), rtol=1E-3)
133 self.assertFloatsAlmostEqual(imageMoments.getCore().getIyy(),
134 shapeletMoments.getCore().getIyy(), rtol=1E-3)
135 self.assertFloatsAlmostEqual(imageMoments.getCore().getIxy(),
136 shapeletMoments.getCore().getIxy(), rtol=1E-3)
137 integral = numpy.trapz(numpy.trapz(z, gx, axis=1), y, axis=0)
138 self.assertFloatsAlmostEqual(integral, function.evaluate().
integrate(), rtol=1E-3)
142 i1 = lsst.afw.image.ImageD(bbox)
144 self.assertFloatsAlmostEqual(i1.getArray().sum(), f1.evaluate().
integrate(), rtol=1E-3)
145 i2 = lsst.afw.image.ImageD(bbox)
147 self.assertFloatsAlmostEqual(i2.getArray().sum(), f2.evaluate().
integrate(), rtol=1E-3)
148 fc1 = f1.convolve(f2)
149 fc2 = f2.convolve(f1)
150 ic1 = lsst.afw.image.ImageD(bbox)
152 ic2 = lsst.afw.image.ImageD(bbox)
154 self.assertFloatsAlmostEqual(ic1.getArray(), ic2.getArray())
155 out = lsst.afw.image.ImageD(bbox)
157 print(
"Skipping convolution test; scipy could not be imported.")
163 scipy.ndimage.convolve(i1.getArray(), i2.getArray(), output=out.getArray(),
164 mode=
"constant", cval=0.0)
165 self.assertFloatsAlmostEqual(out.getArray(), ic1.getArray(), rtol=1E-4, atol=1E-5)
166 self.assertFloatsAlmostEqual(out.getArray(), ic2.getArray(), rtol=1E-4, atol=1E-5)