def testGMixToMultiShapelet(self):
        np.random.seed(5)  # value doesn't matter, but we want deterministic numbers
        msf1 = MultiShapeletFunction([self.makeRandomShapeletFunction(order=0) for n in range(4)])
        gmix1 = convertMultiShapeletToGMix(msf1)
        msf2 = convertGMixToMultiShapelet(gmix1)

        # Test that we've round-tripped through GMix
        self.compareMultiShapeletFunctions(msf1, msf2, simplify=False)

        # Test that LSST and ngmix make images that agree
        bbox = Box2I(Point2I(-20, -15), Point2I(20, 15))
        image1 = Image(bbox, dtype=np.float64)
        msf1.evaluate().addToImage(image1)
        image2 = Image(bbox, dtype=np.float64)
        image2.array[:, :] = gmix1.make_image(image2.array.shape)
        self.assertImagesAlmostEqual(image1, image2)

        # Should reject ShapeletFunctions with order > 0, unless ignoreHighOrder==True
        with self.assertRaises(ValueError):
            problematic = MultiShapeletFunction([self.makeRandomShapeletFunction(order=2) for n in range(4)])
            convertMultiShapeletToGMix(problematic)
        ok = convertMultiShapeletToGMix(problematic, ignoreHighOrder=True)
        truncated1 = convertGMixToMultiShapelet(ok)
        truncated2 = MultiShapeletFunction([ShapeletFunction(0, HERMITE, p.getEllipse(),
                                                             p.getCoefficients()[0:1])
                                            for p in problematic.getComponents()])
        self.compareMultiShapeletFunctions(truncated1, truncated2)
Esempio n. 2
0
 def _doComputeKernelImage(self, position=None, color=None):
     bbox = self.computeBBox()
     img = Image(bbox, dtype=np.float64)
     x, y = np.ogrid[bbox.minY:bbox.maxY + 1, bbox.minX:bbox.maxX + 1]
     rsqr = x**2 + y**2
     img.array[:] = np.exp(-0.5 * rsqr / self.sigma**2)
     img.array /= np.sum(img.array)
     return img
Esempio n. 3
0
 def _doComputeKernelImage(self, position=None, color=None):
     bbox = Box2I(Point2I(-3, -3), Extent2I(7, 7))
     img = Image(bbox, dtype=np.float64)
     x, y = np.ogrid[bbox.minY:bbox.maxY + 1, bbox.minX:bbox.maxX + 1]
     rsqr = x**2 + y**2
     if position.x >= 0.0:
         img.array[:] = np.exp(-0.5 * rsqr)
     else:
         img.array[:] = np.exp(-0.5 * rsqr / 4)
     img.array /= np.sum(img.array)
     return img
Esempio n. 4
0
 def _doImage(self, position, center):
     # Follow Piff conventions for center.
     # None => draw as if star at position
     # True => draw in center of image
     gsimg = self._piffResult.draw(position.x,
                                   position.y,
                                   stamp_size=self.width,
                                   center=center)
     bbox = self._doBBox(position, center)
     img = Image(bbox, dtype=np.float64)
     img.array[:] = gsimg.array
     img.array /= np.sum(img.array)
     return img
 def setUp(self):
     dimensions = Extent2I(7, 7)
     self.bbox = Box2I(Point2I(-dimensions/2), dimensions)
     self.img = Image(self.bbox, dtype=np.float64)
     x, y = np.ogrid[-3:4, -3:4]
     rsqr = x**2 + y**2
     # Some arbitrary circular double Gaussian
     self.img.array[:] = np.exp(-0.5*rsqr**2) + np.exp(-0.5*rsqr**2/4)
     self.img.array /= np.sum(self.img.array)
     self.psf = MyTestImagePsf(self.img)
Esempio n. 6
0
 def testImageFitsReader(self):
     for n, dtypeIn in enumerate(self.dtypes):
         with self.subTest(dtypeIn=dtypeIn):
             imageIn = Image(self.bbox, dtype=dtypeIn)
             imageIn.array[:, :] = np.random.randint(low=1, high=5, size=imageIn.array.shape)
             with lsst.utils.tests.getTempFilePath(".fits") as fileName:
                 imageIn.writeFits(fileName)
                 reader = ImageFitsReader(fileName)
                 self.assertEqual(reader.readBBox(), self.bbox)
                 self.assertEqual(reader.readDType(), dtypeIn)
                 self.assertEqual(reader.fileName, fileName)
                 for args in self.args:
                     with self.subTest(args=args):
                         array1 = reader.readArray(*args)
                         image1 = reader.read(*args)
                         subIn = imageIn.subset(*args) if args else imageIn
                         self.assertEqual(dtypeIn, array1.dtype)
                         self.assertTrue(np.all(subIn.array == array1))
                         self.assertEqual(subIn.getXY0(), reader.readXY0(*args))
                         self.assertImagesEqual(subIn, image1)
                 for dtype2 in self.dtypes[n:]:
                     for args in self.args:
                         with self.subTest(dtype2=dtype2, args=args):
                             subIn = imageIn.subset(*args) if args else imageIn
                             array2 = reader.readArray(*args, dtype=dtype2)
                             image2 = reader.read(*args, dtype=dtype2)
                             self.assertEqual(dtype2, array2.dtype)
                             self.assertTrue(np.all(subIn.array == array2))
                             self.assertEqual(subIn.getXY0(), reader.readXY0(*args))
                             self.assertEqual(subIn.getBBox(), image2.getBBox())
                             self.assertTrue(np.all(image2.array == array2))
