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-24325: Include CCDData cutouts in alert packets #89

Merged
merged 4 commits into from Jun 22, 2020

Conversation

morriscb
Copy link
Contributor

No description provided.

Copy link
Contributor

@isullivan isullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern was what looks like a mismatch between crpix and crval in createCcdDataCutout, but maybe I am missing something. If the current implementation is correct, please add a comment to explain it.

I also made a couple comments about code in the file that was not touched by your changes. That could be outside the scope of this ticket, but if it's not too much trouble to address them please do so.

@@ -106,6 +113,7 @@ def run(self,
self._patchDiaSources(diaSourceCat)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not part of your changes, but it doesn't look like template or ccdExposureIdBits are used anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually will so I'm going to leave it for now.

diffIm.getCutout(sphPoint, cutoutBBox),
sphPoint,
diffImPhotoCalib)

templateCutout = None
# TODO: Create alertIds DM-24858
alertId = diaSource["diaSourceId"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not part of your changes, but I don't see how _patchDiaSources below changes the "currently grouped alert data to None" as the documentation says.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Should have been removed in a previous ticket but was not.

CCDData object storing the calibrate information from the input
difference or template image.
"""
cutOutMinX = cutout.getBBox().minX - 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining the additional -1 here.

cutoutWcs = wcs.WCS(naxis=2)
cutoutWcs.array_shape = (cutout.getBBox().getWidth(),
cutout.getBBox().getWidth())
cutoutWcs.wcs.crpix = [center.x - cutOutMinX, center.y - cutOutMinY]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the crpix at the corner rather than the center of the cutout?

Copy link
Contributor Author

@morriscb morriscb Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, CCDData doesn't store absolute pixel locations. So when you create a dataset with it the "bottom left" pixel is always [1, 1]. Thus we center the crpix such that it's correctly within this newly shifted cutout and at the location of the DiaSource in the cutout. There is a possible future feature in astropy to add an origin to the CCDData object but it is currently not a priority.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "not a priority" is right for them but if we want to add that feature they seem like they would be more than happy to accept a patch. We have been in discussion for years to add pixel origin to NDData.

cutout.getBBox().getWidth())
cutoutWcs.wcs.crpix = [center.x - cutOutMinX, center.y - cutOutMinY]
cutoutWcs.wcs.crval = [sphPoint.getRa().asDegrees(),
sphPoint.getDec().asDegrees()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this crval actually for the center of the bbox?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the center of the DiaSource, see above.

@@ -165,6 +177,80 @@ def createDiaSourceBBox(self, bboxSize):
bbox = geom.Extent2I(bboxSize, bboxSize)
return bbox

def createCcdDataCutout(self, cutout, sphPoint, photoCalib):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel sphPoint describes the data type more than what the parameter is. Maybe something like centerPoint instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to skyCenter

degrees.
"""
localGnomonicWcs = afwGeom.makeSkyWcs(
center, skyCenter, [[self._scale, 0], [0, self._scale]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be more readable if you first defined a variable such as cdMatrix = [[self._scale, 0], [0, self._scale]] and then used that here.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"converted to radians". Do you mean "converted to degrees"?

calibExposure = self.exposure.getPhotoCalib().calibrateImage(
self.exposure.getMaskedImage())

self.assertTrue(np.allclose(ccdData.wcs.wcs.cd,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think self.assertFloatsAlmostEqual(ccdData.wcs.wcs.cd, self.cutoutWcs.wcs.cd) might give more informative error messages if the test fails. The downside is you would have to have TestPackageAlerts inherit from lsst.utils.tests.TestCase instead of unittest.TestCase.

If you end up switching the assert here, also change the other self.assertTrue(np.allclose(... throughout this file.

Debug unittest

Fix linting
Copy link
Contributor

@isullivan isullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the changes and the additional explanation. This looks good to me.

@morriscb morriscb merged commit 4ff2924 into master Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants