-
Notifications
You must be signed in to change notification settings - Fork 1
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-43490: Put correct size to PixelGrid for PSF estimation #25
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bd41624
Make default value for chiLim float
arunkannawadi cc64e28
Add blank lines around match-case
arunkannawadi a73eb3c
Define and pass modelSize for PIFF
arunkannawadi 9331323
Adjust stampSize default based on modelSize
arunkannawadi 0e6b0d5
Add validate method to piffPsfDeterminer
arunkannawadi a5ba125
Move WCS making logic to a separate function
arunkannawadi 66a0829
Update setupDeterminer in the tests
arunkannawadi b9cabd9
Bump chiLim to 6.4 from 6.1 in the unit tests
arunkannawadi fc666c0
Add test method for sky coordinates
arunkannawadi d0b86e8
Conditionally skip the failing 45 degree test
arunkannawadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
from lsst.meas.base import SingleFrameMeasurementTask | ||
from lsst.meas.extensions.piff.piffPsfDeterminer import PiffPsfDeterminerConfig, PiffPsfDeterminerTask | ||
from lsst.meas.extensions.piff.piffPsfDeterminer import _validateGalsimInterpolant | ||
from packaging import version | ||
|
||
|
||
def psfVal(ix, iy, x, y, sigma1, sigma2, b): | ||
|
@@ -55,6 +56,41 @@ def psfVal(ix, iy, x, y, sigma1, sigma2, b): | |
+ b*np.exp(-0.5*(u**2 + (v*ab)**2)/sigma2**2))/(1 + b) | ||
|
||
|
||
def make_wcs(angle_degrees=None): | ||
"""Make a simple SkyWcs that is rotated around the origin. | ||
|
||
Parameters | ||
---------- | ||
angle_degrees : `float`, optional | ||
The angle to rotate the WCS by, in degrees. | ||
|
||
Returns | ||
------- | ||
wcs : `~lsst.afw.geom.SkyWcs` | ||
The WCS object. | ||
""" | ||
cdMatrix = np.array([ | ||
[1.0, 0.0], | ||
[0.0, 1.0] | ||
]) * 0.2 / 3600 | ||
|
||
if angle_degrees is not None: | ||
angle_radians = np.radians(angle_degrees) | ||
cosang = np.cos(angle_radians) | ||
sinang = np.sin(angle_radians) | ||
rot = np.array([ | ||
[cosang, -sinang], | ||
[sinang, cosang] | ||
]) | ||
cdMatrix = np.dot(cdMatrix, rot) | ||
|
||
return afwGeom.makeSkyWcs( | ||
crpix=geom.PointD(0, 0), | ||
crval=geom.SpherePoint(0.0, 0.0, geom.degrees), | ||
cdMatrix=cdMatrix, | ||
) | ||
|
||
|
||
class SpatialModelPsfTestCase(lsst.utils.tests.TestCase): | ||
"""A test case for SpatialModelPsf""" | ||
|
||
|
@@ -101,11 +137,7 @@ def setUp(self): | |
self.exposure = afwImage.makeExposure(self.mi) | ||
self.exposure.setPsf(measAlg.DoubleGaussianPsf(self.ksize, self.ksize, | ||
1.5*sigma1, 1, 0.1)) | ||
cdMatrix = np.array([1.0, 0.0, 0.0, 1.0]) * 0.2/3600 | ||
cdMatrix.shape = (2, 2) | ||
wcs = afwGeom.makeSkyWcs(crpix=geom.PointD(0, 0), | ||
crval=geom.SpherePoint(0.0, 0.0, geom.degrees), | ||
cdMatrix=cdMatrix) | ||
wcs = make_wcs() | ||
self.exposure.setWcs(wcs) | ||
|
||
# | ||
|
@@ -193,6 +225,8 @@ def setUp(self): | |
def setupDeterminer( | ||
self, | ||
stampSize=None, | ||
kernelSize=None, | ||
modelSize=25, | ||
debugStarData=False, | ||
useCoordinates='pixel', | ||
downsample=False, | ||
|
@@ -204,6 +238,19 @@ def setupDeterminer( | |
---------- | ||
stampSize : `int`, optional | ||
Set ``config.stampSize`` to this, if not None. | ||
kernelSize : `int`, optional | ||
Cutout size for the PSF candidates. This is unused if ``stampSize`` | ||
if provided and its value is used for cutout size instead. | ||
modelSize : `int`, optional | ||
Internal model size for PIFF. | ||
debugStarData : `bool`, optional | ||
Include star images used for fitting in PSF model object? | ||
useCoordinates : `str`, optional | ||
Spatial coordinates to regress against for PSF modelling. | ||
downsample : `bool`, optional | ||
Whether to downsample the PSF candidates before modelling? | ||
withlog : `bool`, optional | ||
Should Piff produce chatty log messages? | ||
""" | ||
starSelectorClass = measAlg.sourceSelectorRegistry["objectSize"] | ||
starSelectorConfig = starSelectorClass.ConfigClass() | ||
|
@@ -220,14 +267,18 @@ def setupDeterminer( | |
self.starSelector = starSelectorClass(config=starSelectorConfig) | ||
|
||
makePsfCandidatesConfig = measAlg.MakePsfCandidatesTask.ConfigClass() | ||
if kernelSize: | ||
makePsfCandidatesConfig.kernelSize = kernelSize | ||
if stampSize is not None: | ||
makePsfCandidatesConfig.kernelSize = stampSize | ||
|
||
self.makePsfCandidates = measAlg.MakePsfCandidatesTask(config=makePsfCandidatesConfig) | ||
|
||
psfDeterminerConfig = PiffPsfDeterminerConfig() | ||
psfDeterminerConfig.spatialOrder = 1 | ||
if stampSize is not None: | ||
psfDeterminerConfig.stampSize = stampSize | ||
psfDeterminerConfig.stampSize = stampSize | ||
psfDeterminerConfig.modelSize = modelSize | ||
|
||
psfDeterminerConfig.debugStarData = debugStarData | ||
psfDeterminerConfig.useCoordinates = useCoordinates | ||
if downsample: | ||
|
@@ -237,7 +288,7 @@ def setupDeterminer( | |
|
||
self.psfDeterminer = PiffPsfDeterminerTask(psfDeterminerConfig) | ||
|
||
def subtractStars(self, exposure, catalog, chi_lim=-1): | ||
def subtractStars(self, exposure, catalog, chi_lim=-1.): | ||
"""Subtract the exposure's PSF from all the sources in catalog""" | ||
mi, psf = exposure.getMaskedImage(), exposure.getPsf() | ||
|
||
|
@@ -307,7 +358,7 @@ def checkPiffDeterminer(self, **kwargs): | |
chiLim = 7.0 | ||
else: | ||
numAvail = len(psfCandidateList) | ||
chiLim = 6.1 | ||
chiLim = 6.4 | ||
|
||
self.assertEqual(metadata['numAvailStars'], numAvail) | ||
self.assertEqual(sum(self.catalog['use_psf']), metadata['numGoodStars']) | ||
|
@@ -385,10 +436,6 @@ def testPiffDeterminer_debugStarData(self): | |
"""Test Piff with debugStarData=True.""" | ||
self.checkPiffDeterminer(debugStarData=True) | ||
|
||
def testPiffDeterminer_skyCoords(self): | ||
"""Test Piff sky coords.""" | ||
self.checkPiffDeterminer(useCoordinates='sky') | ||
|
||
def testPiffDeterminer_downsample(self): | ||
"""Test Piff determiner with downsampling.""" | ||
self.checkPiffDeterminer(downsample=True) | ||
|
@@ -397,6 +444,47 @@ def testPiffDeterminer_withlog(self): | |
"""Test Piff determiner with chatty logs.""" | ||
self.checkPiffDeterminer(withlog=True) | ||
|
||
def testPiffDeterminer_stampSize26(self): | ||
"""Test Piff with a psf stampSize of 26.""" | ||
with self.assertRaises(ValueError): | ||
self.checkPiffDeterminer(stampSize=26) | ||
|
||
def testPiffDeterminer_modelSize26(self): | ||
"""Test Piff with a psf stampSize of 26.""" | ||
with self.assertRaises(ValueError): | ||
self.checkPiffDeterminer(modelSize=26, stampSize=25) | ||
|
||
def testPiffDeterminer_skyCoords(self): | ||
"""Test Piff sky coords.""" | ||
|
||
self.checkPiffDeterminer(useCoordinates='sky') | ||
|
||
@lsst.utils.tests.methodParameters(angle_degrees=[0, 35, 77, 135]) | ||
def testPiffDeterminer_skyCoords_with_rotation(self, angle_degrees): | ||
"""Test Piff sky coords with rotation.""" | ||
|
||
wcs = make_wcs(angle_degrees=angle_degrees) | ||
self.exposure.setWcs(wcs) | ||
self.checkPiffDeterminer(useCoordinates='sky', kernelSize=35) | ||
|
||
# TODO: Merge this case with the above in DM-44467. | ||
@unittest.skipUnless(version.parse(galsim.version) >= version.parse("2.5.2"), | ||
reason="Requires GalSim >= 2.5.2", | ||
) | ||
def testPiffDeterminer_skyCoords_rot45(self): | ||
"""Test Piff sky coords.""" | ||
|
||
wcs = make_wcs(angle_degrees=45) | ||
self.exposure.setWcs(wcs) | ||
self.checkPiffDeterminer(useCoordinates='sky', kernelSize=35) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @timj Strictly speaking, this would get merged without ever being run on our CI systems. Should I include it, or add a note to add this test case in a later ticket? |
||
|
||
def testPiffDeterminer_skyCoords_failure(self, angle_degrees=135): | ||
"""Test that using small PSF candidates with sky coordinates fails.""" | ||
wcs = make_wcs(angle_degrees=angle_degrees) | ||
self.exposure.setWcs(wcs) | ||
with self.assertRaises(ValueError): | ||
self.checkPiffDeterminer(useCoordinates='sky', stampSize=15) | ||
|
||
|
||
class PiffConfigTestCase(lsst.utils.tests.TestCase): | ||
"""A test case to check for valid Piff config""" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this switched from 6.1 to 6.4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@esheldon increased it to 6.5 and I found 6.4 was sufficient for tests to pass. Do you have an intuition as to why the increase was necessary with the rotations, Erin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was probably just noise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be. I don't think there was any first-principle motivation for
chiLim = 6.1
in the first place, just a value chosen empirically.Thresholds in
pipelines_check
repo have to be changed only after announcing/asking the entire Science Pipelines team, but these ones can be changed by a reasonable amount.