Example #1
0
    def runQuantum(self, butlerQC, inputRefs, outputRefs):
        inputs = butlerQC.get(inputRefs)
        expId, expBits = butlerQC.quantum.dataId.pack("visit_detector",
                                                      returnMaxBits=True)
        inputs['exposureIdInfo'] = ExposureIdInfo(expId, expBits)

        if self.config.doAstrometry:
            refObjLoader = ReferenceObjectLoader(dataIds=[ref.datasetRef.dataId
                                                          for ref in inputRefs.astromRefCat],
                                                 refCats=inputs.pop('astromRefCat'),
                                                 config=self.config.astromRefObjLoader, log=self.log)
            self.pixelMargin = refObjLoader.config.pixelMargin
            self.astrometry.setRefObjLoader(refObjLoader)

        if self.config.doPhotoCal:
            photoRefObjLoader = ReferenceObjectLoader(dataIds=[ref.datasetRef.dataId
                                                      for ref in inputRefs.photoRefCat],
                                                      refCats=inputs.pop('photoRefCat'),
                                                      config=self.config.photoRefObjLoader,
                                                      log=self.log)
            self.pixelMargin = photoRefObjLoader.config.pixelMargin
            self.photoCal.match.setRefObjLoader(photoRefObjLoader)

        outputs = self.run(**inputs)

        if self.config.doWriteMatches and self.config.doAstrometry:
            normalizedMatches = afwTable.packMatches(outputs.astromMatches)
            normalizedMatches.table.setMetadata(outputs.matchMeta)
            if self.config.doWriteMatchesDenormalized:
                denormMatches = denormalizeMatches(outputs.astromMatches, outputs.matchMeta)
                outputs.matchesDenormalized = denormMatches
            outputs.matches = normalizedMatches
        butlerQC.put(outputs, outputRefs)
    def adaptArgsAndRun(self, inputData, inputDataIds, outputDataIds, butler):
        expId, expBits = butler.registry.packDataId("visit_detector",
                                                    inputDataIds['exposure'],
                                                    returnMaxBits=True)
        inputData['exposureIdInfo'] = ExposureIdInfo(expId, expBits)

        if self.config.doAstrometry:
            refObjLoader = ReferenceObjectLoader(dataIds=inputDataIds['astromRefCat'],
                                                 butler=butler,
                                                 config=self.config.astromRefObjLoader,
                                                 log=self.log)
            self.pixelMargin = refObjLoader.config.pixelMargin
            self.astrometry.setRefObjLoader(refObjLoader)

        if self.config.doPhotoCal:
            photoRefObjLoader = ReferenceObjectLoader(inputDataIds['photoRefCat'],
                                                      butler,
                                                      self.config.photoRefObjLoader,
                                                      self.log)
            self.pixelMargin = photoRefObjLoader.config.pixelMargin
            self.photoCal.match.setRefObjLoader(photoRefObjLoader)

        results = self.run(**inputData)

        if self.config.doWriteMatches:
            normalizedMatches = afwTable.packMatches(results.astromMatches)
            normalizedMatches.table.setMetadata(results.matchMeta)
            if self.config.doWriteMatchesDenormalized:
                denormMatches = denormalizeMatches(results.astromMatches, results.matchMeta)
                results.matchesDenormalized = denormMatches
            results.matches = normalizedMatches
        return results
    def checkDenormalizeMatches(self, refType, srcType, MatchClass, num=10):
        """Check that denormalizeMatches works

        We create reference and source catalogs, generate matches,
        run denormalizeMatches and verify that the results are as
        expected (this includes checking that alias maps from the
        input catalogs are propagated to the "match" catalog).

        Parameters
        ----------
        refType : `str`
            Type of reference catalog/table; "Simple" or "Source".
        srcType : `str`
            Type of source catalog/table; "Simple" or "Source".
        MatchClass : `type`
            Class for match; should be suitable for the refType and srcType.
        """
        refSchema = getattr(lsst.afw.table,
                            refType + "Table").makeMinimalSchema()
        refCat = getattr(lsst.afw.table, refType + "Catalog")(refSchema)
        for ii in range(num):
            ref = refCat.addNew()
            ref.set("id", ii)

        srcSchema = getattr(lsst.afw.table,
                            srcType + "Table").makeMinimalSchema()
        aliasDict = dict(srcIdAlias="id", srcCoordAlias="coord")
        for k, v in aliasDict.items(
        ):  # Add some aliases to srcSchema's aliasMap
            srcSchema.getAliasMap().set(k, v)

        srcCat = getattr(lsst.afw.table, srcType + "Catalog")(srcSchema)
        for ii in range(2 * num, num, -1):
            src = srcCat.addNew()
            src.set("id", ii)
            src.set(
                "coord_ra", 100.0 * degrees
            )  # Arbitrary numbers to avoid NANs for checking dereference
            src.set("coord_dec", 1.0 * degrees)

        matches = [
            MatchClass(ref, src, ref.get("id"))
            for ref, src in zip(refCat, srcCat)
        ]
        catalog = denormalizeMatches(matches)
        for row, ref, src in zip(catalog, refCat, srcCat):
            self.assertEqual(row.get("ref_id"), ref.get("id"))
            self.assertEqual(row.get("src_id"), src.get("id"))
            self.assertEqual(row.get("distance"), ref.get("id"))
            self.assertEqual(row.get("src_srcIdAlias"),
                             row.get("src_id"))  # intra-catalog check
            self.assertEqual(row.get("src_srcIdAlias"),
                             src.get("id"))  # inter-catalog check
            self.assertEqual(row.get("src_srcCoordAlias_ra"),
                             src.get("coord_ra"))  # inter-catalog check
            self.assertEqual(row.get("src_srcCoordAlias_dec"),
                             src.get("coord_dec"))  # inter-catalog check
    def checkDenormalizeMatches(self, refType, srcType, MatchClass, num=10):
        """Check that denormalizeMatches works

        We create reference and source catalogs, generate matches,
        run denormalizeMatches and verify that the results are as
        expected (this includes checking that alias maps from the
        input catalogs are propagated to the "match" catalog).

        Parameters
        ----------
        refType : `str`
            Type of reference catalog/table; "Simple" or "Source".
        srcType : `str`
            Type of source catalog/table; "Simple" or "Source".
        MatchClass : `type`
            Class for match; should be suitable for the refType and srcType.
        """
        refSchema = getattr(lsst.afw.table, refType + "Table").makeMinimalSchema()
        refCat = getattr(lsst.afw.table, refType + "Catalog")(refSchema)
        for ii in range(num):
            ref = refCat.addNew()
            ref.set("id", ii)

        srcSchema = getattr(lsst.afw.table, srcType + "Table").makeMinimalSchema()
        aliasDict = dict(srcIdAlias="id", srcCoordAlias="coord")
        for k, v in aliasDict.items():  # Add some aliases to srcSchema's aliasMap
            srcSchema.getAliasMap().set(k, v)

        srcCat = getattr(lsst.afw.table, srcType + "Catalog")(srcSchema)
        for ii in range(2*num, num, -1):
            src = srcCat.addNew()
            src.set("id", ii)
            src.set("coord_ra", 100.0*degrees)  # Arbitrary numbers to avoid NANs for checking dereference
            src.set("coord_dec", 1.0*degrees)

        matches = [MatchClass(ref, src, ref.get("id")) for ref, src in zip(refCat, srcCat)]
        catalog = denormalizeMatches(matches)
        for row, ref, src in zip(catalog, refCat, srcCat):
            self.assertEqual(row.get("ref_id"), ref.get("id"))
            self.assertEqual(row.get("src_id"), src.get("id"))
            self.assertEqual(row.get("distance"), ref.get("id"))
            self.assertEqual(row.get("src_srcIdAlias"), row.get("src_id"))  # intra-catalog check
            self.assertEqual(row.get("src_srcIdAlias"), src.get("id"))  # inter-catalog check
            self.assertEqual(row.get("src_srcCoordAlias_ra"), src.get("coord_ra"))  # inter-catalog check
            self.assertEqual(row.get("src_srcCoordAlias_dec"), src.get("coord_dec"))  # inter-catalog check
