def __init__(self, magType1, magType2, starGalaxyToggle, **kwargs): testLabel = magType1 + "-" + magType2 QaAnalysisTask.__init__(self, testLabel, **kwargs) self.magCut = self.config.magCut self.deltaLimits = [self.config.deltaMin, self.config.deltaMax] self.rmsLimits = [0.0, self.config.rmsMax] self.derrLimits = [0.0, self.config.derrMax] self.slopeLimits = [ -self.config.slopeMinSigma, self.config.slopeMaxSigma ] self.starGalaxyToggle = starGalaxyToggle # not from config! self.sCatDummy = pqaSource.Catalog() self.srefCatDummy = pqaSource.RefCatalog() def magType(mType): if re.search("(psf|PSF)", mType): return "psf" elif re.search("^ap", mType): return "ap" elif re.search("^mod", mType): return "mod" elif re.search("^cat", mType): return "cat" elif re.search("^inst", mType): return "inst" self.magType1 = magType(magType1) self.magType2 = magType(magType2) self.description = """
def __init__(self, figsize=(5.0, 5.0), **kwargs): QaAnalysisTask.__init__(self, **kwargs) self.figsize = figsize self.limits = [self.config.offsetMin, self.config.offsetMax] self.sCatDummy = pqaSource.Catalog() self.srefCatDummy = pqaSource.RefCatalog() self.description = """
def __init__(self, **kwargs): QaAnalysisTask.__init__(self, **kwargs) self.limitsEllip = [0.0, self.config.ellipMax] self.limitsFwhm = [0.0, self.config.fwhmMax] self.sCatDummy = pqaSource.Catalog() self.srefCatDummy = pqaSource.RefCatalog() self.description = """
def __init__(self, **kwargs): QaAnalysisTask.__init__(self, **kwargs) self.limits = [0, self.config.maxMissing] self.nx = self.config.nx self.ny = self.config.ny self.sCatDummy = pqaSource.Catalog() self.srefCatDummy = pqaSource.RefCatalog() self.description = """
def __init__(self, **kwargs): QaAnalysisTask.__init__(self, **kwargs) self.medLimits = [-self.config.maxMedian, self.config.maxMedian] self.rmsLimits = [0, self.config.maxRms] self.maxMag = self.config.maxMag self.magType1 = "ap" self.magType2 = "cat" self.sCatDummy = pqaSource.Catalog() self.srefCatDummy = pqaSource.RefCatalog() self.description = """
def test(self, data, dataId, fluxType="psf"): testSet = self.getTestSet(data, dataId) testSet.addMetadata({"Description": self.description}) self.fluxType = fluxType self.detector = data.getDetectorBySensor(dataId) self.filter = data.getFilterBySensor(dataId) self.matchListDictSrc = data.getMatchListBySensor(dataId, useRef='src') self.orphan = raftCcdData.RaftCcdVector(self.detector) self.matchedStar = raftCcdData.RaftCcdVector(self.detector) self.blendedStar = raftCcdData.RaftCcdVector(self.detector) self.undetectedStar = raftCcdData.RaftCcdVector(self.detector) self.matchedGalaxy = raftCcdData.RaftCcdVector(self.detector) self.blendedGalaxy = raftCcdData.RaftCcdVector(self.detector) self.undetectedGalaxy = raftCcdData.RaftCcdVector(self.detector) self.depth = raftCcdData.RaftCcdData(self.detector) if hasMinuit: self.fit = raftCcdData.RaftCcdData(self.detector, initValue=[0.0, 0.0]) sCatDummy = pqaSource.Catalog().catalog sCatSchema = sCatDummy.getSchema() srefCatDummy = pqaSource.RefCatalog().catalog srefCatSchema = srefCatDummy.getSchema() psfKey = sCatSchema.find('PsfFlux').key psfErrKey = sCatSchema.find('PsfFluxErr').key apKey = sCatSchema.find('ApFlux').key apErrKey = sCatSchema.find('ApFluxErr').key extKey = sCatSchema.find('Extendedness').key refPsfKey = srefCatSchema.find('PsfFlux').key self.faintest = 0.0 for key in self.detector.keys(): raftId = self.detector[key].getParent().getId().getName() ccdId = self.detector[key].getId().getName() filterName = self.filter[key].getName() if self.matchListDictSrc.has_key(key): # Detections matchSet = [[ self.matchListDictSrc[key]['matched'], self.matchedStar, self.matchedGalaxy ], [ self.matchListDictSrc[key]['blended'], self.blendedStar, self.blendedGalaxy ]] for mset in matchSet: mdict, starvec, galvec = mset stars = [] galaxies = [] for m in mdict: sref, s, dist = m if fluxType == "psf": fref = sref.getD(refPsfKey) f = s.getD(psfKey) ferr = s.getD(psfErrKey) else: fref = sref.getD(refPsfKey) f = s.getD(apKey) ferr = s.getD(apErrKey) if (fref > 0.0 and f > 0.0): # Use known catalog mag mrefmag = -2.5 * num.log10(fref) if num.isfinite(mrefmag): if mrefmag > self.faintest: self.faintest == mrefmag if s.getD(extKey) > 0.0: galaxies.append(mrefmag) else: stars.append(mrefmag) starvec.set(raftId, ccdId, num.array(stars)) galvec.set(raftId, ccdId, num.array(galaxies)) # Non-detections undetectedStars = [] undetectedGalaxies = [] for nondet in self.matchListDictSrc[key]['undetected']: mag = nondet.getMag(filterName) if mag > self.faintest: self.faintest = mag if nondet.getIsStar(): undetectedStars.append(mag) else: undetectedGalaxies.append(mag) self.undetectedStar.set(raftId, ccdId, num.array(undetectedStars)) self.undetectedGalaxy.set(raftId, ccdId, num.array(undetectedGalaxies)) # Orphans orphans = [] for orphan in self.matchListDictSrc[key]['orphan']: if self.fluxType == "psf": f = orphan.getD(psfKey) else: f = orphan.getD(apKey) if f > 0.0: orphmag = -2.5 * num.log10(f) orphans.append(orphmag) if orphmag > self.faintest: self.faintest = orphmag self.orphan.set(raftId, ccdId, num.array(orphans)) ############ Calculate limiting mag maxDepth = self.limitingMag(raftId, ccdId) self.depth.set(raftId, ccdId, maxDepth) areaLabel = data.cameraInfo.getDetectorName(raftId, ccdId) label = "photometric depth " comment = "magnitude where star completeness drops below 0.5" test = testCode.Test(label, maxDepth, self.limits, comment, areaLabel=areaLabel) testSet.addTest(test)
def test(self, data, dataId): # get data self.matchListDictSrc = data.getMatchListBySensor(dataId, useRef='src') self.detector = data.getDetectorBySensor(dataId) self.filter = data.getFilterBySensor(dataId) #self.clusters = data.getSourceClusters(dataId) # compute the mean ra, dec for each source cluster self.dRa = raftCcdData.RaftCcdVector(self.detector) self.dDec = raftCcdData.RaftCcdVector(self.detector) self.x = raftCcdData.RaftCcdVector(self.detector) self.y = raftCcdData.RaftCcdVector(self.detector) self.sCatDummy = pqaSource.Catalog() sCatDummy = self.sCatDummy.catalog sCatSchema = sCatDummy.getSchema() self.srefCatDummy = pqaSource.RefCatalog() srefCatDummy = self.srefCatDummy.catalog srefCatSchema = srefCatDummy.getSchema() xKey = sCatSchema.find('XAstrom').key yKey = sCatSchema.find('YAstrom').key raKey = sCatSchema.find('Ra').key decKey = sCatSchema.find('Dec').key refRaKey = srefCatSchema.find('Ra').key refDecKey = srefCatSchema.find('Dec').key filter = None key = None for key in self.matchListDictSrc.keys(): raft = self.detector[key].getParent().getId().getName() ccd = self.detector[key].getId().getName() filter = self.filter[key].getName() matchList = self.matchListDictSrc[key]['matched'] for m in matchList: sref, s, dist = m ra, dec, raRef, decRef = \ [numpy.radians(x) for x in [s.getD(raKey), s.getD(decKey), \ sref.getD(refRaKey), sref.getD(refDecKey)]] dDec = decRef - dec dRa = (raRef - ra)*abs(numpy.cos(decRef)) intcen = s.getD(self.sCatDummy.FlagPixInterpCenKey) satcen = s.getD(self.sCatDummy.FlagPixSaturCenKey) edge = s.getD(self.sCatDummy.FlagPixEdgeKey) if data.cameraInfo.name == 'coadd': flagit = (satcen or edge) # coadds have excessive area covered by InterpCen flags else: flagit = (intcen or satcen or edge) if not (flagit): self.dRa.append(raft, ccd, dRa) self.dDec.append(raft, ccd, dDec) self.x.append(raft, ccd, s.getD(xKey)) self.y.append(raft, ccd, s.getD(yKey)) testSet = self.getTestSet(data, dataId) testSet.addMetadata({"Description": self.description}) self.medErrArcsec = raftCcdData.RaftCcdData(self.detector) self.medThetaRad = raftCcdData.RaftCcdData(self.detector) for raft, ccd in self.dRa.raftCcdKeys(): dRa = self.dRa.get(raft, ccd).copy() dDec = self.dDec.get(raft, ccd).copy() if len(dRa) > 0: dRaMed = numpy.median(dRa) dDecMed = numpy.median(dDec) else: dRaMed = 0.0 dDecMed = 0.0 sysErr = numpy.sqrt(dRaMed**2 + dDecMed**2)*afwGeom.radians sysErrArcsec = sysErr.asArcseconds() sysThetaRad = numpy.arctan2(dDecMed, dRaMed) dRa -= dRaMed dDec -= dDecMed rmsErr = numpy.sqrt(dRa**2 + dDec**2) rmsThetaRad = numpy.arctan2(dDec, dRa) if len(rmsErr) > 0: stat = afwMath.makeStatistics(rmsErr, afwMath.NPOINT | afwMath.MEDIAN) medRmsErr = stat.getValue(afwMath.MEDIAN) stat = afwMath.makeStatistics(rmsThetaRad, afwMath.NPOINT | afwMath.MEDIAN) medRmsThetaRad = stat.getValue(afwMath.MEDIAN) n = stat.getValue(afwMath.NPOINT) else: medRmsErr = -1.0 medRmsThetaRad = 0.0 n = 0 medRmsErr = medRmsErr*afwGeom.radians self.medErrArcsec.set(raft, ccd, sysErrArcsec) self.medThetaRad.set(raft, ccd, sysThetaRad) areaLabel = data.cameraInfo.getDetectorName(raft, ccd) label = "median systematic astrometry error " comment = "median sqrt(dRa^2+dDec^2) (arcsec, nstar=%d)" % (n) test = testCode.Test(label, sysErrArcsec, self.limits, comment, areaLabel=areaLabel) testSet.addTest(test) label = "median random astrometry error " comment = "median sqrt((dRa-dRaMed)^2+(dDec-dDecMed)^2) (arcsec, nstar=%d)" % (n) test = testCode.Test(label, medRmsErr.asArcseconds(), self.limits, comment, areaLabel=areaLabel) testSet.addTest(test)