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
tickets/DM-22137 #16
Conversation
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.
This reverts commit 2122015.
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.
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.
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) |
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.
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)") |
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.
"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") |
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 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?).
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.
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. | ||
|
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 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.
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.
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") |
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 warning isn't very helpful. Why isn't this caught upstream?
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 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` | ||
""" |
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.
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 | ||
""" |
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.
Where are the Parameter docs? (1)
|
||
|
||
def modelToHeavy(source, filters, xy0=Point2I(), observation=None, dtype=np.float32): | ||
"""Convert the model to a `MultibandFootprint` |
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.
Where are the Parameter docs? (3)
|
||
Parameters | ||
---------- | ||
mExposure: `MultibandExposure` |
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.
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` |
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 don't think you imported Rect anywhere so this probably won't work.
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.
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.
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 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.
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.
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 |
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.
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` |
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 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` |
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 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.
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 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!).
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.
Should be ready to go now. |
Integrate scarlet 1.0 into the stack and test on HSC data.