-
Notifications
You must be signed in to change notification settings - Fork 14
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
Check that the gain is non-negative when setting the variance #47
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,30 @@ def testIllum2(self): | |
def testIllum3(self): | ||
self.doIllum(scaling=3.7) | ||
|
||
def testGainAndReadnoise(self): | ||
import lsst.afw.image as afwImage | ||
from lsst.afw.cameraGeom.testUtils import DetectorWrapper | ||
from lsst.ip.isr import IsrTask | ||
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. Why are there imports inside the test method? 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. There's no downside, but I'm happy to move them. That's probably the rule anyway (I should know) 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. Yes. As-is, this will fail flake8 (which you apparently aren't running?). 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. Imports have now been removed from the method and there are no flake8 violations |
||
|
||
isrTask = IsrTask() | ||
|
||
detector = DetectorWrapper().detector | ||
raw = afwImage.ExposureF(detector.getBBox()) | ||
|
||
level = 10 | ||
readNoise = 1 | ||
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. I was just made aware that |
||
raw.image.set(level) | ||
|
||
amp = detector[0] | ||
amp.setReadNoise(readNoise) | ||
|
||
for gain in [-1, 0, 0.1, 1]: | ||
amp.setGain(gain) | ||
isrTask.updateVariance(raw, amp) | ||
if gain <= 0: | ||
gain = 1 | ||
|
||
self.assertEqual(raw.variance.get(0, 0), level/gain + readNoise**2) | ||
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. I see three possible branches in the code you added: Separately, why are you doing 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. The line's indentation is incorrect; it should be in the loop. I'm not sure how this happened as I checked that the code failed when I reverted the fix. User error. I only need to check one pixel as they're all the same, so this is simpler and equivalent. 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.
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. What NaN case? I'm adding a test to check that we now handle gains <= 0, so I don't need to test all the pixels -- it wouldn't gain anything. And I don't understand your question about the readNoise. I'm adding a test that we handle an illegal value from the cameraGeom data, not a test to check that we handle variances correctly. I would like better test coverage for the IsrTask, but that should be calling the IsrTask, not internals. 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. The code itself has an Again, how do you know that all of the pixels are treated correctly unless you test them? The method you are testing is called 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. A value 1.5 is now used for read noise. A test for a NaN value of gain has been added. Concerning the question about testing all pixels, I agree with Robert that this is outside the scope of this unit test. This is a unit test for the handling of illegal values from the cameraGeom data, not the correct handling of variances. |
||
|
||
class MemoryTester(lsst.utils.tests.MemoryTestCase): | ||
pass | ||
|
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 not combine these lines as
if not math.isnan(gain) and gain <= 0:
?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.
Because the action on NaN and <= 0 is different.
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.
Oh, ok, I see it now, outside the changed code block.
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.
is there anything further to do on this?