Skip to content

Commit

Permalink
Merge pull request #546 from lsst/tickets/DM-26651
Browse files Browse the repository at this point in the history
DM-26651: Persist individual bright stars' warping Transforms, origin and number of rotations
  • Loading branch information
MorganSchmitz committed Jul 1, 2021
2 parents 77f2033 + 3353954 commit 1a9a513
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions python/lsst/pipe/tasks/processBrightStars.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,21 @@ def warpStamps(self, stamps, pixCenters):
Returns
-------
warpedStars : `list` [`afwImage.maskedImage.maskedImage.MaskedImage`]
result : `lsst.pipe.base.Struct`
Result struct with components:
- ``warpedStars``:
`list` [`afwImage.maskedImage.maskedImage.MaskedImage`] of
stamps of warped stars
- ``warpTransforms``:
`list` [`afwGeom.TransformPoint2ToPoint2`] of
the corresponding Transform from the initial star stamp to
the common model grid
- ``xy0s``:
`list` [`geom.Point2I`] of coordinates of the bottom-left
pixels of each stamp, before rotation
- ``nb90Rots``: `int`, the number of 90 degrees rotations required
to compensate for detector orientation
"""
# warping control; only contains shiftingALg provided in config
warpCont = afwMath.WarpingControl(self.config.warpingKernelName)
Expand All @@ -375,7 +389,7 @@ def warpStamps(self, stamps, pixCenters):
nb90Rots = np.argmin(np.abs(possibleRots - float(yaw)))

# apply transformation to each star
warpedStars = []
warpedStars, warpTransforms, xy0s = [], [], []
for star, cent in zip(stamps, pixCenters):
# (re)create empty destination image
destImage = afwImage.MaskedImageF(*self.modelStampSize)
Expand All @@ -385,8 +399,9 @@ def warpStamps(self, stamps, pixCenters):
newBottomLeft.setY(newBottomLeft.getY() - bufferPix[1]/2)
# Convert to int
newBottomLeft = geom.Point2I(newBottomLeft)
# Set origin
# Set origin and save it
destImage.setXY0(newBottomLeft)
xy0s.append(newBottomLeft)

# Define linear shifting to recenter stamps
newCenter = pixToTan.applyForward(cent) # center of warped star
Expand All @@ -407,11 +422,13 @@ def warpStamps(self, stamps, pixCenters):
# Arbitrarily set origin of shifted star to 0
destImage.setXY0(0, 0)

# Apply rotation if apropriate
# Apply rotation if appropriate
if nb90Rots:
destImage = afwMath.rotateImageBy90(destImage, nb90Rots)
warpedStars.append(destImage.clone())
return warpedStars
warpTransforms.append(starWarper)
return pipeBase.Struct(warpedStars=warpedStars, warpTransforms=warpTransforms, xy0s=xy0s,
nb90Rots=nb90Rots)

@pipeBase.timeMethod
def run(self, inputExposure, refObjLoader=None, dataId=None, skyCorr=None):
Expand Down Expand Up @@ -454,11 +471,16 @@ def run(self, inputExposure, refObjLoader=None, dataId=None, skyCorr=None):
# Warp (and shift, and potentially rotate) them
self.log.info("Applying warp and/or shift to %i star stamps from exposure %s",
len(extractedStamps.starIms), dataId)
warpedStars = self.warpStamps(extractedStamps.starIms, extractedStamps.pixCenters)
warpOutputs = self.warpStamps(extractedStamps.starIms, extractedStamps.pixCenters)
warpedStars = warpOutputs.warpedStars
xy0s = warpOutputs.xy0s
brightStarList = [bSS.BrightStarStamp(stamp_im=warp,
archive_element=transform,
position=xy0s[j],
gaiaGMag=extractedStamps.GMags[j],
gaiaId=extractedStamps.gaiaIds[j])
for j, warp in enumerate(warpedStars)]
for j, (warp, transform) in
enumerate(zip(warpedStars, warpOutputs.warpTransforms))]
# Compute annularFlux and normalize
self.log.info("Computing annular flux and normalizing %i bright stars from exposure %s",
len(warpedStars), dataId)
Expand All @@ -471,7 +493,9 @@ def run(self, inputExposure, refObjLoader=None, dataId=None, skyCorr=None):
brightStarStamps = bSS.BrightStarStamps.initAndNormalize(brightStarList,
innerRadius=innerRadius,
outerRadius=outerRadius,
nb90Rots=warpOutputs.nb90Rots,
imCenter=self.modelCenter,
use_archive=True,
statsControl=statsControl,
statsFlag=statsFlag,
badMaskPlanes=self.config.badMaskPlanes,
Expand Down

0 comments on commit 1a9a513

Please sign in to comment.