Exemple #1
0
    def testAstropyRegion(self):
        """Read a FITS region file created by Astropy regions."""
        # The file contains three regions:
        #
        # - Point2I(340, 344)
        # - Point2I(340, 344)
        # - Box2I(minimum=Point2I(5, -5), dimensions=Extent2I(10, 20))
        #
        # The two coincident points are combined on read, so we end up with two defects.

        with self.assertLogs():
            defects = Defects.readFits(os.path.join(TESTDIR, "data",
                                                    "fits_region.fits"),
                                       normalize_on_init=True)

        self.assertEqual(len(defects), 2)
Exemple #2
0
    def test_defects(self):
        defects = Defects()

        defects.append(
            algorithms.Defect(
                lsst.geom.Box2I(lsst.geom.Point2I(5, 6),
                                lsst.geom.Point2I(41, 50))))

        defects.append(
            lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Point2I(4, 5)))
        defects.append(lsst.geom.Point2I(50, 50))
        defects.append(
            afwImage.DefectBase(
                lsst.geom.Box2I(lsst.geom.Point2I(100, 200),
                                lsst.geom.Extent2I(5, 5))))
        self.assertEqual(len(defects), 4)

        for d in defects:
            self.assertIsInstance(d, algorithms.Defect)

        # Transposition
        transposed = defects.transpose()
        self.assertEqual(len(transposed), len(defects))

        # Check that an individual defect is found properly transposed within
        # the outputs.
        found = False
        for defect in transposed:
            if defect.getBBox() == lsst.geom.Box2I(lsst.geom.Point2I(6, 5),
                                                   lsst.geom.Extent2I(45, 37)):
                found = True
                break
        self.assertTrue(found)

        # Serialization round trip
        meta = PropertyList()
        meta["TESTHDR"] = "testing"
        defects.setMetadata(meta)

        table = defects.toFitsRegionTable()

        defects2 = Defects.fromTable([table])

        self.assertEqual(defects2, defects)

        # via FITS
        with lsst.utils.tests.getTempFilePath(".fits") as tmpFile:
            defects.writeFits(tmpFile)
            defects2 = Defects.readFits(tmpFile)

        # Equality tests the bounding boxes so metadata is tested separately.
        self.assertEqual(defects2, defects)
        self.assertMetadata(defects2, defects)

        # via text file
        with lsst.utils.tests.getTempFilePath(".ecsv") as tmpFile:
            defects.writeText(tmpFile)
            defects2 = Defects.readText(tmpFile)

        # Equality tests the bounding boxes so metadata is tested separately.
        self.assertEqual(defects2, defects)
        self.assertMetadata(defects2, defects)

        # Check bad values
        with self.assertRaises(ValueError):
            defects.append(
                lsst.geom.Box2D(lsst.geom.Point2D(0., 0.),
                                lsst.geom.Point2D(3.1, 3.1)))
        with self.assertRaises(ValueError):
            defects.append("defect")