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-22137 #16

Merged
merged 9 commits into from Jan 17, 2020
Merged

tickets/DM-22137 #16

merged 9 commits into from Jan 17, 2020

Conversation

fred3m
Copy link
Contributor

@fred3m fred3m commented Jan 13, 2020

Integrate scarlet 1.0 into the stack and test on HSC data.

fred3m added 5 commits January 8, 2020 14:29
In a conversation with @pmelchior it was suggested that normalizing
the morphology might not be necessary with the new ADAM algorithm in
scarlet, since it's better at breaking up degeneracies.
In order to test this on HSC data this commit added functionality
to rmove the normalization constraint. The result of the test was
that deblending takes longer with poorer results when not using
normalization, so this code will be stripped out in the next commit
but is stored here for historical purposes.
Testing has shown that using the lower convergence threshold for
scarlet 1.0 improves the residuals but takes more iterations.
Execution on a few small 1k x 1k patches running for up to 1000
iterations showed that most models converge before 100 iterations
but a significant fraction of blends don't converge until between
200-300 iterations, while blends that haven't converged by 300
iterations do not appear to ever converge. So we choose 300
iterations as the new cutoff.
This updates the unit tests to use the new API.
This includes removing a few tests for functionality that has either
been stripped or significantly modified.
Copy link

@taranu taranu left a comment

Choose a reason for hiding this comment

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

Mostly fine but I left a few comments that should be addressed.

for center in footprint.peaks
]
psfShape = (config.modelPsfSize, config.modelPsfSize)
model_psf = PSF(partial(gaussian, sigma=.8), shape=(None,)+psfShape)
Copy link

Choose a reason for hiding this comment

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

Isn't that sigma=.8 important enough to set in the config with that default?

usePsfConvolution = pexConfig.Field(
dtype=bool, default=True,
doc=("Whether or not to convolve the morphology with the"
"PSF in each band or use the same morphology in all bands"))
modelPsfSize = pexConfig.Field(
dtype=int, default=11,
doc="The model PSF will be (modelPsfSize, modelPsfSize)")
Copy link

Choose a reason for hiding this comment

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

"Model PSF side length in pixels" or something like that?

"of the source converged, otherwise it"
"contains the bit flag for parameters that"
"failed, which might differ depending on the"
"source type")
Copy link

Choose a reason for hiding this comment

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

I find it somewhat confusing that deblend_blendConvergenceFailed is a flag whose name doesn't end in _flag (why not deblend_blendConvergence_flag?), whereas deblend_sourceConvergenceFlag isn't actually a flag (how about something like deblend_sourceConvergence_bits?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deblend_blendConvergenceFailed -> deblend_blendConvergenceFailedFlag
deblend_sourceConvergenceFlag -> deblend_sourceConvergenceBitFlag

it finds a model that can be initialized. If all of the
models fail, including a `PointSource` model, then skip
the source.

Copy link

Choose a reason for hiding this comment

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

I realize one can and should refer to scarlet's source here but it would be helpful to give a brief hint/summary as to how/why source initialization might fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

clarified the docs

monotonic=monotonic, thresh=thresh)
if (np.any([np.isnan(c.sed) for c in components]) or
np.all([c.sed <= 0 for c in source.components])):
logger.warning("Could not initialize")
Copy link

Choose a reason for hiding this comment

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

This warning isn't very helpful. Why isn't this caught upstream?

Copy link
Contributor Author

@fred3m fred3m Jan 15, 2020

Choose a reason for hiding this comment

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

This was part of a discussion that went on for weeks. scarlet used to throw a SourceInitError to inform the user that initialization failed but Peter felt strongly about having users check for a bad initialization and I finally got tired of fighting him on it.


def morphToHeavy(source, peakSchema, xy0=Point2I()):
"""Convert the morphology to a `HeavyFootprint`
"""
Copy link

Choose a reason for hiding this comment

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

Where are the Parameter docs? (2)

default initialization and update constraints for general sources in
LSST images.
def checkConvergence(source):
"""Check that a source converged
"""
Copy link

Choose a reason for hiding this comment

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

Where are the Parameter docs? (1)



def modelToHeavy(source, filters, xy0=Point2I(), observation=None, dtype=np.float32):
"""Convert the model to a `MultibandFootprint`
Copy link

Choose a reason for hiding this comment

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

Where are the Parameter docs? (3)


Parameters
----------
mExposure: `MultibandExposure`
Copy link

Choose a reason for hiding this comment

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

See https://developer.lsst.io/python/numpydoc.html#py-docstring-parameters

  • Must have a space before and after the colon
  • Parameter types should have the full namespace (lsst.foo.bar); I haven't checked to see if they work without them
  • It would be nice to maintain consistency (always end with a period; only add hyphens for lists)

Record for a peak in the parent `PeakCatalog`
observation: `LsstObservation`
The images, psfs, etc, of the observed data.
bbox: `Rect`
Copy link

Choose a reason for hiding this comment

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

I don't think you imported Rect anywhere so this probably won't work.

Copy link
Contributor Author

@fred3m fred3m Jan 15, 2020

Choose a reason for hiding this comment

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

It should, because I don't think this actually creates a link to the class. Otherwise I'd have to import Rect but never use it, which would cause flake8 to fail.

Copy link

Choose a reason for hiding this comment

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

I thought the whole point was to create links, but apparently it doesn't? I'll have to ask about that.

Anyway, in this case since you're not actually importing Rect, the full namespace would be more useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. It's a good thing you had me do this, I forgot that the stack doesn't call it Rect, it's Box2I.

@@ -24,4 +24,4 @@
from .observation import *
from .source import *
from .blend import *
from .deblend import *
from . import deblend
Copy link

Choose a reason for hiding this comment

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

Missing from .version import * (the docs won't build without it)

Record for a peak in the parent `PeakCatalog`
observation: `LsstObservation`
The images, psfs, etc, of the observed data.
bbox: `Rect`
Copy link

Choose a reason for hiding this comment

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

I thought the whole point was to create links, but apparently it doesn't? I'll have to ask about that.

Anyway, in this case since you're not actually importing Rect, the full namespace would be more useful.


Parameters
----------
frame: `LsstFrame`
Copy link

Choose a reason for hiding this comment

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

Need a space before and after the colon here and in most of the added parameter docstrings.

Sadly I haven't been able to convince PyCharm to do this automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an odd style guide requirement, as DM typically doesn't adhere to the spaces around operators rule. Numpydocs doesn't require this to compile properly, so this is just a waste of time (not your fault, I'm just venting). But I fixed it throughout the package, since I never use a space on both sides of the colon (because why would a sane person!).

fred3m added 2 commits January 16, 2020 14:38
Testing has shown that this threshold is too high and results in
truncated boxes around extended objects. We lower the threshold
from 5 to 1 to allow sources to grow larger.
@fred3m
Copy link
Contributor Author

fred3m commented Jan 16, 2020

Should be ready to go now.

@fred3m fred3m merged commit 74da54f into master Jan 17, 2020
@fred3m fred3m deleted the tickets/DM-22137 branch January 17, 2020 21:18
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.

None yet

2 participants