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

Check that the gain is non-negative when setting the variance #47

Merged
merged 2 commits into from Feb 2, 2018

Conversation

RobertLuptonTheGood
Copy link
Member

No description provided.

Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

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

There's no unittest for this case: this seems like an ideal situation for a unittest to demonstrate pre and post behavior.

if not math.isnan(amp.getGain()):
gain = amp.getGain()
if not math.isnan(gain):
if gain <= 0:
Copy link
Contributor

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:?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member

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?

@RobertLuptonTheGood RobertLuptonTheGood merged commit 2ffccc9 into master Feb 2, 2018
@parejkoj
Copy link
Contributor

parejkoj commented Feb 2, 2018

Um, I hadn't approved this yet. I was writing some comments about your unittest... How did you even manage to merge it with a red change marker in place?

@RobertLuptonTheGood
Copy link
Member Author

RobertLuptonTheGood commented Feb 2, 2018 via email

@parejkoj
Copy link
Contributor

parejkoj commented Feb 2, 2018

I had neither marked this PR as approved, nor marked the original ticket as Reviewed.

@RobertLuptonTheGood
Copy link
Member Author

RobertLuptonTheGood commented Feb 3, 2018 via email

Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

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

Your unittest only covers one case, and you have imports inside it.

if not math.isnan(amp.getGain()):
gain = amp.getGain()
if not math.isnan(gain):
if gain <= 0:
Copy link
Contributor

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.

def testGainAndReadnoise(self):
import lsst.afw.image as afwImage
from lsst.afw.cameraGeom.testUtils import DetectorWrapper
from lsst.ip.isr import IsrTask
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are there imports inside the test method?

Copy link
Member Author

Choose a reason for hiding this comment

The 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)

Copy link
Contributor

Choose a reason for hiding this comment

The 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?).

Copy link
Member

Choose a reason for hiding this comment

The 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

if gain <= 0:
gain = 1

self.assertEqual(raw.variance.get(0, 0), level/gain + readNoise**2)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see three possible branches in the code you added: gain is nan, gain <= 0, and gain > 0. There is only one assert here, so it can only test one of those branches.

Separately, why are you doing raw.variance.get(0, 0), instead of checking all values of raw.variance?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. That still doesn't test the nan case.

  2. How do you know the code is treating all the pixels correctly unless you actually test all the pixels?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

The code itself has an if isnan(gain), which means that we need a test case for gain being NaN.

Again, how do you know that all of the pixels are treated correctly unless you test them?

The method you are testing is called updateVariance. There is a term related to readNoise**2. 1 doesn't give you much information when you square it.

Copy link
Member

@leannep leannep Sep 13, 2019

Choose a reason for hiding this comment

The 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.

raw = afwImage.ExposureF(detector.getBBox())

level = 10
readNoise = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

I was just made aware that readNoise=1 is not helpful, given the definition of variance below...

@leannep
Copy link
Member

leannep commented Sep 12, 2019

@parejkoj Some of your comments have been address by @RobertLuptonTheGood - could you please resolve the conversations where that is the case. Could you also please summarise what you want to see to merge this PR

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