Skip to content

DM-17426#1

Open
michitaro wants to merge 6 commits into
HyperSuprime-Cam:masterfrom
michitaro:tickets/DM-17426
Open

DM-17426#1
michitaro wants to merge 6 commits into
HyperSuprime-Cam:masterfrom
michitaro:tickets/DM-17426

Conversation

@michitaro

@michitaro michitaro commented Mar 13, 2019

Copy link
Copy Markdown

@michitaro

michitaro commented Mar 13, 2019

Copy link
Copy Markdown
Author

Default values are not updated now. so constructSky.py should be run with the following options:

--config \
     largeScaleBackground.xSize=8192 \
     largeScaleBackground.ySize=8192 \

skyCorrection.py should by run with the following options:

--config \
    bgModel.xSize=8192 \
    bgModel.ySize=8192 \
    bgModel2.minFrac=0.5 \
    bgModel2.xSize=256 \
    bgModel2.ySize=256 \
    bgModel2.smoothScale=256

@PaulPrice PaulPrice left a comment

Copy link
Copy Markdown

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"

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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 RuntimeErrors with useful error messages?

ConfigClass = MaskObjectsConfig

def __init__(self, *args, **kwargs):
super(MaskObjectsTask, self).__init__(*args, **kwargs)

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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"?

Comment thread python/lsst/pipe/drivers/background.py
@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))

Copy link
Copy Markdown

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

exp.maskedImage.image.array[detected] = smooth.getImage().getArray()[detected]


class NanSafeSmoothing:

Copy link
Copy Markdown

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.

@michitaro michitaro Apr 2, 2019

Copy link
Copy Markdown
Author

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.

Screen Shot 2019-04-02 at 17 17 16

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.

Copy link
Copy Markdown

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

This reproduces your result:
image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Excellent solution.

pool.mapToPrevious(self.write, dataIdList)

def smoothFocalPlaneSubtraction(self, camera, pool, dataIdList):
'''Do 2nd Focal Plane subtraction

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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.

@michitaro michitaro left a comment

Copy link
Copy Markdown
Author

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.

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.

2 participants