Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-26651: Persist individual bright stars' warping Transforms, origin and number of rotations #546

Merged
merged 3 commits into from
Jul 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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