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

DM-10805: Spatially-varying ZOGY option #66

Merged
merged 1 commit into from Aug 28, 2017
Merged

Conversation

djreiss
Copy link
Contributor

@djreiss djreiss commented Jun 6, 2017

  • Include unit tests for new task

@@ -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))
Copy link
Contributor

@yalsayyad yalsayyad Jul 5, 2017

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.

Copy link
Contributor Author

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.

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
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

@djreiss djreiss Jul 7, 2017

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.

def __init__(self, *args, **kwargs):
ImagePsfMatchTask.__init__(self, *args, **kwargs)

def setDefaults(self):
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, redundant, so removed.


# 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'])
Copy link
Contributor

Choose a reason for hiding this comment

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

badBits not used.

# 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'])
Copy link
Contributor

@yalsayyad yalsayyad Jul 9, 2017

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

def subtractExposures(self, templateExposure, scienceExposure,
doWarping=True, spatiallyVarying=True, inImageSpace=False,
doPreConvolve=False):

Copy link
Contributor

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)

Copy link
Contributor Author

@djreiss djreiss Aug 9, 2017

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.

destBBox=scienceExposure.getBBox())

templateExposure.setPsf(psfWarped)
templateExposure.writeFits('WARPEDTEMPLATE_ZOGY.fits')
Copy link
Contributor

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.

Copy link
Contributor Author

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.

gm(results.D).getArray()[np.isnan(ga(scienceExposure))] |= badBitsNan
gm(results.D).getArray()[np.isnan(ga(templateExposure))] |= badBitsNan

#results = pipeBase.Struct(exposure=D)
Copy link
Contributor

@yalsayyad yalsayyad Jul 9, 2017

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.


def gm(exp):
return exp.getMaskedImage().getMask()
def ga(exp):
Copy link
Contributor

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

return exp.getMaskedImage().getMask()
def ga(exp):
return exp.getMaskedImage().getImage().getArray()
def gv(exp):
Copy link
Contributor

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.

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.

badBitsNan = mask.getPlaneBitMask(['UNMASKEDNAN'])
mask |= gm(scienceExposure)
mask |= gm(templateExposure)
gm(results.D)[:, :] = mask
Copy link
Contributor

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):
Copy link
Contributor

Choose a reason for hiding this comment

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

Add returnMatchedTemplate to docstring.

def subtractMaskedImages(self, templateExposure, scienceExposure,
doWarping=True, spatiallyVarying=True, inImageSpace=False,
doPreConvolve=False):
pass # not implemented
Copy link
Contributor

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.

- 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
@djreiss djreiss merged commit 2e13b0b into master Aug 28, 2017
@ktlim ktlim deleted the tickets/DM-10805 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

4 participants