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

tickets/DM-15106 Use multiband classes in meas_deblender #57

Merged
merged 3 commits into from Jul 28, 2018

Conversation

fred3m
Copy link
Contributor

@fred3m fred3m commented Jul 27, 2018

No description provided.

except TypeError:
maskedImages = [maskedImages]
if not isinstance(mMaskedImage, afwImage.MultibandMaskedImage):
mMaskedImage = [mMaskedImage]

Choose a reason for hiding this comment

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

What if it is already a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not allowed to be. The input either needs to be a MultibandMaskedImage or a MaskedImage, as stated in the docstring.

@@ -102,7 +101,7 @@ def __init__(self, footprint, maskedImages, psfs, psffwhms, log, filters=None,
else:
avgNoise = [avgNoise]
# Now check that all of the parameters have the same number of entries
if any([len(maskedImages)!=len(p) for p in [psfs, psffwhms, avgNoise]]):
if any([len(mMaskedImage.filters)!=len(p) for p in [psfs, psffwhms, avgNoise]]):

Choose a reason for hiding this comment

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

Space around operators?

# Create a DeblendedParent for the Footprint in every filter
self.deblendedParents = OrderedDict([])
for n in range(self.filterCount):
for n,f in enumerate(self.filters):

Choose a reason for hiding this comment

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

Space after comma?

Choose a reason for hiding this comment

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

Perhaps use n, filter as below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with filter is that it's a builtin. I know that some people use it in the stack but I prefer to just use f, although if it really bugs you I can change the name.

@@ -842,8 +840,8 @@ def run(self, exposures, sources):
created by the multiband templates.
If `self.config.saveTemplates` is `False`, then this item will be None
"""
psfs = {B:exp.getPsf() for B, exp in exposures.items()}
return self.deblend(exposures, sources, psfs)
psfs = {f:mExposure[f].getPsf() for f in mExposure.filters}

Choose a reason for hiding this comment

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

filter? f always makes me think of file handle. Although in a comprehension it is pretty obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, even if you'd like me to change it in the loops, I'd prefer to keep the f in the list comprehensions.

Copy link

@yalsayyad yalsayyad Jul 27, 2018

Choose a reason for hiding this comment

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

filter is a built-in and against coding standards anyway: https://developer.lsst.io/python/style.html#user-defined-names-should-not-shadow-python-built-in-functions. Update: I see Fred already pointed this out above.

should be a merged catalog of the sources in each band ('deepCoadd_mergeDet').
Keys are the names of the filters
(should be the same as `mExposure.filters`) and the values are
`lsst.afw.table.source.source.SourceCatalog`'s,which

Choose a reason for hiding this comment

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

Space after comma? Is there a check that they are correct names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is now...

self.log.info("Deblending {0} sources in {1} exposures".format(len(sources), len(bands)))
filters = mExposure.filters
mMaskedImage = afwImage.MultibandMaskedImage(filters=mExposure.filters, image=mExposure.image,
mask=mExposure.mask, variance=mExposure.variance)

Choose a reason for hiding this comment

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

Hmm, so there isn't a constructor for MultibandMaskedImage that takes a MultibandExposure? That seems sad. Although perhaps you don't want that because it is a narrowing conversion? Then perhaps a static method? E.g. mMaskedImage = afwImage.MultibandMaskedImage.fromMultibandExposure(mExposure)? Or a property (mMaskedImage = mExposure.multibandMaskedImage)? both would reduce the potential for swapping image/mask/variance by accident.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point. Actually, I think that MultibandMaskedImage.fromImages would actually work if a MultibandExposure is used in place of the of a MultibandMaskedImage. I'll open a ticket to rename fromImages to a more inclusive name.

_peak = heavy[band].getPeaks()[0]
fluxParents[band].getFootprint().addPeak(_peak.getFx(), _peak.getFy(),
_peak = heavy[f].getPeaks()[0]
fluxParents[f].getFootprint().addPeak(_peak.getFx(), _peak.getFy(),

Choose a reason for hiding this comment

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

Why doesn't addPeak take a Peak?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your guess is as good as mine.

weights[mask] = 0
badPixels = mMaskedImage.mask.getPlaneBitMask(badMask)
mask = (mMaskedImage.mask.array & badPixels) | fpMask[None, :]
weights[mask>0] = 0

Choose a reason for hiding this comment

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

Was this intentional? Is it actually faster?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if it's faster, but it's possible now and I think looks cleaner than the previous version.

Choose a reason for hiding this comment

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

weights[mask>0] is against standards anyway. Need whitespace around >.


# The peak in each band will have the same SpanSet
mask = afwImage.Mask(np.array(np.sum(model, axis=0)>0, dtype=np.int32),
xy0=debResult.footprint.getBBox().getBegin())
mask = afwImage.Mask(np.array(np.sum(model, axis=0)>0, dtype=np.int32), xy0=xy0)

Choose a reason for hiding this comment

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

Since you're changing this line anyway, it's good practice to make it comply with our coding standards even if the original infraction wasn't yours.

@@ -102,7 +101,7 @@ def __init__(self, footprint, maskedImages, psfs, psffwhms, log, filters=None,
else:
avgNoise = [avgNoise]
# Now check that all of the parameters have the same number of entries
if any([len(maskedImages)!=len(p) for p in [psfs, psffwhms, avgNoise]]):
if any([len(self.filters) !=len (p) for p in [psfs, psffwhms, avgNoise]]):

Choose a reason for hiding this comment

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

Variable name maskedImages on line 108 doesn't exist. That raise will never work now.

Choose a reason for hiding this comment

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

Also, did you mean to put the whitespace in this line before the len instead of after? :)

@fred3m fred3m merged commit 2851537 into master Jul 28, 2018
@ktlim ktlim deleted the tickets/DM-15106 branch August 25, 2018 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants