-
Notifications
You must be signed in to change notification settings - Fork 18
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
DM-46693: Add ability to re-apply bgModel1 in SkyCorrectionTask #989
base: main
Are you sure you want to change the base?
Conversation
440338a
to
1fef450
Compare
1fef450
to
a4066ff
Compare
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.
Just a few minor comments, otherwise LGTM.
from lsst.pipe.base import (PipelineTask, PipelineTaskConfig, | ||
PipelineTaskConnections, Struct) | ||
from lsst.pipe.tasks.background import (FocalPlaneBackground, | ||
FocalPlaneBackgroundConfig, | ||
MaskObjectsTask, SkyMeasurementTask) | ||
from lsst.pipe.tasks.visualizeVisit import (VisualizeMosaicExpConfig, | ||
VisualizeMosaicExpTask) |
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.
Is there a reason that this formatting changed? In general we prefer not to make changes that are merely stylistic that depend on the coders style preference, and the older version is the preferred black
formatting, so I would undo this change.
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 agree, this formatting change should probably be reverted. When I run this file through my black
/isort
formatters, it also reverts it to its original format as well.
doBgModel1 = Field( | ||
dtype=bool, | ||
default=True, | ||
doc="If False, adds back initial background model after sky", | ||
) |
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 would change the name of this config parameter. I see the symmetry in making it similar to doBgModel2 but in that case the config option chooses whether or not to do the final cleanup and background subtraction. Here, it looks like the initial background subtraction is done in order to do the sky subtraction, then it is added back in if doBgModel1 == False
. So I would recommend calling this restoreOriginalBackground
or something similar that doesn't make it sound as if the model 1 background subtraction is skipped completely.
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.
How about restoreBgModel1
? To keep the symmetry but clarify the usage. And then the default value will swap to False
.
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.
Maybe I misunderstand the code, but it isn't restoring bgModel1, right? I thought that it's restoring the background before bgModel1 was made and subtracted. Maybe undoBgModel1
or removeBgModel1
or revertBgModel1
?
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.
The order of operations facilitated here is:
- subtract bgModel1
- subtract sky
- remove bgModel1 from the background list
- subtract bgModel2
At the end of this, the skyCorr
output background list should consist of:
- the inverted original detector-level background elements (4 of them)
- no bgModel1 (this has been used to fit the sky frame, and then removed from the bg list)
- sky frame
- bgModel2
With that in mind, I do agree that naming this config doBgModel1
makes it seem like a similar operation to doBgModel2
, but it does act differently. I wasn't sure which alternative to endorse; I realize that in describing the order of operations and dataset outputs above I twice referred to this as a removal. However, out of context, "remove BG Model 1" sounds like you're subtracting the model, which is the opposite of what we're doing here.
So with that said, I think undoBgModel1
is a nice compromise. I think we would need to make the usage of this config clear in the doc string though.
|
||
Parameters | ||
---------- | ||
calExps : `list` [`lsst.afw.image.exposure.ExposureF`] |
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 can just be:
calExps : `list` [`lsst.afw.image.ExposureF`]
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 probably needs to be changed in the doc-strings across this file at the same time too)
---------- | ||
calExps : `list` [`lsst.afw.image.exposure.ExposureF`] | ||
Calibrated exposures to be background subtracted. | ||
calBkgs : `list` [`lsst.afw.math._backgroundList.BackgroundList`] |
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 can also just be:
calBkgs : `list` [`lsst.afw.math.BackgroundList`]
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.
(and in the returns below)
Returns | ||
------- | ||
calExps : `list` [`lsst.afw.image.maskedImage.MaskedImageF`] | ||
Background subtracted exposures for creating a focal plane image. | ||
calBkgs : `list` [`lsst.afw.math._backgroundList.BackgroundList`] | ||
Updated background lists with a visit-level model removed. |
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.
There's a return section here, but this function doesn't seem to return anything? Instead, it seems to edit in-place?
calBkg._backgrounds.pop(-2) | ||
|
||
self.log.info( | ||
"Detector %d: FFP background restored", |
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 think this log message could do with being more verbose, e.g.:
"Detector %d: Initial background model prior to sky frame subtraction (bgModel1) has been restored",
This does however now clash with usage of "initial background" on lines 377 and 396, which refer to the "original background" at the calexp level. I would favor renaming these two instances to "original background", and preserve initial background as a reference to bgModel1
.
@@ -387,6 +400,37 @@ def _restoreBackgroundRefineMask(self, calExps, calBkgs): | |||
skyCorrBases.append(skyCorrBase) | |||
return calExps, skyCorrBases | |||
|
|||
def _restoreVisitBackground(self, calExps, calBkgs): |
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 would suggest renaming this to _restoreInitialBackground
.
In tandem with this, the current method _restoreBackgroundRefineMask
should probably also be renamed to _restoreOriginalBackgroundRefineMask
, to avoid any potential confusion.
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.
PS - if we're changing the associated config to undoBgModel1
, it probably also makes sense to rename this method _undoInitialBackground
as well.
|
||
Returns | ||
------- | ||
calExps : `list` [`lsst.afw.image.maskedImage.MaskedImageF`] |
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 worried me originally, as the input calExps
are ExposureF
, but the output is a MaskedImageF
? However, I think this returns section is going away in any case (see other related comment). You can probably replace this section with a Notes
stating that the inputs are modified in-place.
bfeda7e
to
ad3505d
Compare
f30f0f2
to
739b097
Compare
739b097
to
65fed08
Compare
The current
SkyCorrectionTask
has three principal steps:bgModel1
- a large-scale sky estimation and subtractionsky
- a subtraction of the sky framebgModel2
- a small-scale sky estimation and subtractionIf one has
doSky = True
, thenbgModel1
is implied. However, during testing of DM-44889, it became apparent that the need for adoSky = True
-only dataset output was required. This necessitates thatbgModel1
is generated, used, and then undone.This ticket adds that functionality into the current
SkyCorrectionTask
.Note the prior related removal ticket of
doBgModel1
, DM-37429, which may be relevant/of use here.