-
Notifications
You must be signed in to change notification settings - Fork 8
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
Added mask planes from template and science fake plane into difference #280
Conversation
d790d07
to
143cdf1
Compare
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.
In addition to the code comments, please add a simple unit test of the new updateMasks
.
templateFakeBitMask = template[bbox].mask.getPlaneBitMask('FAKE') | ||
|
||
injScienceMaskArray = ((science.mask.array & scienceFakeBitMask) > 0) | ||
injScienceMaskArray *= diffInjectedBitMask |
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.
In testing, I get the following error from this line (and below):
numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'multiply' output from dtype('int64') to dtype('bool') with casting rule 'same_kind'
I suggest removing the line injScienceMaskArray *= diffInjectedBitMask
and using mask.array[injScienceMaskArray] |= diffInjectedBitMask
below. You might want to change the variable name of injScienceMaskArray
to reflect the new usage.
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 found an alternative solution to this. I have simplified to a single line, and multiplied by the bit mask values in the same variable assignation. It also seems to suit the same name, at least to me.
injTemplateMaskArray = ((template[bbox].mask.array & templateFakeBitMask) > 0) | ||
injTemplateMaskArray *= diffInjectedTemplateBitMask | ||
|
||
mask.array |= injScienceMaskArray |
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 my requested modification in the comment above. Looks resolved with the above changes.
@@ -581,6 +576,42 @@ def finalize(self, template, science, difference, kernel, | |||
correctedExposure = difference | |||
return correctedExposure | |||
|
|||
def updateMasks(self, difference, science, template): |
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.
Could you keep the same order of images as in finalize
: template, science, difference
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.
Done!
maskPlane for maskPlane in badMaskPlanes if maskPlane in mask.getMaskPlaneDict().keys() | ||
] | ||
|
||
badPixelMask = mask.getPlaneBitMask(setBadMaskPlanes) |
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.
Thanks for changing this. We need to switch from lsst.afw.image.Mask.getPlaneBitMask
to mask.getPlaneBitMask
in general (see lsst/meas_algorithms#329 (comment))
@@ -712,7 +743,12 @@ def _checkMask(mask, sources, badMaskPlanes): | |||
kept (True) or rejected (False) based on the value of the | |||
mask plane at its location. | |||
""" | |||
badPixelMask = lsst.afw.image.Mask.getPlaneBitMask(badMaskPlanes) | |||
setBadMaskPlanes = [ | |||
maskPlane for maskPlane in badMaskPlanes if maskPlane in mask.getMaskPlaneDict().keys() |
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.
Minor point, but I don't think the .keys()
is necessary here.
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.
Done
This is ready for second review! |
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.
Looks good! I had a few suggested changes, though the only necessary one is to remove the dangling code comment.
if self.config.doDecorrelation: | ||
self.log.info("Decorrelating image difference.") | ||
# We have cleared the template mask plane, so copy the mask plane of | ||
# the image difference so that we can calculate correct statistics | ||
# during decorrelation | ||
template[science.getBBox()].mask.array[...] = difference.mask.array[...] |
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 remove the associated code comment above.
tests/test_subtractTask.py
Outdated
science.image.array += science_fake_img.image.array | ||
template.image.array += tmplt_fake_img.image.array | ||
|
||
# TODO: update to INJECTED names when source injection gets refactored |
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.
Try to always reference a ticket number with any TODO. I think that is DM-40796 here.
inj_masked = (diff_mask.array & diff_mask.getPlaneBitMask("INJECTED")) > 0 | ||
|
||
# template mask should be now in INJECTED_TEMPLATE | ||
injTmplt_masked = (diff_mask.array & diff_mask.getPlaneBitMask("INJECTED_TEMPLATE")) > 0 | ||
|
||
self.assertEqual(np.sum(inj_masked.astype(int)-science_fake_masked.astype(int)), 0) | ||
self.assertEqual(np.sum(injTmplt_masked.astype(int)-template_fake_masked.astype(int)), 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.
Since the mask plane is changing, this looks like a good way to do the test. For future reference, see https://pipelines.lsst.io/py-api/lsst.utils.tests.TestCase.html for useful built-in asserts, though I don't think any would quite work here.
tests/test_subtractTask.py
Outdated
science.mask.addMaskPlane("FAKE") | ||
template.mask.addMaskPlane("FAKE") | ||
|
||
science_mask_planes = science.mask.getMaskPlaneDict() |
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.
You could use science_fake_mask = science.mask.getMaskPlane('FAKE')
here, and then just use science_fake_mask
instead of science_mask_planes['FAKE']
later. Same for the template below.
Or use science_fake_mask = science.mask.getPlaneBitMask("FAKE")
if you use my suggestion below.
tests/test_subtractTask.py
Outdated
for dy in (-1, 0, 1): | ||
science.mask.setMaskPlaneValues( | ||
science_mask_planes['FAKE'], | ||
int(a_science_source.getX() - x0)-1, | ||
int(a_science_source.getX() - x0)+1, | ||
int(a_science_source.getY() - y0)+dy | ||
) |
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 is fine, but I have an alternate suggestion:
bbox = lsst.geom.Box2I(lsst.geom.Point2I(a_science_source.getX(), a_science_source.getY()), lsst.geom.Extent2I(3, 3))
science[bbox].mask.array |= science_fake_mask
using science_fake_mask
from my above suggestion.
Thanks for the comments. All of them are implemented! |
fc2f8aa
to
7d888a3
Compare
This is the final Jenkins run that validates this merge: https://rubin-ci.slac.stanford.edu/job/stack-os-matrix/480/ |
Added the needed mask plane into differences. These are two new planes named
'INJECTED'
and'INJECTED_TEMPLATE'