Skip to content

Commit e25f21d

Browse files
authored
Merge pull request #153 from lsst/tickets/DM-39900
DM-39900: Develop improved metrics for completeness based on injected sources
2 parents 8ffc5d5 + 2b85630 commit e25f21d

File tree

6 files changed

+284
-0
lines changed

6 files changed

+284
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
description: |
2+
AP plots and metrics to assess quality in Prompt Processing using Fake sources
3+
parameters:
4+
# Note that these parameter names are shared with ApPipe, and are overwritten
5+
# by changes in the values there.
6+
coaddName: goodSeeing
7+
fakesType: 'fakes_'
8+
9+
tasks:
10+
analyzeDiaFakesDetectorVisitCore:
11+
class: lsst.analysis.tools.tasks.DiaFakesDetectorVisitAnalysisTask
12+
config:
13+
atools.numFoundFakesDiaAllMetric: FractionFoundFakesDiaSnrMetric
14+
atools.numFoundFakesDiaAllMetric.snrMin: 0
15+
# atools.numFoundFakesDiaAllMetric.snrMax: NO MAXIMUM: all the fakes
16+
# Bins of SNR
17+
atools.numFoundFakesDiaSNR0t3Metric: FractionFoundFakesDiaSnrMetric
18+
atools.numFoundFakesDiaSNR0t3Metric.snrMin: 0
19+
atools.numFoundFakesDiaSNR0t3Metric.snrMax: 3
20+
atools.numFoundFakesDiaSNR3t6Metric: FractionFoundFakesDiaSnrMetric
21+
atools.numFoundFakesDiaSNR3t6Metric.snrMin: 3
22+
atools.numFoundFakesDiaSNR3t6Metric.snrMax: 6
23+
atools.numFoundFakesDiaSNR6t8Metric: FractionFoundFakesDiaSnrMetric
24+
atools.numFoundFakesDiaSNR6t8Metric.snrMin: 6
25+
atools.numFoundFakesDiaSNR6t8Metric.snrMax: 8
26+
atools.numFoundFakesDiaSNR8t10Metric: FractionFoundFakesDiaSnrMetric
27+
atools.numFoundFakesDiaSNR8t10Metric.snrMin: 8
28+
atools.numFoundFakesDiaSNR8t10Metric.snrMax: 10
29+
atools.numFoundFakesDiaSNR10t20Metric: FractionFoundFakesDiaSnrMetric
30+
atools.numFoundFakesDiaSNR10t20Metric.snrMin: 10
31+
atools.numFoundFakesDiaSNR10t20Metric.snrMax: 20
32+
# From 6 to infinity
33+
atools.numFoundFakesDiaSNR6tInfMetric: FractionFoundFakesDiaSnrMetric
34+
atools.numFoundFakesDiaSNR6tInfMetric.snrMin: 6
35+
connections.outputName: diaFakesDetectorVisitCore
36+
python: |
37+
from lsst.analysis.tools.atools import FractionFoundFakesDiaSnrMetric
38+
analyzeDiaFakesVisitCore:
39+
class: lsst.analysis.tools.tasks.DiaFakesVisitAnalysisTask
40+
config:
41+
atools.numFoundFakesDiaAllMetric: FractionFoundFakesDiaSnrMetric
42+
atools.numFoundFakesDiaAllMetric.snrMin: 0
43+
# atools.numFoundFakesDiaAllMetric.snrMax: NO MAXIMUM: all the fakes
44+
# Bins of SNR
45+
atools.numFoundFakesDiaSNR0t3Metric: FractionFoundFakesDiaSnrMetric
46+
atools.numFoundFakesDiaSNR0t3Metric.snrMin: 0
47+
atools.numFoundFakesDiaSNR0t3Metric.snrMax: 3
48+
atools.numFoundFakesDiaSNR3t6Metric: FractionFoundFakesDiaSnrMetric
49+
atools.numFoundFakesDiaSNR3t6Metric.snrMin: 3
50+
atools.numFoundFakesDiaSNR3t6Metric.snrMax: 6
51+
atools.numFoundFakesDiaSNR6t8Metric: FractionFoundFakesDiaSnrMetric
52+
atools.numFoundFakesDiaSNR6t8Metric.snrMin: 6
53+
atools.numFoundFakesDiaSNR6t8Metric.snrMax: 8
54+
atools.numFoundFakesDiaSNR8t10Metric: FractionFoundFakesDiaSnrMetric
55+
atools.numFoundFakesDiaSNR8t10Metric.snrMin: 8
56+
atools.numFoundFakesDiaSNR8t10Metric.snrMax: 10
57+
atools.numFoundFakesDiaSNR10t20Metric: FractionFoundFakesDiaSnrMetric
58+
atools.numFoundFakesDiaSNR10t20Metric.snrMin: 10
59+
atools.numFoundFakesDiaSNR10t20Metric.snrMax: 20
60+
# From 6 to infinity
61+
atools.numFoundFakesDiaSNR6tInfMetric: FractionFoundFakesDiaSnrMetric
62+
atools.numFoundFakesDiaSNR6tInfMetric.snrMin: 6
63+
connections.data: "fakes_{coaddName}Diff_matchDiaSourceTable"
64+
connections.outputName: diaFakesVisitCore
65+
python: |
66+
from lsst.analysis.tools.atools import FractionFoundFakesDiaSnrMetric