Example #5
0
    def writeOutputs(self, dataRef, exposure, background, sourceCat,
                     astromMatches, matchMeta):
        """Write output data to the output repository

        @param[in] dataRef  butler data reference corresponding to a science
            image
        @param[in] exposure  exposure to write
        @param[in] background  background model for exposure
        @param[in] sourceCat  catalog of measured sources
        @param[in] astromMatches  list of source/refObj matches from the
            astrometry solver
        """
        dataRef.put(sourceCat, "src")
        if self.config.doWriteMatches and astromMatches is not None:
            normalizedMatches = afwTable.packMatches(astromMatches)
            normalizedMatches.table.setMetadata(matchMeta)
            dataRef.put(normalizedMatches, "srcMatch")
            if self.config.doWriteMatchesDenormalized:
                denormMatches = denormalizeMatches(astromMatches, matchMeta)
                dataRef.put(denormMatches, "srcMatchFull")
        dataRef.put(exposure, "calexp")
        dataRef.put(background, "calexpBackground")
Example #6
0
    def checkDenormalizeMatches(self, refType, srcType, MatchClass, num=10):
        """Check that denormalizeMatches works

        We create reference and source catalogs, generate matches,
        run denormalizeMatches and verify that the results are as expected.

        Parameters
        ----------
        refType : `str`
            Type of reference catalog/table; "Simple" or "Source".
        srcType : `str`
            Type of source catalog/table; "Simple" or "Source".
        MatchClass : `type`
            Class for match; should be suitable for the refType and srcType.
        """
        refSchema = getattr(lsst.afw.table,
                            refType + "Table").makeMinimalSchema()
        refCat = getattr(lsst.afw.table, refType + "Catalog")(refSchema)
        for ii in range(num):
            ref = refCat.addNew()
            ref.set("id", ii)

        srcSchema = getattr(lsst.afw.table,
                            srcType + "Table").makeMinimalSchema()
        srcCat = getattr(lsst.afw.table, srcType + "Catalog")(srcSchema)
        for ii in range(2 * num, num, -1):
            src = srcCat.addNew()
            src.set("id", ii)

        matches = [
            MatchClass(ref, src, ref.get("id"))
            for ref, src in zip(refCat, srcCat)
        ]
        catalog = denormalizeMatches(matches)
        for row, ref, src in zip(catalog, refCat, srcCat):
            self.assertEqual(row.get("ref_id"), ref.get("id"))
            self.assertEqual(row.get("src_id"), src.get("id"))
            self.assertEqual(row.get("distance"), ref.get("id"))