Conversation
|
Default values are not updated now. so
|
81d60d4 to
876d95d
Compare
PaulPrice
left a comment
There was a problem hiding this comment.
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" |
| 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.
Can you change these into RuntimeErrors with useful error messages?
| ConfigClass = MaskObjectsConfig | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super(MaskObjectsTask, self).__init__(*args, **kwargs) |
There was a problem hiding this comment.
Python 3, so just need super().__init__(*args, **kwargs).
|
|
||
|
|
||
| class MaskObjectsTask(Task): | ||
| """MaskObjectsTask |
There was a problem hiding this comment.
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.
Why two normalisation factors of (s * numpy.sqrt(2. * numpy.pi))?
| exp.maskedImage.image.array[detected] = smooth.getImage().getArray()[detected] | ||
|
|
||
|
|
||
| class NanSafeSmoothing: |
There was a problem hiding this comment.
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.
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.
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
| pool.mapToPrevious(self.write, dataIdList) | ||
|
|
||
| def smoothFocalPlaneSubtraction(self, camera, pool, dataIdList): | ||
| '''Do 2nd Focal Plane subtraction |
There was a problem hiding this comment.
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.
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.
This comment is a bit too terse to understand what you mean.


See https://jira.lsstcorp.org/browse/DM-17426?focusedCommentId=191295&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-191295