Esempio n. 7
0
    def checkMultiPlaneReader(self, reader, objectIn, fileName, dtypesOut,
                              compare):
        """Test operations common to MaskedImageFitsReader and ExposureFitsReader.

        Parameters
        ----------
        reader : `MaskedImageFitsReader` or `ExposureFitsReader` instance
            Reader object to test.
        objectIn : `MaskedImage` or `Exposure`
            Object originally saved, to compare against.
        fileName : `str`
            Name of the file the reader is reading.
        dtypesOut : sequence of `numpy.dype`
            Compatible image pixel types to try to read in.
        compare : callable
            Callable that compares objects of the same type as objectIn and
            asserts if they are not equal.
        """
        dtypeIn = objectIn.image.dtype
        self.assertEqual(reader.readBBox(), self.bbox)
        self.assertEqual(reader.readImageDType(), dtypeIn)
        self.assertEqual(reader.readMaskDType(), MaskPixel)
        self.assertEqual(reader.readVarianceDType(), VariancePixel)
        self.assertEqual(reader.fileName, fileName)
        for args in self.args:
            with self.subTest(args=args):
                object1 = reader.read(*args)
                subIn = objectIn.subset(*args) if args else objectIn
                self.assertEqual(object1.image.array.dtype, dtypeIn)
                self.assertEqual(object1.mask.array.dtype, MaskPixel)
                self.assertEqual(object1.variance.array.dtype, VariancePixel)
                self.assertImagesEqual(subIn.image, reader.readImage(*args))
                self.assertImagesEqual(subIn.mask, reader.readMask(*args))
                self.assertImagesEqual(subIn.variance,
                                       reader.readVariance(*args))
                compare(subIn, object1)
                for dtype2 in dtypesOut:
                    with self.subTest(dtype2=dtype2, args=args):
                        object2 = reader.read(*args, dtype=dtype2)
                        image2 = reader.readImage(*args, dtype=dtype2)
                        self.assertEqual(object2.image.array.dtype, dtype2)
                        self.assertEqual(object2.mask.array.dtype, MaskPixel)
                        self.assertEqual(object2.variance.array.dtype,
                                         VariancePixel)
                        self.assertImagesEqual(
                            subIn.image, Image(image2,
                                               deep=True,
                                               dtype=dtypeIn))
                        self.assertImagesEqual(image2, object2.image)
                        compare(subIn, object2)
Esempio n. 8
0
 def testImageFitsReader(self):
     for n, dtypeIn in enumerate(self.dtypes):
         with self.subTest(dtypeIn=dtypeIn):
             imageIn = Image(self.bbox, dtype=dtypeIn)
             imageIn.array[:, :] = np.random.randint(
                 low=1, high=5, size=imageIn.array.shape)
             with lsst.utils.tests.getTempFilePath(".fits") as fileName:
                 imageIn.writeFits(fileName)
                 reader = ImageFitsReader(fileName)
                 self.assertEqual(reader.readBBox(), self.bbox)
                 self.assertEqual(reader.readDType(), dtypeIn)
                 self.assertEqual(reader.fileName, fileName)
                 for args in self.args:
                     with self.subTest(args=args):
                         array1 = reader.readArray(*args)
                         image1 = reader.read(*args)
                         subIn = imageIn.subset(*args) if args else imageIn
                         self.assertEqual(dtypeIn, array1.dtype)
                         self.assertTrue(np.all(subIn.array == array1))
                         self.assertEqual(subIn.getXY0(),
                                          reader.readXY0(*args))
                         self.assertImagesEqual(subIn, image1)
                 for dtype2 in self.dtypes[n:]:
                     for args in self.args:
                         with self.subTest(dtype2=dtype2, args=args):
                             subIn = imageIn.subset(
                                 *args) if args else imageIn
                             array2 = reader.readArray(*args, dtype=dtype2)
                             image2 = reader.read(*args, dtype=dtype2)
                             self.assertEqual(dtype2, array2.dtype)
                             self.assertTrue(np.all(subIn.array == array2))
                             self.assertEqual(subIn.getXY0(),
                                              reader.readXY0(*args))
                             self.assertEqual(subIn.getBBox(),
                                              image2.getBBox())
                             self.assertTrue(np.all(image2.array == array2))