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-10805: Spatially-varying ZOGY option #66
Conversation
djreiss
commented
Jun 6, 2017
- Include unit tests for new task
ffa12aa
to
fe07bf8
Compare
python/lsst/ip/diffim/zogy.py
Outdated
@@ -288,8 +319,8 @@ def computePrereqs(self, psf1=None, psf2=None, padSize=0): | |||
padSize = self.padSize if padSize is None else padSize | |||
Pr, Pn = psf1, psf2 | |||
if padSize > 0: | |||
Pr = ZogyTask._padPsfToSize(psf1, (padSize, padSize)) | |||
Pn = ZogyTask._padPsfToSize(psf2, (padSize, padSize)) | |||
Pr = ZogyTask._padPsfToSize(psf1, (psf1.shape[0]+padSize, psf1.shape[0]+padSize)) |
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.
Did you mean: (psf1.shape[0] + padSize, psf1.shape[1] + padSize)
or is there something special about the x
dimension. Please comment if so.
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.
This arose from a desire to force it to be square. However, that is enforced below, so I will update it here to avoid confusion.
python/lsst/ip/diffim/zogy.py
Outdated
results = task.run(scienceExposure, template=templateExposure, inImageSpace=inImageSpace, | ||
doScorr=doPreConvolve, forceEvenSized=True) | ||
results.D = results.exposure | ||
# The CoaddPsf apparently cannot be used for detection as it doesn't have a |
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 this comment about CoaddPsf still true?
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 don't think it was ever true. We have used CoaddPsf
for detection from its genesis.
If I'm wrong, please file a ticket on meas_algorithms.
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.
My understanding from looking at the code was that it computes a single psf from the averagePosition
and uses that for detection. But it is still a good point that the comment is untrue. I've updated the comment wrt my understanding on this.
python/lsst/ip/diffim/zogy.py
Outdated
def __init__(self, *args, **kwargs): | ||
ImagePsfMatchTask.__init__(self, *args, **kwargs) | ||
|
||
def setDefaults(self): |
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.
Does this function do anything? I thought only Configs run setDefaults
.
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.
Also, redundant, so removed.
python/lsst/ip/diffim/zogy.py
Outdated
|
||
# Make sure masks of input images are propagated to diffim | ||
mask = results.D.getMaskedImage().getMask() | ||
badBits = mask.getPlaneBitMask(['UNMASKEDNAN', 'NO_DATA', 'BAD', 'EDGE', 'SUSPECT', 'CR', 'SAT']) |
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.
badBits not used.
python/lsst/ip/diffim/zogy.py
Outdated
# Make sure masks of input images are propagated to diffim | ||
mask = results.D.getMaskedImage().getMask() | ||
badBits = mask.getPlaneBitMask(['UNMASKEDNAN', 'NO_DATA', 'BAD', 'EDGE', 'SUSPECT', 'CR', 'SAT']) | ||
badBitsNan = mask.getPlaneBitMask(['UNMASKEDNAN']) |
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.
See comment on jira ticket about UNMASKEDNAN. Not sure if calexps/coadds are guaranteed to have this. Check to see if this plane is present first before using it
python/lsst/ip/diffim/zogy.py
Outdated
def subtractExposures(self, templateExposure, scienceExposure, | ||
doWarping=True, spatiallyVarying=True, inImageSpace=False, | ||
doPreConvolve=False): | ||
|
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.
Needs docstring (esp. to make it clear that this function modifies the input exposures)
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 will surely add the docstring, and you are correct, the means of the input images are subtracted inplace, so I will note that.
python/lsst/ip/diffim/zogy.py
Outdated
destBBox=scienceExposure.getBBox()) | ||
|
||
templateExposure.setPsf(psfWarped) | ||
templateExposure.writeFits('WARPEDTEMPLATE_ZOGY.fits') |
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.
Tasks shouldn't write exposures to the current working directory. If you really need this, use the lsstDebug framework to tuck it in an if statement so that it only writes out if requested.
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.
Whoops, meant to remove that, thanks for catching it.
python/lsst/ip/diffim/zogy.py
Outdated
gm(results.D).getArray()[np.isnan(ga(scienceExposure))] |= badBitsNan | ||
gm(results.D).getArray()[np.isnan(ga(templateExposure))] |= badBitsNan | ||
|
||
#results = pipeBase.Struct(exposure=D) |
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.
Remove this line and 1074.
python/lsst/ip/diffim/zogy.py
Outdated
|
||
def gm(exp): | ||
return exp.getMaskedImage().getMask() | ||
def ga(exp): |
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.
- line between functions (even inner functions).
python/lsst/ip/diffim/zogy.py
Outdated
return exp.getMaskedImage().getMask() | ||
def ga(exp): | ||
return exp.getMaskedImage().getImage().getArray() | ||
def gv(exp): |
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.
gv is not used and is exactly the same as ga.
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.
Also, user convenience functions like these make the code harder to read. Please don't do this.
Also, with pybind11, you can write this as e.g. exp.maskedImage.mask
which might make this more palatable.
python/lsst/ip/diffim/zogy.py
Outdated
badBitsNan = mask.getPlaneBitMask(['UNMASKEDNAN']) | ||
mask |= gm(scienceExposure) | ||
mask |= gm(templateExposure) | ||
gm(results.D)[:, :] = mask |
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.
mask
here is a view (pointer) of results.D
's mask (i.e. the two lines before have already modified it) This line is unnecessary as it just copies itself to itself.
@@ -478,7 +516,8 @@ def _setNewPsf(self, exposure, psfArr): | |||
exposure.setPsf(psfNew) | |||
return exposure | |||
|
|||
def computeDiffim(self, inImageSpace=None, padSize=None, **kwargs): | |||
def computeDiffim(self, inImageSpace=None, padSize=None, | |||
returnMatchedTemplate=False, **kwargs): |
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.
Add returnMatchedTemplate to docstring.
python/lsst/ip/diffim/zogy.py
Outdated
def subtractMaskedImages(self, templateExposure, scienceExposure, | ||
doWarping=True, spatiallyVarying=True, inImageSpace=False, | ||
doPreConvolve=False): | ||
pass # not implemented |
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.
Consider if raise NotImplementedError
would be better here.
2708160
to
cb7132d
Compare
a6c487f
to
9e9d795
Compare
- Include unit tests for new task Fix issues pointed out by reviewer Attempt to fix padding issues Ensure an UNMASKEDNAN mask Fix PSF padding - Add unit test for different-sized PSFs - Add some documentation - Other fixes from review Add subtractAlgorithmRegistry Various docstring fixes Remove `subTask` from class/config names
9e9d795
to
09d7660
Compare