Exemplo n.º 1
0
    def run(
        self,
        refCatalogs: typing.List[afwTable.SimpleCatalog],
        exposure: afwImage.Exposure,
    ) -> pipeBase.Struct:

        refObjLoader = self.getRefObjLoader(refCatalogs)

        detector = exposure.getDetector()
        detectorWcs = exposure.getWcs()

        try:
            # Match detector layout to reference catalog
            refSelection = self.runSelection(refObjLoader, detector,
                                             detectorWcs, self.filterName)

        # Except RuntimeError caused when no reference catalog
        # available for the region covered by detector
        except RuntimeError:
            warnings.warn(
                "No catalogs cover this detector. Returning empty catalog.",
                RuntimeWarning,
            )
            refSelection = None

        fieldObjects = self.donutCatalogToDataFrame(refSelection)

        return pipeBase.Struct(donutCatalog=fieldObjects)
Exemplo n.º 2
0
    def run(
        self,
        exposure: afwImage.Exposure,
    ) -> pipeBase.Struct:

        detectorName = exposure.getDetector().getName()
        defocalType = DefocalType.Extra  # we use one of the DefocalTypes,
        # TODO: perhaps could make that as another configurable
        camType = getCamType(self.instName)
        pixelScale = exposure.getWcs().getPixelScale().asArcseconds()

        # create a donut template
        templateMaker = DonutTemplateFactory.createDonutTemplate(
            DonutTemplateType.Model)

        template = templateMaker.makeTemplate(
            detectorName,
            defocalType,
            self.donutTemplateSize,
            camType,
            self.opticalModel,
            pixelScale,
        )

        # given this template, detect donuts in one of the defocal images
        detector = DonutDetector()
        expArray = copy(exposure.getImage().getArray())
        donutDf = detector.detectDonuts(
            expArray,
            template,
            blendRadius=self.blendRadius,
            peakThreshold=self.peakThreshold,
            binaryChoice=self.binaryChoice,
        )

        # make a donut catalog :
        # 1) remove the blends in donut catalog
        if self.config.removeBlends:
            donutDfCopy = donutDf[~donutDf["blended"]].copy()
        else:
            donutDfCopy = donutDf

        # 2) update column names and content
        donutCatUpd = self.updateDonutCatalog(donutDfCopy, exposure)

        return pipeBase.Struct(donutCatalog=donutCatUpd)
    def run(self, exposure: afwImage.Exposure,
            inputCatalog: afwTable.SourceCatalog, msg: str) -> pipeBase.Struct:
        self.log.info(f"Running aperture phot {msg}")
        # Get the dimensions of the exposure
        dimensions = exposure.getDimensions()

        # Get indexes for each pixel
        indy, indx = np.indices((dimensions.getY(), dimensions.getX()))

        # Loop over each record in the catalog
        for i, source in enumerate(inputCatalog):
            if i % 100 == 0:
                self.log.info(f"Processing record {i}")
            # Create an aperture and measure the flux
            center = source.getCentroid()
            mask = ((indy - center.getY())**2 +
                    (indx - center.getX())**2)**0.5 < self.apRad
            flux = np.sum(exposure.image.array * mask)

            # Add a record to the output catalog
            tmpRecord = self.outputCatalog.addNew()
            tmpRecord.set(self.apKey, flux)

        return pipeBase.Struct(outputCatalog=self.outputCatalog)
