From 1d2c0c705123d7cc6d3a48a20eb40390ac0e8afb Mon Sep 17 00:00:00 2001 From: Ian Sullivan Date: Fri, 30 Sep 2022 16:36:56 -0700 Subject: [PATCH] Add demo pipeline for a new metric and plot --- pipelines/demoPipeline.yaml | 13 +++++++ .../tools/analysisMetrics/__init__.py | 1 + .../tools/analysisMetrics/demoMetric.py | 36 +++++++++++++++++++ .../tools/analysisParts/demoPsfApRatio.py | 22 ++++++++++++ .../analysis/tools/analysisPlots/__init__.py | 1 + .../analysis/tools/analysisPlots/demoPlot.py | 14 ++++++++ python/lsst/analysis/tools/tasks/__init__.py | 1 + python/lsst/analysis/tools/tasks/demo.py | 29 +++++++++++++++ 8 files changed, 117 insertions(+) create mode 100644 pipelines/demoPipeline.yaml create mode 100644 python/lsst/analysis/tools/analysisMetrics/demoMetric.py create mode 100644 python/lsst/analysis/tools/analysisParts/demoPsfApRatio.py create mode 100644 python/lsst/analysis/tools/analysisPlots/demoPlot.py create mode 100644 python/lsst/analysis/tools/tasks/demo.py diff --git a/pipelines/demoPipeline.yaml b/pipelines/demoPipeline.yaml new file mode 100644 index 000000000..738179ef8 --- /dev/null +++ b/pipelines/demoPipeline.yaml @@ -0,0 +1,13 @@ +description: | + Test pipeline +tasks: + demoMetric1: + class: lsst.analysis.tools.tasks.DemoTask + config: + connections.outputName: demoOutput + bands: ['g'] + metrics.demoMetric: DemoMetric + plots.demoPlot: DemoPlot + python: | + from lsst.analysis.tools.analysisMetrics import * + from lsst.analysis.tools.analysisPlots import * diff --git a/python/lsst/analysis/tools/analysisMetrics/__init__.py b/python/lsst/analysis/tools/analysisMetrics/__init__.py index 9d325bde0..7a49e6f9b 100644 --- a/python/lsst/analysis/tools/analysisMetrics/__init__.py +++ b/python/lsst/analysis/tools/analysisMetrics/__init__.py @@ -25,3 +25,4 @@ from .photometricRepeatabilityMetrics import * from .psfResidualMetrics import * from .skyFluxStatisticMetrics import * +from .demoMetric import * diff --git a/python/lsst/analysis/tools/analysisMetrics/demoMetric.py b/python/lsst/analysis/tools/analysisMetrics/demoMetric.py new file mode 100644 index 000000000..8858bf6ad --- /dev/null +++ b/python/lsst/analysis/tools/analysisMetrics/demoMetric.py @@ -0,0 +1,36 @@ + +__all__ = ( + "DemoMetric", +) + + +from ..interfaces import AnalysisMetric +from lsst.analysis.tools.actions.scalar import MedianAction +from lsst.analysis.tools.actions.vector import SnSelector + + +class DemoMetric(AnalysisMetric): + def setDefaults(self): + super().setDefaults() + + # select on high signal to noise obejcts + # add in a signal to noise selector + self.prep.selectors.snSelector = SnSelector() + + # set what key the selector should use when deciding SNR + self.prep.selectors.snSelector.fluxType = "psFlux" + + # select what threshold value is desireable for the selector + self.prep.selectors.snSelector.threshold = 10 + + # the final name in the qualification is used as a key to insert + # the calculation into KeyedData + self.process.calculateActions.medianValueName = MedianAction(vectorKey="psFlux") + + # tell the metic what the units are for the quantity + self.produce.units = {"medianValueName": "Jy"} + + # Rename the quanity prior to producing the Metric + # (useful for resuable workflows that set a name toward + # the end of computation) + self.produce.newNames = {"medianValueName": "DemoMetric"} diff --git a/python/lsst/analysis/tools/analysisParts/demoPsfApRatio.py b/python/lsst/analysis/tools/analysisParts/demoPsfApRatio.py new file mode 100644 index 000000000..1bae1d7ab --- /dev/null +++ b/python/lsst/analysis/tools/analysisParts/demoPsfApRatio.py @@ -0,0 +1,22 @@ +from lsst.analysis.tools.interfaces import AnalysisTool +from lsst.analysis.tools.actions.vector import LoadVector, DivideVector + + +class DemoPsfApRatioBaseClass(AnalysisTool): + """Base class for scatter plots of PSF residuals. + This is shared by size and ellipticity plots. + """ + + def setDefaults(self): + super().setDefaults() + self.process.filterActions.loadVectorPsf = LoadVector() + self.process.filterActions.loadVectorAp = LoadVector() + + self.process.filterActions.loadVectorPsf.vectorKey = "psFlux" + self.process.filterActions.loadVectorAp.vectorKey = "apFlux" + + # the final name in the qualification is used as a key to insert + # the calculation into KeyedData + self.process.calculateActions.fluxRatioMetric = DivideVector( + actionA=self.process.filterActions.loadVectorPsf, + actionB=self.process.filterActions.loadVectorAp) diff --git a/python/lsst/analysis/tools/analysisPlots/__init__.py b/python/lsst/analysis/tools/analysisPlots/__init__.py index 7c9895cb3..9dd7500c3 100644 --- a/python/lsst/analysis/tools/analysisPlots/__init__.py +++ b/python/lsst/analysis/tools/analysisPlots/__init__.py @@ -1,2 +1,3 @@ from .analysisPlots import * from .skyObject import * +from .demoPlot import * diff --git a/python/lsst/analysis/tools/analysisPlots/demoPlot.py b/python/lsst/analysis/tools/analysisPlots/demoPlot.py new file mode 100644 index 000000000..fe778ca2f --- /dev/null +++ b/python/lsst/analysis/tools/analysisPlots/demoPlot.py @@ -0,0 +1,14 @@ +from lsst.analysis.tools.actions.plot.histPlot import HistPlot, HistPanel +from lsst.analysis.tools.interfaces import AnalysisPlot +from ..analysisParts.demoPsfApRatio import DemoPsfApRatioBaseClass + + +class DemoPlot(AnalysisPlot, DemoPsfApRatioBaseClass): + def setDefaults(self): + super().setDefaults() + + self.produce = HistPlot() + + self.produce.panels["panel_flux"] = HistPanel() + self.produce.panels["panel_flux"].label = "Psf/Ap Ratio" + self.produce.panels["panel_flux"].hists = dict(fluxRatioMetric="fluxRatioMetric") diff --git a/python/lsst/analysis/tools/tasks/__init__.py b/python/lsst/analysis/tools/tasks/__init__.py index 367ad3cfb..20b2e9dc0 100644 --- a/python/lsst/analysis/tools/tasks/__init__.py +++ b/python/lsst/analysis/tools/tasks/__init__.py @@ -3,3 +3,4 @@ from .diaSourceTableVisitAnalysis import * from .objectTableTractAnalysis import * from .sourceTableVisitAnalysis import * +from .demo import * diff --git a/python/lsst/analysis/tools/tasks/demo.py b/python/lsst/analysis/tools/tasks/demo.py new file mode 100644 index 000000000..25f2e7616 --- /dev/null +++ b/python/lsst/analysis/tools/tasks/demo.py @@ -0,0 +1,29 @@ +from __future__ import annotations + +from lsst.pipe.base import connectionTypes as ct + +from .base import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask + + +class DemoConnections( + AnalysisBaseConnections, + dimensions=("visit", "band"), + defaultTemplates={"coaddName": "deep", "fakesType": "fakes_"}, +): + + data = ct.Input( + doc="CcdVisit-based DiaSource table to load from the butler", + name="{fakesType}{coaddName}Diff_assocDiaSrc", + storageClass="DataFrame", + dimensions=("visit", "band", "detector"), + deferLoad=True, + ) + + +class DemoConfig(AnalysisBaseConfig, pipelineConnections=DemoConnections): + pass + + +class DemoTask(AnalysisPipelineTask): + ConfigClass = DemoConfig + _DefaultName = "DemoAnalysis"