Skip to content

Commit

Permalink
Respond to review
Browse files Browse the repository at this point in the history
Debug unittest
  • Loading branch information
morriscb committed Jun 22, 2020
1 parent 865c859 commit 13cac58
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
23 changes: 13 additions & 10 deletions python/lsst/ap/association/packageAlerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ def run(self,
self.alertSchema.store_alerts(f, alerts)

def _patchDiaSources(self, diaSources):
"""Add the ``programId`` column to the data and change currently
grouped alert data to ``None``.
"""Add the ``programId`` column to the data.
Parameters
----------
Expand Down Expand Up @@ -177,14 +176,14 @@ def createDiaSourceBBox(self, bboxSize):
bbox = geom.Extent2I(bboxSize, bboxSize)
return bbox

def createCcdDataCutout(self, cutout, sphPoint, photoCalib):
def createCcdDataCutout(self, cutout, skyCenter, photoCalib):
"""Convert a cutout into a calibrate CCDData image.
Parameters
----------
cutout : `lsst.afw.image.ExposureF`
Cutout to convert.
sphPoint : `lsst.geom.SpherePoint`
skyCenter : `lsst.geom.SpherePoint`
Center point of DiaSource on the sky.
photoCalib : `lsst.afw.image.PhotoCalib`
Calibrate object of the image the cutout is cut from.
Expand All @@ -195,20 +194,23 @@ def createCcdDataCutout(self, cutout, sphPoint, photoCalib):
CCDData object storing the calibrate information from the input
difference or template image.
"""
# Find the value of the bottom corner of our cutout's BBox and
# subtract 1 so that the CCDData cutout position value will be
# [1, 1].
cutOutMinX = cutout.getBBox().minX - 1
cutOutMinY = cutout.getBBox().minY - 1
center = cutout.getWcs().skyToPixel(sphPoint)
center = cutout.getWcs().skyToPixel(skyCenter)
calibCutout = photoCalib.calibrateImage(cutout.getMaskedImage())

cutoutWcs = wcs.WCS(naxis=2)
cutoutWcs.array_shape = (cutout.getBBox().getWidth(),
cutout.getBBox().getWidth())
cutoutWcs.wcs.crpix = [center.x - cutOutMinX, center.y - cutOutMinY]
cutoutWcs.wcs.crval = [sphPoint.getRa().asDegrees(),
sphPoint.getDec().asDegrees()]
cutoutWcs.wcs.crval = [skyCenter.getRa().asDegrees(),
skyCenter.getDec().asDegrees()]
cutoutWcs.wcs.cd = self.makeLocalTransformMatrix(cutout.getWcs(),
center,
sphPoint)
skyCenter)

return CCDData(
data=calibCutout.getImage().array,
Expand All @@ -226,7 +228,7 @@ def makeLocalTransformMatrix(self, wcs, center, skyCenter):
The approximation is created as if the center is at RA=0, DEC=0. All
comparing x,y coordinate are relative to the position of center. Matrix
is initially calculated with units arcseconds and then converted to
radians. This yields higher precision results due to quirks in AST.
degrees. This yields higher precision results due to quirks in AST.
Parameters
----------
Expand All @@ -243,8 +245,9 @@ def makeLocalTransformMatrix(self, wcs, center, skyCenter):
Matrix representation the local wcs approximation with units
degrees.
"""
blankCDMatrix = [[self._scale, 0], [0, self._scale]]
localGnomonicWcs = afwGeom.makeSkyWcs(
center, skyCenter, [[self._scale, 0], [0, self._scale]])
center, skyCenter, blankCDMatrix)
measurementToLocalGnomonic = wcs.getTransform().then(
localGnomonicWcs.getTransform().inverted()
)
Expand Down
19 changes: 11 additions & 8 deletions tests/test_packageAlerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _roundTripThroughApdb(objects, sources, dateTime):
return (diaObjects, diaSources)


class TestPackageAlerts(unittest.TestCase):
class TestPackageAlerts(lsst.utils.tests.TestCase):

def setUp(self):
np.random.seed(1234)
Expand Down Expand Up @@ -312,10 +312,10 @@ def testCreateCcdDataCutout(self):
calibExposure = self.exposure.getPhotoCalib().calibrateImage(
self.exposure.getMaskedImage())

self.assertTrue(np.allclose(ccdData.wcs.wcs.cd,
self.cutoutWcs.wcs.cd))
self.assertTrue(np.allclose(ccdData.data,
calibExposure.getImage().array))
self.assertFloatsAlmostEqual(ccdData.wcs.wcs.cd,
self.cutoutWcs.wcs.cd)
self.assertFloatsAlmostEqual(ccdData.data,
calibExposure.getImage().array)

def testMakeLocalTransformMatrix(self):
"""Test that the local WCS approximation is correct.
Expand All @@ -328,7 +328,11 @@ def testMakeLocalTransformMatrix(self):
self.cutoutSize))
cd = packageAlerts.makeLocalTransformMatrix(
cutout.getWcs(), self.center, sphPoint)
self.assertTrue(np.allclose(cd, cutout.getWcs().getCdMatrix()))
self.assertFloatsAlmostEqual(
cd,
cutout.getWcs().getCdMatrix(),
rtol=1e-11,
atol=1e-11)

def testStreamCcdDataToBytes(self):
"""Test round tripping an CCDData cutout to bytes and back.
Expand All @@ -347,8 +351,7 @@ def testStreamCcdDataToBytes(self):
cutoutBytes = packageAlerts.streamCcdDataToBytes(cutoutCcdData)
with io.BytesIO(cutoutBytes) as bytesIO:
cutoutFromBytes = CCDData.read(bytesIO, format="fits")
self.assertTrue(
np.allclose(cutoutCcdData.data, cutoutFromBytes.data))
self.assertFloatsAlmostEqual(cutoutCcdData.data, cutoutFromBytes.data)

def testMakeAlertDict(self):
"""Test stripping data from the various data products and into a
Expand Down

0 comments on commit 13cac58

Please sign in to comment.