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

fix variance calculation to use masks #26

Merged
merged 1 commit into from Jul 26, 2016
Merged

fix variance calculation to use masks #26

merged 1 commit into from Jul 26, 2016

Conversation

djreiss
Copy link
Contributor

@djreiss djreiss commented Jul 21, 2016

fix normalization of correction kernel
remove commented print statements
add coordinate parameters to run for testing
update test for stricter tolerance after bug fix
turn on old ClassificationDipole again
add options to DecorrelateALKerneltask.run()
change all sig**2 to variance
Fix mixup of var1 and var2 for science and template

@@ -130,19 +129,28 @@ def __init__(self, *args, **kwargs):
"NO_DATA", "DETECTED_NEGATIVE"]))

@pipeBase.timeMethod
def run(self, templateExposure, exposure, subtractedExposure, psfMatchingKernel):
def run(self, exposure, templateExposure, subtractedExposure, psfMatchingKernel,
xcen=None, ycen=None, var1=None, var2=None):
"""! Perform decorrelation of an image difference exposure.
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be handy to note in the docstring that exposure, template match equation whatever in some paper.

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 not in a paper, yet. But I will reference the (still in progress) DMTN-021 with those details.

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 the reference. Thanks. Maybe I_1 and I_2 should be I_s and I_t in DMTN-021, to make it explicit?

(to within a 1% tolerance).
"""

def _testImages(self):
# Create the matching kernel. We used Gaussian PSFs for im1 and im2, so we can compute the "expected"
Copy link
Contributor

Choose a reason for hiding this comment

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

Though it's a "private" method, it would be good to have a short docstring here that says what gets tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

@parejkoj
Copy link
Contributor

Few things, besides the specific comments I had on lines (some of which are expanded on below):

  • You can replace your singleGaussian2d() with astropy.modeling's Gaussian2D as follows (check that it doesn't break anything). Plus, since it's an object, you can instantiate it once and just call it in the loop as needed, which will make the intention of that loop clearer.
x,y = np.meshgrid(np.linspace(blah), np.linspace(blah))
someGaussian2d = astropy.modeling.functional_models.Gaussian2D(1,0,2,1,2,np.pi/4)
someGaussian2d(x,y)
  • Please double-check your linter config: a few off-standard lines have slipped through (not necessarily in the reviewed lines).
  • If you pull those staticmethods out to top level functions, you can then easily write a unittest for each, to help ensure they're e.g. padding how you want them to.
  • I probably shouldn't be surprised that afw.math.makeStatistics doesn't have a non-verbose way to get a variance, mean, etc. from a maskedImage. Given that, you can cut out a lot of code duplication by writing a top level imageDecorrelation functions to return the clipped-mean variance of a MaskedImage, and maybe another for one of the other statistics you're always computing.
  • Your tests would be more robust if you better quantified what the test was (e.g. var-expected_var > 10 or var-expected_var < 10), since assertNotClose covers quite a broad range of possibilities.

(to within a 1% tolerance).
"""
self._setUpImages(var1=0.04, var2=0.08)
self._testImages()


def suite():
Copy link
Contributor

Choose a reason for hiding this comment

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

TestSuite is dead: long live py.test! See SQR-012 and the developer docs for more details:

https://sqr-012.lsst.io/
https://developer.lsst.io/coding/python_testing.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, converted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks.

fix normalization of correction kernel
remove commented print statements
add coordinate parameters to `run` for testing
update test for stricter tolerance after bug fix
turn on old ClassificationDipole again
add options to DecorrelateALKerneltask.run()
change all sig**2 to variance
Fix mixup of var1 and var2 for science and template
Rename var1 to svar and var2 to tvar
Improvements to unit tests
Other improvements thanks to code review
@djreiss djreiss merged commit 840e2db into master Jul 26, 2016
@ktlim ktlim deleted the tickets/DM-6580 branch August 25, 2018 06:44
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