def run(display=False): exposure = loadData() schema = afwTable.SourceTable.makeMinimalSchema() # # Create the detection and measurement Tasks # config = SourceDetectionTask.ConfigClass() config.reEstimateBackground = False detectionTask = SourceDetectionTask(config=config, schema=schema) config = SingleFrameMeasurementTask.ConfigClass() # Use the minimum set of plugins required. config.plugins.names.clear() for plugin in [ "base_SdssCentroid", "base_SdssShape", "base_CircularApertureFlux", "base_PixelFlags" ]: config.plugins.names.add(plugin) config.plugins["base_CircularApertureFlux"].radii = [7.0] # Use of the PSF flux is hardcoded in secondMomentStarSelector config.slots.psfFlux = "base_CircularApertureFlux_7_0" measureTask = SingleFrameMeasurementTask(schema, config=config) # # Create the measurePsf task # config = MeasurePsfTask.ConfigClass() psfDeterminer = config.psfDeterminer.apply() psfDeterminer.config.sizeCellX = 128 psfDeterminer.config.sizeCellY = 128 psfDeterminer.config.spatialOrder = 1 psfDeterminer.config.nEigenComponents = 3 measurePsfTask = MeasurePsfTask(config=config, schema=schema) # # Create the output table # tab = afwTable.SourceTable.make(schema) # # Process the data # sources = detectionTask.run(tab, exposure, sigma=2).sources measureTask.measure(exposure, sources) result = measurePsfTask.run(exposure, sources) psf = result.psf cellSet = result.cellSet if display: # display on ds9 (see also --debug argparse option) frame = 1 ds9.mtv(exposure, frame=frame) with ds9.Buffering(): for s in sources: xy = s.getCentroid() ds9.dot('+', *xy, frame=frame) if s.get("calib.psf.candidate"): ds9.dot('x', *xy, ctype=ds9.YELLOW, frame=frame) if s.get("calib.psf.used"): ds9.dot('o', *xy, size=4, ctype=ds9.RED, frame=frame)
def run(display=False): exposure = loadData() schema = afwTable.SourceTable.makeMinimalSchema() # # Create the detection task # config = SourceDetectionTask.ConfigClass() config.thresholdPolarity = "both" config.background.isNanSafe = True config.thresholdValue = 3 detectionTask = SourceDetectionTask(config=config, schema=schema) # # And the measurement Task # config = SingleFrameMeasurementTask.ConfigClass() config.algorithms.names = ["base_SdssCentroid", "base_SdssShape", "base_CircularApertureFlux"] config.algorithms["base_CircularApertureFlux"].radii = [1, 2, 4, 8, 16] # pixels config.slots.instFlux = None config.slots.modelFlux = None config.slots.psfFlux = None algMetadata = dafBase.PropertyList() measureTask = SingleFrameMeasurementTask(schema, algMetadata=algMetadata, config=config) radii = algMetadata.get("base_CircularApertureFlux_radii") # # Create the output table # tab = afwTable.SourceTable.make(schema) # # Process the data # result = detectionTask.run(tab, exposure) sources = result.sources print("Found %d sources (%d +ve, %d -ve)" % (len(sources), result.fpSets.numPos, result.fpSets.numNeg)) measureTask.run(sources, exposure) if display: # display on ds9 (see also --debug argparse option) frame = 1 ds9.mtv(exposure, frame=frame) with ds9.Buffering(): for s in sources: xy = s.getCentroid() ds9.dot('+', *xy, ctype=ds9.CYAN if s.get("flags.negative") else ds9.GREEN, frame=frame) ds9.dot(s.getShape(), *xy, ctype=ds9.RED, frame=frame) for i in range(s.get("flux.aperture.nProfile")): ds9.dot('o', *xy, size=radii[i], ctype=ds9.YELLOW, frame=frame)
def run(args): exposure = loadData(args.image) if args.debug: ds9.mtv(exposure, frame=1) schema = afwTable.SourceTable.makeMinimalSchema() # Create the detection task config = SourceDetectionTask.ConfigClass() config.thresholdPolarity = "both" config.background.isNanSafe = True config.thresholdValue = 3 detectionTask = SourceDetectionTask(config=config, schema=schema) # And the measurement Task config = DipoleMeasurementTask.ConfigClass() config.plugins.names.remove('base_SkyCoord') algMetadata = dafBase.PropertyList() measureTask = DipoleMeasurementTask(schema, algMetadata, config=config) # Create the output table tab = afwTable.SourceTable.make(schema) # Process the data results = detectionTask.run(tab, exposure) # Merge the positve and negative sources fpSet = results.fpSets.positive growFootprint = 2 fpSet.merge(results.fpSets.negative, growFootprint, growFootprint, False) diaSources = afwTable.SourceCatalog(tab) fpSet.makeSources(diaSources) print("Merged %s Sources into %d diaSources (from %d +ve, %d -ve)" % (len(results.sources), len(diaSources), results.fpSets.numPos, results.fpSets.numNeg)) measureTask.run(diaSources, exposure) # Display dipoles if debug enabled if args.debug: dpa = DipoleAnalysis() dpa.displayDipoles(exposure, diaSources)
def testInclude(self): schema = afwTable.SourceTable.makeMinimalSchema() # Create the detection task config = SourceDetectionTask.ConfigClass() config.reEstimateBackground = False # Turn off so that background does not change from orig detectionTask = SourceDetectionTask(config=config, schema=schema) # Create the deblender Task debConfig = measDeb.SourceDeblendConfig() debTask = measDeb.SourceDeblendTask(schema, config=debConfig) # Create the measurement Task config = SingleFrameMeasurementTask.ConfigClass() measureTask = SingleFrameMeasurementTask(schema, config=config) # Create the output table tab = afwTable.SourceTable.make(schema) # Process the data result = detectionTask.run(tab, self.calexp) sources = result.sources # Run the deblender debTask.run(self.calexp, sources) # Run the measurement task: this where the replace-with-noise occurs measureTask.run(sources, self.calexp) plotOnFailure = False if display: plotOnFailure = True # The relative differences ranged from 0.02 to ~2. This rtol is somewhat # random, but will certainly catch the pathology if it occurs. self.assertFloatsAlmostEqual( self.calexpOrig.getMaskedImage().getImage().getArray(), self.calexp.getMaskedImage().getImage().getArray(), rtol=1E-3, printFailures=False, plotOnFailure=plotOnFailure)
def run(display=False): exposure = loadData() schema = afwTable.SourceTable.makeMinimalSchema() # # Create the detection task # config = SourceDetectionTask.ConfigClass() config.thresholdPolarity = "both" config.background.isNanSafe = True config.thresholdValue = 3 detectionTask = SourceDetectionTask(config=config, schema=schema) # # And the measurement Task # config = SingleFrameMeasurementTask.ConfigClass() config.algorithms.names = [ "base_SdssCentroid", "base_SdssShape", "base_CircularApertureFlux" ] config.algorithms["base_CircularApertureFlux"].radii = [ 1, 2, 4, 8, 12, 16 ] # pixels config.slots.gaussianFlux = None config.slots.modelFlux = None config.slots.psfFlux = None algMetadata = dafBase.PropertyList() measureTask = SingleFrameMeasurementTask(schema, algMetadata=algMetadata, config=config) radii = algMetadata.getArray("BASE_CIRCULARAPERTUREFLUX_RADII") # # Create the output table # tab = afwTable.SourceTable.make(schema) # # Process the data # result = detectionTask.run(tab, exposure) sources = result.sources print("Found %d sources (%d +ve, %d -ve)" % (len(sources), result.fpSets.numPos, result.fpSets.numNeg)) measureTask.run(sources, exposure) if display: # display image (see also --debug argparse option) afwDisplay.setDefaultMaskTransparency(75) frame = 1 disp = afwDisplay.Display(frame=frame) disp.mtv(exposure) with disp.Buffering(): for s in sources: xy = s.getCentroid() disp.dot('+', *xy, ctype=afwDisplay.CYAN if s.get("flags_negative") else afwDisplay.GREEN) disp.dot(s.getShape(), *xy, ctype=afwDisplay.RED) for radius in radii: disp.dot('o', *xy, size=radius, ctype=afwDisplay.YELLOW)
def run(display=False): exposure = loadData() schema = afwTable.SourceTable.makeMinimalSchema() # # Create the detection task # config = SourceDetectionTask.ConfigClass() config.thresholdPolarity = "both" config.background.isNanSafe = True config.thresholdValue = 3 detectionTask = SourceDetectionTask(config=config, schema=schema) # # And the measurement Task # config = SingleFrameMeasurementTask.ConfigClass() config.plugins.names.clear() for plugin in [ "base_SdssCentroid", "base_SdssShape", "base_CircularApertureFlux", "base_GaussianFlux" ]: config.plugins.names.add(plugin) config.slots.psfFlux = None config.slots.apFlux = "base_CircularApertureFlux_3_0" measureTask = SingleFrameMeasurementTask(schema, config=config) # # Print the schema the configuration produced # print schema # # Create the output table # tab = afwTable.SourceTable.make(schema) # # Process the data # result = detectionTask.run(tab, exposure) sources = result.sources print "Found %d sources (%d +ve, %d -ve)" % ( len(sources), result.fpSets.numPos, result.fpSets.numNeg) measureTask.run(sources, exposure) if display: # display on ds9 (see also --debug argparse option) frame = 1 ds9.mtv(exposure, frame=frame) with ds9.Buffering(): for s in sources: xy = s.getCentroid() ds9.dot( '+', *xy, ctype=ds9.CYAN if s.get("flags_negative") else ds9.GREEN, frame=frame) ds9.dot(s.getShape(), *xy, ctype=ds9.RED, frame=frame) ds9.dot( 'o', *xy, size=config.plugins["base_CircularApertureFlux"].radii[0], ctype=ds9.YELLOW, frame=frame)