def setUp(self): # Load sample input from disk testDir = os.path.dirname(__file__) self.srcCat = afwTable.SourceCatalog.readFits( os.path.join(testDir, "data", "v695833-e0-c000.xy.fits")) self.srcCat["slot_ApFlux_fluxSigma"] = 1 self.srcCat["slot_PsfFlux_fluxSigma"] = 1 # The .xy.fits file has sources in the range ~ [0,2000],[0,4500] # which is bigger than the exposure self.bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(2048, 4612)) smallExposure = afwImage.ExposureF( os.path.join(testDir, "data", "v695833-e0-c000-a00.sci.fits")) self.exposure = afwImage.ExposureF(self.bbox) self.exposure.setWcs(smallExposure.getWcs()) self.exposure.setFilter(smallExposure.getFilter()) self.exposure.setCalib(smallExposure.getCalib()) # Make a reference loader butler = Butler(RefCatDir) self.refObjLoader = LoadIndexedReferenceObjectsTask(butler=butler) logLevel = Log.TRACE self.log = Log.getLogger('testPhotoCal') self.log.setLevel(logLevel) self.config = PhotoCalConfig() # The test and associated data have been prepared on the basis that we # use the PsfFlux to perform photometry. self.config.fluxField = "base_PsfFlux_flux"
def setUp(self): # Load sample input from disk testDir = os.path.dirname(__file__) self.srcCat = afwTable.SourceCatalog.readFits( os.path.join(testDir, "data", "v695833-e0-c000.xy.fits")) self.srcCat["slot_ApFlux_instFluxErr"] = 1 self.srcCat["slot_PsfFlux_instFluxErr"] = 1 # The .xy.fits file has sources in the range ~ [0,2000],[0,4500] # which is bigger than the exposure self.bbox = geom.Box2I(geom.Point2I(0, 0), geom.Extent2I(2048, 4612)) smallExposure = afwImage.ExposureF( os.path.join(testDir, "data", "v695833-e0-c000-a00.sci.fits")) self.exposure = afwImage.ExposureF(self.bbox) self.exposure.setWcs(smallExposure.getWcs()) self.exposure.setFilter( afwImage.FilterLabel(band="i", physical="test-i")) self.exposure.setPhotoCalib(smallExposure.getPhotoCalib()) coordKey = self.srcCat.getCoordKey() centroidKey = self.srcCat.getCentroidSlot().getMeasKey() wcs = self.exposure.getWcs() for src in self.srcCat: src.set(coordKey, wcs.pixelToSky(src.get(centroidKey))) # Make a reference loader filenames = sorted( glob.glob( os.path.join(RefCatDir, 'ref_cats', 'cal_ref_cat', '??????.fits'))) self.refObjLoader = MockReferenceObjectLoaderFromFiles(filenames, htmLevel=8) self.log = logging.getLogger('lsst.testPhotoCal') self.log.setLevel(TRACE) self.config = PhotoCalConfig() self.config.match.matchRadius = 0.5 self.config.match.referenceSelection.doMagLimit = True self.config.match.referenceSelection.magLimit.maximum = 22.0 self.config.match.referenceSelection.magLimit.fluxField = "i_flux" self.config.match.referenceSelection.doFlags = True self.config.match.referenceSelection.flags.good = ['photometric'] self.config.match.referenceSelection.flags.bad = ['resolved'] self.config.match.sourceSelection.doUnresolved = False # Don't have star/galaxy in the srcCat # The test and associated data have been prepared on the basis that we # use the PsfFlux to perform photometry. self.config.fluxField = "base_PsfFlux_instFlux"
def setUp(self): # Load sample input from disk testDir = os.path.dirname(__file__) self.srcCat = afwTable.SourceCatalog.readFits( os.path.join(testDir, "data", "v695833-e0-c000.xy.fits")) self.srcCat["slot_ApFlux_fluxSigma"] = 1 self.srcCat["slot_PsfFlux_fluxSigma"] = 1 # The .xy.fits file has sources in the range ~ [0,2000],[0,4500] # which is bigger than the exposure self.bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(2048, 4612)) smallExposure = afwImage.ExposureF( os.path.join(testDir, "data", "v695833-e0-c000-a00.sci.fits")) self.exposure = afwImage.ExposureF(self.bbox) self.exposure.setWcs(smallExposure.getWcs()) self.exposure.setFilter(smallExposure.getFilter()) self.exposure.setCalib(smallExposure.getCalib()) coordKey = self.srcCat.getCoordKey() centroidKey = self.srcCat.getCentroidKey() wcs = self.exposure.getWcs() for src in self.srcCat: src.set(coordKey, wcs.pixelToSky(src.get(centroidKey))) # Make a reference loader butler = Butler(RefCatDir) self.refObjLoader = LoadIndexedReferenceObjectsTask(butler=butler) logLevel = Log.TRACE self.log = Log.getLogger('testPhotoCal') self.log.setLevel(logLevel) self.config = PhotoCalConfig() self.config.match.matchRadius = 0.5 self.config.match.referenceSelection.doMagLimit = True self.config.match.referenceSelection.magLimit.maximum = 22.0 self.config.match.referenceSelection.magLimit.fluxField = "i_flux" self.config.match.referenceSelection.doFlags = True self.config.match.referenceSelection.flags.good = ['photometric'] self.config.match.referenceSelection.flags.bad = ['resolved'] self.config.match.sourceSelection.doUnresolved = False # Don't have star/galaxy in the srcCat # The test and associated data have been prepared on the basis that we # use the PsfFlux to perform photometry. self.config.fluxField = "base_PsfFlux_flux"
def test1(self): res = self.getAstrometrySolution() matches = res.matches print 'Test1' logLevel = Log.DEBUG log = Log(Log.getDefaultLog(), 'testPhotoCal', logLevel) schema = matches[0].second.schema config = PhotoCalConfig() # The test and associated data have been prepared on the basis that we # use the PsfFlux to perform photometry. config.fluxField = "base_PsfFlux_flux" config.doWriteOutput = False # schema is fixed because we already loaded the data task = PhotoCalTask(config=config, schema=schema) pCal = task.run(exposure=self.exposure, matches=matches) print "Ref flux fields list =", pCal.arrays.refFluxFieldList refFluxField = pCal.arrays.refFluxFieldList[0] # These are *all* the matches; we don't really expect to do that well. diff=[] for m in matches: refFlux = m[0].get(refFluxField) # reference catalog flux if refFlux <= 0: continue refMag = afwImage.abMagFromFlux(refFlux) # reference catalog mag instFlux = m[1].getPsfFlux() #Instrumental Flux if instFlux <= 0: continue instMag = pCal.calib.getMagnitude(instFlux) #Instrumental mag diff.append(instMag - refMag) diff = np.array(diff) self.assertGreater(len(diff), 50) log.info('%i magnitude differences; mean difference %g; mean abs diff %g' % (len(diff), np.mean(diff), np.mean(np.abs(diff)))) self.assertLess(np.mean(diff), 0.6) # Differences of matched objects that were used in the fit. zp = pCal.calib.getMagnitude(1.) log.logdebug('zeropoint: %g' % zp) fitdiff = pCal.arrays.srcMag + zp - pCal.arrays.refMag log.logdebug('number of sources used in fit: %i' % len(fitdiff)) log.logdebug('rms diff: %g' % np.mean(fitdiff**2)**0.5) log.logdebug('median abs(diff): %g' % np.median(np.abs(fitdiff))) # zeropoint: 31.3145 # number of sources used in fit: 65 # median diff: -0.009681 # mean diff: 0.00331871 # median abs(diff): 0.0368904 # mean abs(diff): 0.0516589 self.assertLess(abs(zp - 31.3145), 0.05) self.assertGreater(len(fitdiff), 50) # Tolerances are somewhat arbitrary; they're set simply to avoid regressions, and # are not based on we'd expect to get given the data quality. self.assertLess(np.mean(fitdiff**2)**0.5, 0.07) # rms difference self.assertLess(np.median(np.abs(fitdiff)), 0.06) # median absolution difference
def test1(self): res = self.getAstrometrySolution() matches = res.matches print 'Test1' logLevel = Log.DEBUG log = Log(Log.getDefaultLog(), 'testPhotoCal', logLevel) schema = matches[0].second.schema config = PhotoCalConfig() # The test and associated data have been prepared on the basis that we # use the PsfFlux to perform photometry. config.fluxField = "base_PsfFlux_flux" config.doWriteOutput = False # schema is fixed because we already loaded the data task = PhotoCalTask(config=config, schema=schema) pCal = task.run(exposure=self.exposure, matches=matches) print "Ref flux fields list =", pCal.arrays.refFluxFieldList refFluxField = pCal.arrays.refFluxFieldList[0] # These are *all* the matches; we don't really expect to do that well. diff = [] for m in matches: refFlux = m[0].get(refFluxField) # reference catalog flux if refFlux <= 0: continue refMag = afwImage.abMagFromFlux(refFlux) # reference catalog mag instFlux = m[1].getPsfFlux() #Instrumental Flux if instFlux <= 0: continue instMag = pCal.calib.getMagnitude(instFlux) #Instrumental mag diff.append(instMag - refMag) diff = np.array(diff) self.assertGreater(len(diff), 50) log.info( '%i magnitude differences; mean difference %g; mean abs diff %g' % (len(diff), np.mean(diff), np.mean(np.abs(diff)))) self.assertLess(np.mean(diff), 0.6) # Differences of matched objects that were used in the fit. zp = pCal.calib.getMagnitude(1.) log.logdebug('zeropoint: %g' % zp) fitdiff = pCal.arrays.srcMag + zp - pCal.arrays.refMag log.logdebug('number of sources used in fit: %i' % len(fitdiff)) log.logdebug('rms diff: %g' % np.mean(fitdiff**2)**0.5) log.logdebug('median abs(diff): %g' % np.median(np.abs(fitdiff))) # zeropoint: 31.3145 # number of sources used in fit: 65 # median diff: -0.009681 # mean diff: 0.00331871 # median abs(diff): 0.0368904 # mean abs(diff): 0.0516589 self.assertLess(abs(zp - 31.3145), 0.05) self.assertGreater(len(fitdiff), 50) # Tolerances are somewhat arbitrary; they're set simply to avoid regressions, and # are not based on we'd expect to get given the data quality. self.assertLess(np.mean(fitdiff**2)**0.5, 0.07) # rms difference self.assertLess(np.median(np.abs(fitdiff)), 0.06) # median absolution difference