python/lsst/analysis/tools/atools/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .coveragePlots import *
88
from .deblenderMetric import *
99
from .deltaSkyCorr import *
10+
from .diaFakeMetrics import *
1011
from .diaSolarSystemObjectMetrics import *
1112
from .diaSourceMetrics import *
1213
from .diaSourceTableTractMetrics import *
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# This file is part of analysis_tools.
2+
#
3+
# Developed for the LSST Data Management System.
4+
# This product includes software developed by the LSST Project
5+
# (https://www.lsst.org).
6+
# See the COPYRIGHT file at the top-level directory of this distribution
7+
# for details of code ownership.
8+
#
9+
# This program is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation, either version 3 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
21+
from __future__ import annotations
22+
23+
__all__ = ("FractionFoundFakesDiaSnrMetric", "FractionFoundFakesDiaMagMetric")
24+
25+
import numpy as np
26+
from lsst.pex.config import Field
27+
28+
from ..actions.scalar import CountAction, FracThreshold
29+
from ..actions.vector import DownselectVector, RangeSelector
30+
from ..interfaces import AnalysisTool
31+
32+
33+
class FractionFoundFakesDiaSnrMetric(AnalysisTool):
34+
"""Calculate the fraction of fake DIA Sources found within the
35+
given SNR range"""
36+
37+
parameterizedBand: bool = False
38+
39+
snrMin = Field[float](doc="Minimum SNR for fake sources metric calculation.", default=0)
40+
41+
snrMax = Field[float](doc="Maximum SNR for fake sources metric calculation.", default=np.inf)
42+
43+
fluxType = Field[str](
44+
"Flux type for fake sources metric calculation.", default="forced_base_PsfFlux_instFlux"
45+
)
46+
47+
def setDefaults(self):
48+
super().setDefaults()
49+
50+
def finalize(self):
51+
# There is no need to calculate the SNR as it is already estimated
52+
# Select the fake sources using their SNR values for the given range
53+
# and flux type estimation
54+
self.process.filterActions.fakeSourcesDiaSrcId = DownselectVector(
55+
vectorKey="diaSourceId",
56+
selector=RangeSelector(
57+
vectorKey=f"{self.fluxType}_SNR", maximum=self.snrMax, minimum=self.snrMin
58+
),
59+
)
60+
61+
self.process.calculateActions.numTotalFakeSources = CountAction(vectorKey="fakeSourcesDiaSrcId")
62+
63+
self.process.calculateActions.numFoundFakeSources = CountAction(
64+
vectorKey="fakeSourcesDiaSrcId", op="gt", threshold=0
65+
)
66+
self.process.calculateActions.fractionFoundFakesDiaAll = FracThreshold(
67+
vectorKey="fakeSourcesDiaSrcId", op="gt", threshold=0
68+
)
69+
# the units for the quantity (count, an astropy quantity)
70+
self.produce.metric.units = {
71+
"numTotalFakeSources": "ct",
72+
"numFoundFakeSources": "ct",
73+
"fractionFoundFakesDiaAll": "",
74+
}
75+
76+
77+
class FractionFoundFakesDiaMagMetric(AnalysisTool):
78+
"""Calculate the fraction of fake DIA Sources found within the given
79+
magnitude range"""
80+
81+
parameterizedBand: bool = False
82+
83+
magMin = Field[float](doc="Minimum magnitude for fake sources metric calculation.", default=18)
84+
85+
magMax = Field[float](doc="Maximum magnitude for fake sources metric calculation.", default=22)
86+
87+
def finalize(self):
88+
# Selecting the fake sources using the truth magnitude values.
89+
self.process.filterActions.fakeSourcesDiaSrcId = DownselectVector(
90+
vectorKey="diaSourceId",
91+
selector=RangeSelector(vectorKey="mag", maximum=self.magMax, minimum=self.magMin),
92+
)
93+
94+
self.process.calculateActions.numTotalFakeSources = CountAction(vectorKey="fakeSourcesDiaSrcId")
95+
96+
self.process.calculateActions.numFoundFakeSources = CountAction(
97+
vectorKey="fakeSourcesDiaSrcId", op="gt", threshold=0
98+
)
99+
self.process.calculateActions.fractionFoundFakesDiaAll = FracThreshold(
100+
vectorKey="fakeSourcesDiaSrcId", op="gt", threshold=0
101+
)
102+
# the units for the quantity (count, an astropy quantity)
103+
self.produce.metric.units = {
104+
"numTotalFakeSources": "ct",
105+
"numFoundFakeSources": "ct",
106+
"fractionFoundFakesDiaAll": "",
107+
}

