def _runTask(self): """All the common setup to actually test the results""" task = PhotoCalTask(self.refObjLoader, config=self.config, schema=self.srcCat.schema) pCal = task.run(exposure=self.exposure, sourceCat=self.srcCat) matches = pCal.matches 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 = u.Quantity(refFlux, u.nJy).to_value(u.ABmag) instFlux = m[1].getPsfInstFlux() # Instrumental Flux if instFlux <= 0: continue instMag = pCal.photoCalib.instFluxToMagnitude( instFlux) # Instrumental mag diff.append(instMag - refMag) self.diff = np.array(diff) # Differences of matched objects that were used in the fit. self.zp = pCal.photoCalib.instFluxToMagnitude(1.) self.fitdiff = pCal.arrays.srcMag + self.zp - pCal.arrays.refMag
def run(): exposure, srcCat = loadData() schema = srcCat.getSchema() # # Create the astrometry task # config = AstrometryTask.ConfigClass() config.refObjLoader.filterMap = {"_unknown_": "r"} config.matcher.sourceFluxType = "Psf" # sample catalog does not contain aperture flux aTask = AstrometryTask(config=config) # # And the photometry Task # config = PhotoCalTask.ConfigClass() config.applyColorTerms = False # we don't have any available, so this suppresses a warning pTask = PhotoCalTask(config=config, schema=schema) # # The tasks may have added extra elements to the schema (e.g. AstrometryTask's centroidKey to # handle distortion; photometryTask's config.outputField). If this is so, we need to add # these columns to the Source table. # # We wouldn't need to do this if we created the schema prior to measuring the exposure, # but in this case we read the sources from disk # if schema != srcCat.getSchema(): # the tasks added fields print("Adding columns to the source catalogue") cat = afwTable.SourceCatalog(schema) cat.table.defineCentroid(srcCat.table.getCentroidDefinition()) cat.table.definePsfFlux(srcCat.table.getPsfFluxDefinition()) scm = afwTable.SchemaMapper(srcCat.getSchema(), schema) for schEl in srcCat.getSchema(): scm.addMapping(schEl.getKey(), True) cat.extend(srcCat, True, scm) # copy srcCat to cat, adding new columns srcCat = cat del cat # # Process the data # matches = aTask.run(exposure, srcCat).matches result = pTask.run(exposure, matches) calib = result.calib fm0, fm0Err = calib.getFluxMag0() print("Used %d calibration sources out of %d matches" % (len(result.matches), len(matches))) delta = result.arrays.refMag - result.arrays.srcMag q25, q75 = np.percentile(delta, [25, 75]) print("RMS error is %.3fmmsg (robust %.3f, Calib says %.3f)" % (np.std(delta), 0.741 * (q75 - q25), 2.5 / np.log(10) * fm0Err / fm0))
def run(): exposure, srcCat = loadData() schema = srcCat.getSchema() # # Create the astrometry task # config = measAstrom.LoadAstrometryNetObjectsTask.ConfigClass() config.filterMap = {"_unknown_": "r"} refObjLoader = measAstrom.LoadAstrometryNetObjectsTask(config=config) config = measAstrom.AstrometryTask.ConfigClass() config.matcher.sourceFluxType = "Psf" # sample catalog does not contain aperture flux aTask = measAstrom.AstrometryTask(config=config, refObjLoader=refObjLoader) # # And the photometry Task # config = PhotoCalTask.ConfigClass() config.applyColorTerms = False # we don't have any available, so this suppresses a warning pTask = PhotoCalTask(config=config, schema=schema) # # The tasks may have added extra elements to the schema (e.g. AstrometryTask's centroidKey to # handle distortion; photometryTask's config.outputField). If this is so, we need to add # these columns to the Source table. # # We wouldn't need to do this if we created the schema prior to measuring the exposure, # but in this case we read the sources from disk # if schema != srcCat.getSchema(): # the tasks added fields print("Adding columns to the source catalogue") cat = afwTable.SourceCatalog(schema) cat.table.defineCentroid(srcCat.table.getCentroidDefinition()) cat.table.definePsfFlux(srcCat.table.getPsfFluxDefinition()) scm = afwTable.SchemaMapper(srcCat.getSchema(), schema) for schEl in srcCat.getSchema(): scm.addMapping(schEl.getKey(), True) cat.extend(srcCat, True, scm) # copy srcCat to cat, adding new columns srcCat = cat; del cat # # Process the data # matches = aTask.run(exposure, srcCat).matches result = pTask.run(exposure, matches) calib = result.calib fm0, fm0Err = calib.getFluxMag0() print("Used %d calibration sources out of %d matches" % (len(result.matches), len(matches))) delta = result.arrays.refMag - result.arrays.srcMag q25, q75 = np.percentile(delta, [25, 75]) print("RMS error is %.3fmmsg (robust %.3f, Calib says %.3f)" % (np.std(delta), 0.741*(q75 - q25), 2.5/np.log(10)*fm0Err/fm0))
def testFlags(self): """test that all the calib_photometry flags are set to reasonable values""" schema = self.srcCat.schema task = PhotoCalTask(self.refObjLoader, config=self.config, schema=schema) mapper = afwTable.SchemaMapper(self.srcCat.schema, schema) cat = afwTable.SourceCatalog(schema) for name in self.srcCat.schema.getNames(): mapper.addMapping(self.srcCat.schema.find(name).key) cat.extend(self.srcCat, mapper=mapper) # test that by default, no stars are reserved and all used are candidates task.run(exposure=self.exposure, sourceCat=cat) used = 0 for source in cat: if source.get("calib_photometry_used"): used += 1 self.assertFalse(source.get("calib_photometry_reserved")) # test that some are actually used self.assertGreater(used, 0)
def _runTask(self): """All the common setup to actually test the results""" task = PhotoCalTask(self.refObjLoader, config=self.config, schema=self.srcCat.schema) pCal = task.run(exposure=self.exposure, sourceCat=self.srcCat) matches = pCal.matches 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 = u.Quantity(refFlux, u.nJy).to_value(u.ABmag) instFlux = m[1].getPsfInstFlux() # Instrumental Flux if instFlux <= 0: continue instMag = pCal.photoCalib.instFluxToMagnitude(instFlux) # Instrumental mag diff.append(instMag - refMag) self.diff = np.array(diff) # Differences of matched objects that were used in the fit. self.zp = pCal.photoCalib.instFluxToMagnitude(1.) self.fitdiff = pCal.arrays.srcMag + self.zp - pCal.arrays.refMag
def _runTask(self): """All the common setup to actually test the results""" task = PhotoCalTask(self.refObjLoader, config=self.config, schema=None) pCal = task.run(exposure=self.exposure, sourceCat=self.srcCat) matches = pCal.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) self.diff = np.array(diff) # Differences of matched objects that were used in the fit. self.zp = pCal.calib.getMagnitude(1.) self.fitdiff = pCal.arrays.srcMag + self.zp - pCal.arrays.refMag
def testFlags(self): """test that all the calib_photometry flags are set to reasonable values""" schema = self.srcCat.schema task = PhotoCalTask(self.refObjLoader, config=self.config, schema=schema) mapper = afwTable.SchemaMapper(self.srcCat.schema, schema) cat = afwTable.SourceCatalog(schema) for name in self.srcCat.schema.getNames(): mapper.addMapping(self.srcCat.schema.find(name).key) cat.extend(self.srcCat, mapper=mapper) # test that by default, no stars are reserved and used < candidates task.run(exposure=self.exposure, sourceCat=cat) candidates = 0 used = 0 reserved = 0 for source in cat: if source.get("calib_photometryCandidate"): candidates += 1 if source.get("calib_photometryUsed"): used += 1 if source.get("calib_photometryReserved"): reserved += 1 self.assertLessEqual(used, candidates) self.assertEqual(reserved, 0) # set the reserve fraction, and see if the right proportion are reserved. self.config.reserveFraction = .3 task.run(exposure=self.exposure, sourceCat=cat) candidates = 0 reserved = 0 used = 0 for source in cat: if source.get("calib_photometryCandidate"): candidates += 1 if source.get("calib_photometryUsed"): used += 1 if source.get("calib_photometryReserved"): reserved += 1 self.assertEqual(reserved, int(.3 * candidates)) self.assertLessEqual(used, (candidates - reserved))
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
def run(): exposure, srcCat = loadData() schema = srcCat.getSchema() # # Create the reference catalog loader # refCatDir = os.path.join(lsst.utils.getPackageDir('meas_astrom'), 'tests', 'data', 'sdssrefcat') butler = Butler(refCatDir) refObjLoader = LoadIndexedReferenceObjectsTask(butler=butler) # # Create the astrometry task # config = AstrometryTask.ConfigClass() config.matcher.sourceFluxType = "Psf" # sample catalog does not contain aperture flux config.matcher.minSnr = 0 # disable S/N test because sample catalog does not contain flux sigma aTask = AstrometryTask(config=config, refObjLoader=refObjLoader) # # And the photometry Task # config = PhotoCalTask.ConfigClass() config.applyColorTerms = False # we don't have any available, so this suppresses a warning # The associated data has been prepared on the basis that we use PsfFlux to perform photometry. config.fluxField = "base_PsfFlux_flux" pTask = PhotoCalTask(config=config, schema=schema) # # The tasks may have added extra elements to the schema (e.g. AstrometryTask's centroidKey to # handle distortion; photometryTask's config.outputField). If this is so, we need to add # these columns to the Source table. # # We wouldn't need to do this if we created the schema prior to measuring the exposure, # but in this case we read the sources from disk # if schema != srcCat.getSchema(): # the tasks added fields print("Adding columns to the source catalogue") cat = afwTable.SourceCatalog(schema) cat.table.defineCentroid(srcCat.table.getCentroidDefinition()) cat.table.definePsfFlux(srcCat.table.getPsfFluxDefinition()) scm = afwTable.SchemaMapper(srcCat.getSchema(), schema) for schEl in srcCat.getSchema(): scm.addMapping(schEl.getKey(), True) cat.extend(srcCat, True, scm) # copy srcCat to cat, adding new columns srcCat = cat del cat # # Process the data # matches = aTask.run(exposure, srcCat).matches result = pTask.run(exposure, matches) calib = result.calib fm0, fm0Err = calib.getFluxMag0() print("Used %d calibration sources out of %d matches" % (len(result.matches), len(matches))) delta = result.arrays.refMag - result.arrays.srcMag q25, q75 = np.percentile(delta, [25, 75]) print("RMS error is %.3fmmsg (robust %.3f, Calib says %.3f)" % (np.std(delta), 0.741 * (q75 - q25), 2.5 / np.log(10) * fm0Err / fm0))