Skip to content

Commit

Permalink
Merge pull request #221 from lsst/tickets/DM-43848
Browse files Browse the repository at this point in the history
DM-43848: Add tests to reflect the new spatially sampled metric Task
  • Loading branch information
BrunoSanchez committed Apr 17, 2024
2 parents 50eb43f + 9f797e6 commit 44401d7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
37 changes: 35 additions & 2 deletions python/lsst/ap/verify/testPipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
DiaPipelineConfig, FilterDiaSourceCatalogConfig)
from lsst.pipe.base import PipelineTask, Struct
from lsst.ip.isr import IsrTaskConfig
from lsst.ip.diffim import GetTemplateConfig, AlardLuptonSubtractConfig, DetectAndMeasureConfig
from lsst.ip.diffim import (GetTemplateConfig, AlardLuptonSubtractConfig,
DetectAndMeasureConfig, SpatiallySampledMetricsConfig)
from lsst.pipe.tasks.characterizeImage import CharacterizeImageConfig
from lsst.pipe.tasks.calibrate import CalibrateConfig
from lsst.meas.transiNet import RBTransiNetConfig
Expand Down Expand Up @@ -432,7 +433,6 @@ def run(self, science, matchedTemplate, difference,
"""
return Struct(subtractedMeasuredExposure=difference,
diaSources=afwTable.SourceCatalog(),
spatiallySampledMetrics=astropy.table.Table(),
)


Expand Down Expand Up @@ -460,6 +460,39 @@ def run(self, diaSourceCat):
)


class MockSpatiallySampledMetricsTask(PipelineTask):
"""A do-nothing substitute for SpatiallySampledMetricsTask.
"""
ConfigClass = SpatiallySampledMetricsConfig
_DefaultName = "notSpatiallySampledMetricsTask"

def run(self, science, matchedTemplate, template, difference, diaSources):
"""Produce spatially sampled metrics
Parameters
----------
science : `lsst.afw.image.ExposureF`
Science exposure that the template was subtracted from.
matchedTemplate : `lsst.afw.image.ExposureF`
Warped and PSF-matched template that was used produce the
difference image.
template : `lsst.afw.image.ExposureF`
Warped and non PSF-matched template that was used to produce
the difference image.
difference : `lsst.afw.image.ExposureF`
Result of subtracting template from the science image.
diaSources : `lsst.afw.table.SourceCatalog`
The catalog of detected sources.
Returns
-------
results : `lsst.pipe.base.Struct`
Results struct with components.
"""

return Struct(spatiallySampledMetrics=astropy.table.Table())


class MockRBTransiNetTask(PipelineTask):
"""A do-nothing substitute for RBTransiNetTask.
"""
Expand Down
31 changes: 29 additions & 2 deletions tests/test_testPipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
from lsst.ap.verify.testPipeline import MockIsrTask, MockCharacterizeImageTask, \
MockCalibrateTask, MockGetTemplateTask, \
MockAlardLuptonSubtractTask, MockDetectAndMeasureTask, MockTransformDiaSourceCatalogTask, \
MockRBTransiNetTask, MockDiaPipelineTask, MockFilterDiaSourceCatalogTask
MockRBTransiNetTask, MockDiaPipelineTask, MockFilterDiaSourceCatalogTask, \
MockSpatiallySampledMetricsTask


class MockTaskTestSuite(unittest.TestCase):
Expand Down Expand Up @@ -254,7 +255,6 @@ def testMockDetectAndMeasureTask(self):
"difference": self.visitId,
"diaSources": self.visitId,
"subtractedMeasuredExposure": self.visitId,
"spatiallySampledMetrics": self.visitId,
})
pipelineTests.runTestQuantum(task, self.butler, quantum, mockRun=False)

Expand All @@ -264,6 +264,33 @@ def testMockFilterDiaSourceCatalogTask(self):
result = task.run(afwTable.SourceCatalog())
pipelineTests.assertValidOutput(task, result)

def testMockSpatiallySampledMetricsTask(self):
task = MockSpatiallySampledMetricsTask()
result = task.run(
afwImage.ExposureF(),
afwImage.ExposureF(),
afwImage.ExposureF(),
afwImage.ExposureF(),
afwTable.SourceCatalog(),
)
pipelineTests.assertValidOutput(task, result)

self.butler.put(afwImage.ExposureF(), "calexp", self.visitId)
self.butler.put(afwImage.ExposureF(), "deepDiff_matchedExp", self.visitId)
self.butler.put(afwImage.ExposureF(), "deepDiff_templateExp", self.visitId)
self.butler.put(afwImage.ExposureF(), "deepDiff_differenceExp", self.visitId)
self.butler.put(afwTable.SourceCatalog(), "deepDiff_candidateDiaSrc", self.visitId)
quantum = pipelineTests.makeQuantum(
task, self.butler, self.visitId,
{"science": self.visitId,
"matchedTemplate": self.visitId,
"template": self.visitId,
"difference": self.visitId,
"diaSources": self.visitId,
"spatiallySampledMetrics": self.visitId,
})
pipelineTests.runTestQuantum(task, self.butler, quantum, mockRun=False)

def testMockRBTransiNetTask(self):
task = MockRBTransiNetTask()
pipelineTests.assertValidInitOutput(task)
Expand Down

0 comments on commit 44401d7

Please sign in to comment.