python/lsst/analysis/tools/tasks/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from .calibrationAnalysis import *
77
from .catalogMatch import *
88
from .ccdVisitTableAnalysis import *
9+
from .diaFakesDetectorVisitAnalysis import *
10+
from .diaFakesVisitAnalysis import *
911
from .diaObjectDetectorVisitAnalysis import *
1012
from .diaSourceDetectorVisitAnalysis import *
1113
from .diaSourceTableTractAnalysis import *
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This file is part of analysis_tools.
2+
#
3+
# Developed for the LSST Data Management System.
4+
# This product includes software developed by the LSST Project
5+
# (https://www.lsst.org).
6+
# See the COPYRIGHT file at the top-level directory of this distribution
7+
# for details of code ownership.
8+
#
9+
# This program is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation, either version 3 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
21+
from __future__ import annotations
22+
23+
__all__ = (
24+
"DiaFakesDetectorVisitAnalysisConfig",
25+
"DiaFakesDetectorVisitAnalysisTask",
26+
)
27+
28+
from lsst.pipe.base.connectionTypes import Input
29+
30+
from ..interfaces import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask
31+
32+
33+
class DiaFakesDetectorVisitAnalysisConnections(
34+
AnalysisBaseConnections,
35+
dimensions=("instrument", "visit", "detector"),
36+
defaultTemplates={"coaddName": "goodSeeing", "fakesType": "fakes_"},
37+
):
38+
data = Input(
39+
doc="CcdVisit-based Matched fake to load from the butler",
40+
name="{fakesType}{coaddName}Diff_matchDiaSrc",
41+
storageClass="DataFrame",
42+
deferLoad=True,
43+
dimensions=("instrument", "visit", "detector"),
44+
)
45+
46+
47+
class DiaFakesDetectorVisitAnalysisConfig(
48+
AnalysisBaseConfig, pipelineConnections=DiaFakesDetectorVisitAnalysisConnections
49+
):
50+
pass
51+
52+
53+
class DiaFakesDetectorVisitAnalysisTask(AnalysisPipelineTask):
54+
ConfigClass = DiaFakesDetectorVisitAnalysisConfig
55+
_DefaultName = "DiaFakesDetectorVisitAnalysis"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This file is part of analysis_tools.
2+
#
3+
# Developed for the LSST Data Management System.
4+
# This product includes software developed by the LSST Project
5+
# (https://www.lsst.org).
6+
# See the COPYRIGHT file at the top-level directory of this distribution
7+
# for details of code ownership.
8+
#
9+
# This program is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation, either version 3 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
21+
from __future__ import annotations
22+
23+
__all__ = (
24+
"DiaFakesVisitAnalysisConfig",
25+
"DiaFakesVisitAnalysisTask",
26+
)
27+
28+
from lsst.pipe.base.connectionTypes import Input
29+
30+
from ..interfaces import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask
31+
32+
33+
class DiaFakesVisitAnalysisConnections(
34+
AnalysisBaseConnections,
35+
dimensions=("instrument", "visit"),
36+
defaultTemplates={"coaddName": "goodSeeing", "fakesType": "fakes_"},
37+
):
38+
data = Input(
39+
doc="CcdVisit-based Matched fake to load from the butler",
40+
name="{fakesType}{coaddName}Diff_matchDiaSourceTable",
41+
storageClass="DataFrame",
42+
deferLoad=True,
43+
dimensions=("instrument", "visit"),
44+
)
45+
46+
47+
class DiaFakesVisitAnalysisConfig(AnalysisBaseConfig, pipelineConnections=DiaFakesVisitAnalysisConnections):
48+
pass
49+
50+
51+
class DiaFakesVisitAnalysisTask(AnalysisPipelineTask):
52+
ConfigClass = DiaFakesVisitAnalysisConfig
53+
_DefaultName = "FakesDiaVisitAnalysis"

0 commit comments

Comments
 (0)