Exemplo n.º 1
0
    def measureAndNormalize(
        self,
        annulus,
        statsControl=afwMath.StatisticsControl(),
        statsFlag=afwMath.stringToStatisticsProperty("MEAN"),
        badMaskPlanes=('BAD', 'SAT', 'NO_DATA')):
        """Compute "annularFlux", the integrated flux within an annulus
        around an object's center, and normalize it.

        Since the center of bright stars are saturated and/or heavily affected
        by ghosts, we measure their flux in an annulus with a large enough
        inner radius to avoid the most severe ghosts and contain enough
        non-saturated pixels.

        Parameters
        ----------
        annulus : `lsst.afw.geom.spanSet.SpanSet`
            SpanSet containing the annulus to use for normalization.
        statsControl : `lsst.afw.math.statistics.StatisticsControl`, optional
            StatisticsControl to be used when computing flux over all pixels
            within the annulus.
        statsFlag : `lsst.afw.math.statistics.Property`, optional
            statsFlag to be passed on to ``afwMath.makeStatistics`` to compute
            annularFlux. Defaults to a simple MEAN.
        badMaskPlanes : `collections.abc.Collection` [`str`]
            Collection of mask planes to ignore when computing annularFlux.
        """
        stampSize = self.stamp_im.getDimensions()
        # create image with the same pixel values within annulus, NO_DATA
        # elsewhere
        maskPlaneDict = self.stamp_im.mask.getMaskPlaneDict()
        annulusImage = MaskedImageF(stampSize, planeDict=maskPlaneDict)
        annulusMask = annulusImage.mask
        annulusMask.array[:] = 2**maskPlaneDict['NO_DATA']
        annulus.copyMaskedImage(self.stamp_im, annulusImage)
        # set mask planes to be ignored
        andMask = reduce(ior, (annulusMask.getPlaneBitMask(bm)
                               for bm in badMaskPlanes))
        statsControl.setAndMask(andMask)
        # compute annularFlux
        annulusStat = afwMath.makeStatistics(annulusImage, statsFlag,
                                             statsControl)
        self.annularFlux = annulusStat.getValue()
        if np.isnan(self.annularFlux):
            raise RuntimeError(
                "Annular flux computation failed, likely because no pixels were valid."
            )
        # normalize stamps
        self.stamp_im.image.array /= self.annularFlux
        return None
Exemplo n.º 2
0
 def setUp(self):
     np.random.seed(1)
     self.spans = SpanSet.fromShape(2, Stencil.CIRCLE)
     self.footprint = Footprint(self.spans)
     self.footprint.addPeak(3, 4, 10)
     self.footprint.addPeak(8, 1, 2)
     fp = Footprint(self.spans)
     for peak in self.footprint.getPeaks():
         fp.addPeak(peak["f_x"], peak["f_y"], peak["peakValue"])
     self.peaks = fp.getPeaks()
     self.bbox = self.footprint.getBBox()
     self.filters = ("G", "R", "I")
     singles = []
     images = []
     for n, f in enumerate(self.filters):
         image = ImageF(self.spans.getBBox())
         image.set(n)
         images.append(image.array)
         maskedImage = MaskedImageF(image)
         heavy = makeHeavyFootprint(self.footprint, maskedImage)
         singles.append(heavy)
     self.image = np.array(images)
     self.mFoot = MultibandFootprint(self.filters, singles)
Exemplo n.º 3
0
import lsst.utils
from lsst.afw.image import MaskedImageF
from lsst.pipe.tasks.exampleStatsTasks import ExampleSimpleStatsTask, ExampleSigmaClippedStatsTask

# Parse command-line arguments. If the user supplies an image, use it;
# otherwise use one from the afwdata package (or complain if afwdata is not setup).
if len(sys.argv) < 2:
    afwDataDir = lsst.utils.getPackageDir('afwdata')
    maskedImagePath = os.path.join(afwDataDir, "data", "med.fits")
else:
    maskedImagePath = sys.argv[1]
print("computing statistics on %r\n" % (maskedImagePath, ))

# Read the masked image from the specified file. The file may be a masked image or exposure,
# but if the file is a simple image, with no mask or variance plane, then this call will fail.
maskedImage = MaskedImageF(maskedImagePath)

# Construct the simple stats task configuration and use that to construct and run the task
print("running ExampleSimpleStatsTask")
config1 = ExampleSimpleStatsTask.ConfigClass()
# ...modify the config if desired...
config1.validate(
)  # check that the config parameters are valid; optional, but catches errors early
task1 = ExampleSimpleStatsTask(config=config1)
res1 = task1.run(maskedImage)
print("result  =", res1)
print()

# Construct the sigma-clipped stats task configuration and use that to construct and run the task
print("running ExampleSigmaClippedStatsTask")
config2 = ExampleSigmaClippedStatsTask.ConfigClass()