Skip to content

Commit

Permalink
Turn off compatibility mode as the default.
Browse files Browse the repository at this point in the history
Also set the default convolution mode to `convolveTemplate`.
This is the next step in our transition to the refactored image differencing,
which preserves the default functionality of always convolving the template.
With `forceCompatibility=False` we can use the new code to fix a few bugs that were
present in the old ImageDifferenceTask.

Update subtractImages config validation.
  • Loading branch information
isullivan committed Aug 5, 2022
1 parent a4827df commit 2f31e82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
10 changes: 6 additions & 4 deletions python/lsst/ip/diffim/subtractImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class AlardLuptonSubtractConfig(lsst.pipe.base.PipelineTaskConfig,
pipelineConnections=AlardLuptonSubtractConnections):
mode = lsst.pex.config.ChoiceField(
dtype=str,
default="auto",
default="convolveTemplate",
allowed={"auto": "Choose which image to convolve at runtime.",
"convolveScience": "Only convolve the science image.",
"convolveTemplate": "Only convolve the template image."},
Expand Down Expand Up @@ -148,7 +148,7 @@ class AlardLuptonSubtractConfig(lsst.pipe.base.PipelineTaskConfig,

forceCompatibility = lsst.pex.config.Field(
dtype=bool,
default=True,
default=False,
doc="Set up and run diffim using settings that ensure the results"
"are compatible with the old version in pipe_tasks.",
deprecated="This option is only for backwards compatibility purposes"
Expand All @@ -162,8 +162,10 @@ def setDefaults(self):
self.makeKernel.kernel.active.spatialBgOrder = 2

def validate(self):
if self.forceCompatibility:
self.mode = "convolveTemplate"
if self.forceCompatibility and not (self.mode == "convolveTemplate"):
msg = "forceCompatibility=True requires mode='convolveTemplate'"
raise lsst.pex.config.FieldValidationError(AlardLuptonSubtractConfig.forceCompatibility,
self, msg)


class AlardLuptonSubtractTask(lsst.pipe.base.PipelineTask):
Expand Down
20 changes: 13 additions & 7 deletions tests/test_subtractTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,18 @@ def test_config_validate_forceCompatibility(self):
config = subtractImages.AlardLuptonSubtractTask.ConfigClass()
config.mode = "auto"
config.forceCompatibility = True
# Ensure we're not trying to change config values inside validate().
config.freeze()
with self.assertRaises(FieldValidationError):
config.validate()

config = subtractImages.AlardLuptonSubtractTask.ConfigClass()
config.mode = "convolveTemplate"
config.forceCompatibility = True
# Ensure we're not trying to change config values inside validate().
config.freeze()
# Should not raise:
config.validate()
self.assertEqual(config.mode, "convolveTemplate")

def test_mismatched_template(self):
"""Test that an error is raised if the template
Expand Down Expand Up @@ -207,7 +217,6 @@ def test_auto_convolveTemplate(self):
config = subtractImages.AlardLuptonSubtractTask.ConfigClass()
config.doSubtractBackground = False
config.mode = "convolveTemplate"
config.forceCompatibility = False

task = subtractImages.AlardLuptonSubtractTask(config=config)
output = task.run(template.clone(), science.clone(), sources)
Expand All @@ -228,7 +237,6 @@ def test_auto_convolveScience(self):
config = subtractImages.AlardLuptonSubtractTask.ConfigClass()
config.doSubtractBackground = False
config.mode = "convolveScience"
config.forceCompatibility = False

task = subtractImages.AlardLuptonSubtractTask(config=config)
output = task.run(template.clone(), science.clone(), sources)
Expand All @@ -252,6 +260,7 @@ def _run_and_check_images(statsCtrl, statsCtrlDetect, scienceNoiseLevel, templat
config = subtractImages.AlardLuptonSubtractTask.ConfigClass()
config.doSubtractBackground = False
config.forceCompatibility = False
config.mode = "convolveScience"
task = subtractImages.AlardLuptonSubtractTask(config=config)
output = task.run(template, science, sources)
self.assertFloatsAlmostEqual(task.metadata["scaleTemplateVarianceFactor"], 1., atol=.05)
Expand Down Expand Up @@ -330,7 +339,6 @@ def test_symmetry(self):
config = subtractImages.AlardLuptonSubtractTask.ConfigClass()
config.mode = 'auto'
config.doSubtractBackground = False
config.forceCompatibility = False
task = subtractImages.AlardLuptonSubtractTask(config=config)

# The science image will be modified in place, so use a copy for the second run.
Expand Down Expand Up @@ -426,7 +434,6 @@ def test_background_subtraction(self):
xSize=xSize, ySize=ySize, x0=x0, y0=y0)
config = subtractImages.AlardLuptonSubtractTask.ConfigClass()
config.doSubtractBackground = True
config.forceCompatibility = False

config.makeKernel.kernel.name = "AL"
config.makeKernel.kernel.active.fitForBackground = True
Expand Down Expand Up @@ -542,6 +549,7 @@ def _run_and_check_images(science, template, sources, statsCtrl,
"""

config = subtractImages.AlardLuptonSubtractTask.ConfigClass()
config.mode = "convolveScience"
config.doSubtractBackground = False
config.forceCompatibility = False
config.doDecorrelation = doDecorrelation
Expand Down Expand Up @@ -619,7 +627,6 @@ def test_exposure_properties_convolve_template(self):

config = subtractImages.AlardLuptonSubtractTask.ConfigClass()
config.mode = "convolveTemplate"
config.forceCompatibility = False

def _run_and_check_images(doDecorrelation):
"""Check that the metadata is correct with or without decorrelation.
Expand Down Expand Up @@ -669,7 +676,6 @@ def test_exposure_properties_convolve_science(self):

config = subtractImages.AlardLuptonSubtractTask.ConfigClass()
config.mode = "convolveScience"
config.forceCompatibility = False

def _run_and_check_images(doDecorrelation):
"""Check that the metadata is correct with or without decorrelation.
Expand Down

0 comments on commit 2f31e82

Please sign in to comment.