Skip to content

Commit

Permalink
Extract stars on, or slightly beyond, exposure edge
Browse files Browse the repository at this point in the history
  • Loading branch information
MorganSchmitz committed Jan 28, 2021
1 parent cbd0928 commit 19782b1
Showing 1 changed file with 45 additions and 11 deletions.
56 changes: 45 additions & 11 deletions python/lsst/pipe/tasks/processBrightStars.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import lsst.pex.config as pexConfig
from lsst.pipe import base as pipeBase
from lsst.pipe.base import connectionTypes as cT
from lsst.pex.exceptions import InvalidParameterError
from lsst.meas.algorithms.loadIndexedReferenceObjects import LoadIndexedReferenceObjectsTask
from lsst.meas.algorithms import ReferenceObjectLoader
from lsst.meas.algorithms import brightStarStamps as bSS
Expand Down Expand Up @@ -127,6 +128,12 @@ class ProcessBrightStarsConfig(pipeBase.PipelineTaskConfig,
" annular flux.",
default=('BAD', 'CR', 'CROSSTALK', 'EDGE', 'NO_DATA', 'SAT', 'SUSPECT', 'UNMASKEDNAN')
)
minPixelsWithinFrame = pexConfig.Field(
dtype=int,
doc="When a bright star is beyond exposure boundary, what is the minimal number of pixels that still "
"fall within the stamp required for it to be saved",
default=50
)
refObjLoader = pexConfig.ConfigurableField(
target=LoadIndexedReferenceObjectsTask,
doc="reference object loader for astrometric calibration",
Expand Down Expand Up @@ -207,8 +214,12 @@ def extractStamps(self, inputExposure, refObjLoader=None):
GMags = []
ids = []
wcs = inputExposure.getWcs()
# select stars within input exposure from refcat
withinCalexp = refObjLoader.loadPixelBox(inputExposure.getBBox(), wcs, filterName="phot_g_mean")
bmp = inputExposure.mask.getMaskPlaneDict()
# select stars within, or close enough to input exposure from refcat
inputExpBBox = inputExposure.getBBox()
dilatationExtent = geom.Extent2I(np.array(self.config.stampSize) - self.config.minPixelsWithinFrame)
withinCalexp = refObjLoader.loadPixelBox(inputExpBBox.dilatedBy(dilatationExtent), wcs,
filterName="phot_g_mean")
refCat = withinCalexp.refCat
# keep bright objects
fluxLimit = ((self.config.magLimit*u.ABmag).to(u.nJy)).to_value()
Expand All @@ -221,15 +232,38 @@ def extractStamps(self, inputExposure, refObjLoader=None):
for j, (ra, dec) in enumerate(zip(selectedColumns["coord_ra"], selectedColumns["coord_dec"])):
sp = geom.SpherePoint(ra, dec, geom.radians)
cpix = wcs.skyToPixel(sp)
# TODO: DM-25894 keep objects on or slightly beyond CCD edge
if (cpix[0] >= self.config.stampSize[0]/2
and cpix[0] < inputExposure.getDimensions()[0] - self.config.stampSize[0]/2
and cpix[1] >= self.config.stampSize[1]/2
and cpix[1] < inputExposure.getDimensions()[1] - self.config.stampSize[1]/2):
starIms.append(inputExposure.getCutout(sp, geom.Extent2I(self.config.stampSize)))
pixCenters.append(cpix)
GMags.append(allGMags[j])
ids.append(allIds[j])
try:
starIm = inputExposure.getCutout(sp, geom.Extent2I(self.config.stampSize))
except InvalidParameterError:
# star is beyond boundary
bboxCorner = np.array(cpix) - np.array(self.config.stampSize)/2
bboxCorner = geom.Point2I(bboxCorner)
# compute bbox as it would be otherwise
idealBBox = geom.Box2I(geom.Point2I(bboxCorner), geom.Extent2I(self.config.stampSize))
bottomLeft = idealBBox.getBegin()
topRight = idealBBox.getEnd()
# can any pixel be salvaged?
if np.any(np.array(bottomLeft) >= np.array(inputExposure.getDimensions())) or \
np.any(np.array(topRight) <= 0):
continue
subBBox = geom.Box2I(idealBBox)
subBBox.clip(inputExpBBox)
# extract pixels if any
subSp = wcs.pixelToSky(subBBox.getCenter())
subStarIm = inputExposure.getCutout(subSp, subBBox.getDimensions())
# and create full-sized stamp with NO_DATA elsewhere
starIm = afwImage.ExposureF(idealBBox)
starIm.image.array[:] = np.nan
starIm.mask.array[:] = 2**bmp['NO_DATA']
starIm.image[subBBox] = subStarIm.image
starIm.mask[subBBox] = subStarIm.mask
# set detector and wcs, used in warpStars
starIm.setDetector(inputExposure.getDetector())
starIm.setWcs(inputExposure.getWcs())
starIms.append(starIm)
pixCenters.append(cpix)
GMags.append(allGMags[j])
ids.append(allIds[j])
return pipeBase.Struct(starIms=starIms,
pixCenters=pixCenters,
GMags=GMags,
Expand Down

0 comments on commit 19782b1

Please sign in to comment.