Skip to content

Commit

Permalink
Merge branch 'tickets/DM-45709'
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenam committed Aug 21, 2024
2 parents 5c9cb89 + d78f4a7 commit 76fe02a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/lsst/ip/diffim/computeSpatiallySampledMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def _evaluateLocalMetric(self, src, science, matchedTemplate, template, differen
bbox.grow(metricRegionSize)
bbox = bbox.clippedTo(science.getBBox())
nPix = bbox.getArea()
pixScale = science.wcs.getPixelScale()
pixScale = science.wcs.getPixelScale(bbox.getCenter())
area = nPix*pixScale.asDegrees()**2
peak = src.getFootprint().getPeaks()[0]
src.set('x', peak['i_x'])
Expand Down
22 changes: 16 additions & 6 deletions python/lsst/ip/diffim/dcrModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def wcs(self):
Returns
-------
bbox : `lsst.afw.geom.SkyWcs`
wcs : `lsst.afw.geom.SkyWcs`
Coordinate system definition (wcs) for the exposure.
"""
return self._wcs
Expand Down Expand Up @@ -403,7 +403,7 @@ def buildMatchedTemplate(self, exposure=None, order=3,
if bbox is None:
bbox = self.bbox
dcrShift = calculateDcr(visitInfo, self.wcs, self.effectiveWavelength, self.bandwidth, len(self),
splitSubfilters=splitSubfilters)
splitSubfilters=splitSubfilters, bbox=bbox)
templateImage = afwImage.ImageF(bbox)
refModel = None
for subfilter, dcr in enumerate(dcrShift):
Expand Down Expand Up @@ -729,7 +729,8 @@ def applyDcr(image, dcr, useInverse=False, splitSubfilters=False, splitThreshold
return shiftedImage


def calculateDcr(visitInfo, wcs, effectiveWavelength, bandwidth, dcrNumSubfilters, splitSubfilters=False):
def calculateDcr(visitInfo, wcs, effectiveWavelength, bandwidth, dcrNumSubfilters, splitSubfilters=False,
bbox=None):
"""Calculate the shift in pixels of an exposure due to DCR.
Parameters
Expand All @@ -747,6 +748,10 @@ def calculateDcr(visitInfo, wcs, effectiveWavelength, bandwidth, dcrNumSubfilter
splitSubfilters : `bool`, optional
Calculate DCR for two evenly-spaced wavelengths in each subfilter,
instead of at the midpoint. Default: False
bbox : `lsst.afw.geom.Box2I`, optional
Bounding box for the region of interest for evaluating the local
pixelScale (defaults to the Sky Origin of the ``wcs`` provided if
``bbox`` is None).
Returns
-------
Expand All @@ -768,17 +773,22 @@ def calculateDcr(visitInfo, wcs, effectiveWavelength, bandwidth, dcrNumSubfilter
elevation=visitInfo.getBoresightAzAlt().getLatitude(),
observatory=visitInfo.getObservatory(),
weather=visitInfo.getWeather())
if bbox is not None:
pixelScale = wcs.getPixelScale(bbox.getCenter()).asArcseconds()
else:
pixelScale = wcs.getPixelScale().asArcseconds()

if splitSubfilters:
diffRefractPix0 = diffRefractAmp0.asArcseconds()/wcs.getPixelScale().asArcseconds()
diffRefractPix1 = diffRefractAmp1.asArcseconds()/wcs.getPixelScale().asArcseconds()
diffRefractPix0 = diffRefractAmp0.asArcseconds()/pixelScale
diffRefractPix1 = diffRefractAmp1.asArcseconds()/pixelScale
diffRefractArr = [diffRefractPix0*weight[0] + diffRefractPix1*weight[1],
diffRefractPix0*weight[1] + diffRefractPix1*weight[0]]
shiftX = [diffRefractPix*np.sin(rotation.asRadians()) for diffRefractPix in diffRefractArr]
shiftY = [diffRefractPix*np.cos(rotation.asRadians()) for diffRefractPix in diffRefractArr]
dcrShift.append(((shiftY[0], shiftX[0]), (shiftY[1], shiftX[1])))
else:
diffRefractAmp = (diffRefractAmp0 + diffRefractAmp1)/2.
diffRefractPix = diffRefractAmp.asArcseconds()/wcs.getPixelScale().asArcseconds()
diffRefractPix = diffRefractAmp.asArcseconds()/pixelScale
shiftX = diffRefractPix*np.sin(rotation.asRadians())
shiftY = diffRefractPix*np.cos(rotation.asRadians())
dcrShift.append((shiftY, shiftX))
Expand Down

0 comments on commit 76fe02a

Please sign in to comment.