def bypass_defects(self, datasetType, pythonType, butlerLocation, dataId):
        """Return a defect based on the butler location returned by map_defects.

        Parameters
        ----------
        butlerLocation : `lsst.daf.persistence.ButlerLocation`
            A ButlerLocation with locationList = path to defects FITS file.
        dataId : `dict`
            The usual data ID; "ccd" must be set.

        Notes
        -----
        The name "bypass_XXX" means the butler makes no attempt to convert
        the ButlerLocation into an object, which is what we want for now,
        since that conversion is a bit tricky.
        """
        (ccdKey, ccdSerial) = self._getCcdKeyVal(dataId)
        defectsFitsPath = butlerLocation.locationList[0]
        with pyfits.open(defectsFitsPath) as hduList:
            for hdu in hduList[1:]:
                if str(hdu.header["SERIAL"]) != ccdSerial:
                    continue

                defectList = []
                for data in hdu.data:
                    bbox = afwGeom.Box2I(
                        afwGeom.Point2I(int(data['x0']), int(data['y0'])),
                        afwGeom.Extent2I(int(data['width']), int(data['height'])),
                    )
                    defectList.append(afwImage.DefectBase(bbox))
                return defectList

        raise RuntimeError("No defects for ccdSerial %s in %s" % (ccdSerial, defectsFitsPath))
Example #2
0
 def X_bypass_defects(self, datasetType, pythonType, location, dataId):
     """ since we have no defects, return an empty list.  Fix this when defects exist """
     return [afwImage.DefectBase(afwGeom.Box2I(afwGeom.Point2I(x0, y0), afwGeom.Point2I(x1, y1))) for
             x0, y0, x1, y1 in (
                 # These may be hot pixels, but we'll treat them as bad until we can get more data
                 (3801, 666, 3805, 669),
                 (3934, 582, 3936, 589),
             )]
Example #3
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")