595 def apply(self, catalog, exposure):
596 """Apply the mask plane requirements to a catalog.
597
598 Returns whether the sources were selected.
599
600 Parameters
601 ----------
602 catalog : `lsst.afw.table.SourceCatalog` or `pandas.DataFrame`
603 or `astropy.table.Table`
604 Catalog of sources to which the requirements will be applied.
605 exposure : `lsst.afw.image.Exposure` or None
606 The exposure whose mask plane is to be respected.
607
608
609 Returns
610 -------
611 selected : `numpy.ndarray`
612 Boolean array indicating for each source whether it is selected
613 (True means selected).
614
615 Raises
616 ------
617 RuntimeError
618 Raised if exposure passed is `None`.
619 """
620 if exposure is None:
621 raise RuntimeError("Must provide an exposure to CullFromMaskedRegion selection.")
622 xRefList = catalog[self.xColName]
623 yRefList = catalog[self.yColName]
624
625
626
627 x0, y0 = exposure.getXY0()
628 xMax, yMax = exposure.getDimensions()
629 xRefList = [int(min(max(0, xRef - x0), xMax - 1)) for xRef in xRefList]
630 yRefList = [int(min(max(0, yRef - y0), yMax - 1)) for yRef in yRefList]
631 badMaskNames = []
632 maskPlaneDict = exposure.getMask().getMaskPlaneDict()
633 for badName in self.badMaskNames:
634 if badName in maskPlaneDict:
635 badMaskNames.append(badName)
636 bitmask = exposure.mask.getPlaneBitMask(badMaskNames)
637 toKeep = ((exposure.mask.array & bitmask) == 0)
638 selected = toKeep[yRefList, xRefList]
639
640 return selected
641
642