Exemplo n.º 4
0
 def testMultiPlaneFitsReaders(self):
     """Run tests for MaskedImageFitsReader and ExposureFitsReader.
     """
     metadata = PropertyList()
     metadata.add("FIVE", 5)
     metadata.add("SIX", 6.0)
     wcs = makeSkyWcs(Point2D(2.5, 3.75),
                      SpherePoint(40.0 * degrees, 50.0 * degrees),
                      np.array([[1E-5, 0.0], [0.0, -1E-5]]))
     defineFilter("test_readers_filter", lambdaEff=470.0)
     calib = PhotoCalib(2.5E4)
     psf = GaussianPsf(21, 21, 8.0)
     polygon = Polygon(Box2D(self.bbox))
     apCorrMap = ApCorrMap()
     visitInfo = VisitInfo(exposureTime=5.0)
     transmissionCurve = TransmissionCurve.makeIdentity()
     coaddInputs = CoaddInputs(ExposureTable.makeMinimalSchema(),
                               ExposureTable.makeMinimalSchema())
     detector = DetectorWrapper().detector
     record = coaddInputs.ccds.addNew()
     record.setWcs(wcs)
     record.setPhotoCalib(calib)
     record.setPsf(psf)
     record.setValidPolygon(polygon)
     record.setApCorrMap(apCorrMap)
     record.setVisitInfo(visitInfo)
     record.setTransmissionCurve(transmissionCurve)
     record.setDetector(detector)
     for n, dtypeIn in enumerate(self.dtypes):
         with self.subTest(dtypeIn=dtypeIn):
             exposureIn = Exposure(self.bbox, dtype=dtypeIn)
             shape = exposureIn.image.array.shape
             exposureIn.image.array[:, :] = np.random.randint(low=1,
                                                              high=5,
                                                              size=shape)
             exposureIn.mask.array[:, :] = np.random.randint(low=1,
                                                             high=5,
                                                             size=shape)
             exposureIn.variance.array[:, :] = np.random.randint(low=1,
                                                                 high=5,
                                                                 size=shape)
             exposureIn.setMetadata(metadata)
             exposureIn.setWcs(wcs)
             exposureIn.setFilter(Filter("test_readers_filter"))
             exposureIn.setFilterLabel(
                 FilterLabel(physical="test_readers_filter"))
             exposureIn.setPhotoCalib(calib)
             exposureIn.setPsf(psf)
             exposureIn.getInfo().setValidPolygon(polygon)
             exposureIn.getInfo().setApCorrMap(apCorrMap)
             exposureIn.getInfo().setVisitInfo(visitInfo)
             exposureIn.getInfo().setTransmissionCurve(transmissionCurve)
             exposureIn.getInfo().setCoaddInputs(coaddInputs)
             exposureIn.setDetector(detector)
             with lsst.utils.tests.getTempFilePath(".fits") as fileName:
                 exposureIn.writeFits(fileName)
                 self.checkMaskedImageFitsReader(exposureIn, fileName,
                                                 self.dtypes[n:])
                 self.checkExposureFitsReader(exposureIn, fileName,
                                              self.dtypes[n:])
Exemplo n.º 5
0
 def testMultiPlaneFitsReaders(self):
     """Run tests for MaskedImageFitsReader and ExposureFitsReader.
     """
     metadata = PropertyList()
     metadata.add("FIVE", 5)
     metadata.add("SIX", 6.0)
     wcs = makeSkyWcs(Point2D(2.5, 3.75), SpherePoint(40.0*degrees, 50.0*degrees),
                      np.array([[1E-5, 0.0], [0.0, -1E-5]]))
     defineFilter("test_readers_filter", lambdaEff=470.0)
     calib = PhotoCalib(2.5E4)
     psf = GaussianPsf(21, 21, 8.0)
     polygon = Polygon(Box2D(self.bbox))
     apCorrMap = ApCorrMap()
     visitInfo = VisitInfo(exposureTime=5.0)
     transmissionCurve = TransmissionCurve.makeIdentity()
     coaddInputs = CoaddInputs(ExposureTable.makeMinimalSchema(), ExposureTable.makeMinimalSchema())
     detector = DetectorWrapper().detector
     record = coaddInputs.ccds.addNew()
     record.setWcs(wcs)
     record.setCalib(calib)
     record.setPsf(psf)
     record.setValidPolygon(polygon)
     record.setApCorrMap(apCorrMap)
     record.setVisitInfo(visitInfo)
     record.setTransmissionCurve(transmissionCurve)
     record.setDetector(detector)
     for n, dtypeIn in enumerate(self.dtypes):
         with self.subTest(dtypeIn=dtypeIn):
             exposureIn = Exposure(self.bbox, dtype=dtypeIn)
             shape = exposureIn.image.array.shape
             exposureIn.image.array[:, :] = np.random.randint(low=1, high=5, size=shape)
             exposureIn.mask.array[:, :] = np.random.randint(low=1, high=5, size=shape)
             exposureIn.variance.array[:, :] = np.random.randint(low=1, high=5, size=shape)
             exposureIn.setMetadata(metadata)
             exposureIn.setWcs(wcs)
             exposureIn.setFilter(Filter("test_readers_filter"))
             exposureIn.setCalib(calib)
             exposureIn.setPsf(psf)
             exposureIn.getInfo().setValidPolygon(polygon)
             exposureIn.getInfo().setApCorrMap(apCorrMap)
             exposureIn.getInfo().setVisitInfo(visitInfo)
             exposureIn.getInfo().setTransmissionCurve(transmissionCurve)
             exposureIn.getInfo().setCoaddInputs(coaddInputs)
             exposureIn.setDetector(detector)
             with lsst.utils.tests.getTempFilePath(".fits") as fileName:
                 exposureIn.writeFits(fileName)
                 self.checkMaskedImageFitsReader(exposureIn, fileName, self.dtypes[n:])
                 self.checkExposureFitsReader(exposureIn, fileName, self.dtypes[n:])