-
Notifications
You must be signed in to change notification settings - Fork 0
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-17426 #1
base: master
Are you sure you want to change the base?
DM-17426 #1
Conversation
Default values are not updated now. so
|
81d60d4
to
876d95d
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.
This is a good start, but we need to make some changes in order to meet LSST's standards.
self.detection.doTempLocalBackground = False | ||
self.detection.doTempWideBackground = False | ||
self.detection.thresholdValue = 2.5 | ||
# self.detection.thresholdPolarity = "both" |
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 commented code.
def validate(self): | ||
assert not self.detection.reEstimateBackground | ||
assert not self.detection.doTempLocalBackground | ||
assert not self.detection.doTempWideBackground |
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.
Can you change these into RuntimeError
s with useful error messages?
ConfigClass = MaskObjectsConfig | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(MaskObjectsTask, self).__init__(*args, **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.
Python 3, so just need super().__init__(*args, **kwargs)
.
|
||
|
||
class MaskObjectsTask(Task): | ||
"""MaskObjectsTask |
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.
Need a better short summary than the name of the task. Maybe "Iterative masking of objects on an image"?
@staticmethod | ||
def _normalDist(x, s=1., m=0.): | ||
''' Normal Distribution ''' | ||
return 1. / (s * numpy.sqrt(2. * numpy.pi)) * numpy.exp(-(x-m)**2/(2*s**2)) / (s * numpy.sqrt(2*numpy.pi)) |
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.
Why two normalisation factors of (s * numpy.sqrt(2. * numpy.pi))
?
@@ -785,3 +794,52 @@ def run(self, exp): | |||
detected = mask.array & mask.getPlaneBitMask(['DETECTED']) > 0 | |||
exp.maskedImage.image.array[detected] = smooth.getImage().getArray()[detected] | |||
|
|||
|
|||
class NanSafeSmoothing: |
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 think this section needs a different implementation.
It looks like you're using class
here just as a namespace, which feels dirty. I don't think it adds anything beyond making a stand-alone function with a couple of embedded functions.
A direct convolution implemented in python is going to be crazy slow (especially since you're not making use of the fact that the kernel is separable). Is there a reason you can't use the convolution functionality in afw, as is done in SourceDetectionTask
? If you're worried about NaNs, you can always (temporarily?) replace them with zeros when you do the convolution.
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.
If you're worried about NaNs, you can always (temporarily?) replace them with zeros when you do the convolution.
This is why I didn't use the existing convolution code. Replacing NaNs with 0 is not equivalent to my code.
Sometimes super-pixels on the edge of the field are bit high. In that case it is better that the super-pixels out of the field are as the are extrapolated (this is what I intended to) than assuming that they are zero (replacing NaNs with 0). In other words, replacing NaNs with 0 leads low sky estimation near the bright edge.
A direct convolution in Python is crazy slow, but the targets of this code are relatively small images such as FocalPlaneBackground._values whose dimensions are about 140x150. Convolutions on such images end in about 0.5 second on my mac.
It looks like you're using class here just as a namespace, which feels dirty. I don't think it adds anything beyond making a stand-alone function with a couple of embedded functions.
I totally agree with you. I will put these functions flat in the module.
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 figured out the difference between your convolution and the vanilla convolution. This will allow us to condense the code, and probably run it faster:
def safeConvolve(array, sigma=2):
bad = np.isnan(array)
safe = np.where(bad, 0.0, array)
convolved = gaussian_filter(safe, sigma, mode="constant", cval=0.0)
corr = np.where(bad, 0.0, 1.0)
ones = np.ones_like(array)
numerator = gaussian_filter(ones, sigma, mode="constant", cval=0.0)
denominator = gaussian_filter(corr, sigma, mode="constant", cval=0.0)
return convolved*numerator/denominator
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.
Excellent solution.
# Persist camera-level image of calexp | ||
image = makeCameraImage(camera, exposures) | ||
expRef.put(image, "calexp_camera") | ||
|
||
pool.mapToPrevious(self.write, dataIdList) | ||
|
||
def smoothFocalPlaneSubtraction(self, camera, pool, dataIdList): | ||
'''Do 2nd Focal Plane subtraction |
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.
Please use numpydoc style for docstrings.
for ii, bg in enumerate(bgModelList): | ||
self.log.info("Background %d: %d pixels", ii, bg._numbers.array.sum()) | ||
bgModel.merge(bg) | ||
exposures = pool.mapToPrevious(self.subtractModel, dataIdList, bgModel) |
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 the same code as before (lines 138-143). Can you factor it into a common method so the code isn't duplicated?
'''Do 2nd Focal Plane subtraction | ||
|
||
After doSky, we get smooth focal plane image. | ||
(Before doSky, sky pistons remain in HSC-G) |
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 comment is a bit too terse to understand what you mean.
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 would like your comment on this.
I've started revising the code for other comments.
See https://jira.lsstcorp.org/browse/DM-17426?focusedCommentId=191295&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-191295