23
23
__all__ = ("FractionFoundFakesDiaSnrMetric" , "FractionFoundFakesDiaMagMetric" )
24
24
25
25
import numpy as np
26
- from lsst .pex .config import Field
26
+ from lsst .pex .config import Field , ListField
27
27
28
28
from ..actions .scalar import CountAction , FracThreshold
29
- from ..actions .vector import DownselectVector , RangeSelector
29
+ from ..actions .vector import FlagSelector , MultiCriteriaDownselectVector , RangeSelector
30
30
from ..interfaces import AnalysisTool
31
31
32
32
@@ -44,33 +44,81 @@ class FractionFoundFakesDiaSnrMetric(AnalysisTool):
44
44
"Flux type for fake sources metric calculation." , default = "forced_base_PsfFlux_instFlux"
45
45
)
46
46
47
+ fakeFlagsWhenTrue = ListField [str ](
48
+ "Flags for fake source cleaning before metrics calculation." , default = []
49
+ )
50
+
51
+ fakeFlagsWhenFalse = ListField [str ](
52
+ "Flags for fake source cleaning before metrics calculation." ,
53
+ default = [
54
+ "forced_base_PixelFlags_flag_bad" ,
55
+ "forced_base_LocalBackground_flag" ,
56
+ "forced_base_PixelFlags_flag_interpolated" ,
57
+ "forced_base_PixelFlags_flag_edgeCenter" ,
58
+ ],
59
+ )
60
+
47
61
def setDefaults (self ):
48
62
super ().setDefaults ()
49
63
50
64
def finalize (self ):
51
65
# There is no need to calculate the SNR as it is already estimated
52
66
# Select the fake sources using their SNR values for the given range
53
67
# 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
- ),
68
+ self .process .filterActions .fakeSourcesDiaSrcId = MultiCriteriaDownselectVector (
69
+ vectorKey = "diaSourceId"
70
+ )
71
+
72
+ self .process .filterActions .fakeSourcesDiaSrcId .selectors .snrange = RangeSelector (
73
+ vectorKey = f"{ self .fluxType } _SNR" , maximum = self .snrMax , minimum = self .snrMin
74
+ )
75
+
76
+ self .process .filterActions .fakeSourcesDiaSrcId .selectors .fakeFlags = FlagSelector (
77
+ selectWhenFalse = self .fakeFlagsWhenFalse , selectWhenTrue = self .fakeFlagsWhenTrue
59
78
)
60
79
61
80
self .process .calculateActions .numTotalFakeSources = CountAction (vectorKey = "fakeSourcesDiaSrcId" )
62
81
63
82
self .process .calculateActions .numFoundFakeSources = CountAction (
64
83
vectorKey = "fakeSourcesDiaSrcId" , op = "gt" , threshold = 0
65
84
)
85
+
66
86
self .process .calculateActions .fractionFoundFakesDiaAll = FracThreshold (
67
87
vectorKey = "fakeSourcesDiaSrcId" , op = "gt" , threshold = 0
68
88
)
89
+
90
+ self .process .filterActions .fakeSourcesAssocDiaSrcId = MultiCriteriaDownselectVector (
91
+ vectorKey = "isAssocDiaSource"
92
+ )
93
+
94
+ self .process .filterActions .fakeSourcesAssocDiaSrcId .selectors .snrange = RangeSelector (
95
+ vectorKey = f"{ self .fluxType } _SNR" , maximum = self .snrMax , minimum = self .snrMin
96
+ )
97
+
98
+ self .process .filterActions .fakeSourcesAssocDiaSrcId .selectors .fakeFlags = FlagSelector (
99
+ selectWhenFalse = self .fakeFlagsWhenFalse , selectWhenTrue = self .fakeFlagsWhenTrue
100
+ )
101
+
102
+ self .process .calculateActions .numTotalFakeAssocSources = CountAction (
103
+ vectorKey = "fakeSourcesAssocDiaSrcId"
104
+ )
105
+
106
+ self .process .calculateActions .numFoundFakeAssocSources = CountAction (
107
+ vectorKey = "fakeSourcesAssocDiaSrcId" , op = "gt" , threshold = 0
108
+ )
109
+
110
+ self .process .calculateActions .fractionFoundFakesAssocDiaAll = FracThreshold (
111
+ vectorKey = "fakeSourcesAssocDiaSrcId" , op = "gt" , threshold = 0
112
+ )
113
+
69
114
# the units for the quantity (count, an astropy quantity)
70
115
self .produce .metric .units = {
71
116
"numTotalFakeSources" : "ct" ,
72
117
"numFoundFakeSources" : "ct" ,
73
118
"fractionFoundFakesDiaAll" : "" ,
119
+ "numTotalFakeAssocSources" : "ct" ,
120
+ "numFoundFakeAssocSources" : "ct" ,
121
+ "fractionFoundFakesAssocDiaAll" : "" ,
74
122
}
75
123
76
124
@@ -84,24 +132,74 @@ class FractionFoundFakesDiaMagMetric(AnalysisTool):
84
132
85
133
magMax = Field [float ](doc = "Maximum magnitude for fake sources metric calculation." , default = 22 )
86
134
135
+ fakeFlagsWhenTrue = ListField [str ](
136
+ "Flags for fake source cleaning before metrics calculation." , default = []
137
+ )
138
+
139
+ fakeFlagsWhenFalse = ListField [str ](
140
+ "Flags for fake source cleaning before metrics calculation." ,
141
+ default = [
142
+ "forced_base_PixelFlags_flag_interpolated" ,
143
+ "forced_base_LocalBackground_flag" ,
144
+ "forced_base_PixelFlags_flag_bad" ,
145
+ "forced_base_PixelFlags_flag_edgeCenter" ,
146
+ ],
147
+ )
148
+
87
149
def finalize (self ):
88
150
# 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 ),
151
+ self .process .filterActions .fakeSourcesDiaSrcId = MultiCriteriaDownselectVector (
152
+ vectorKey = "diaSourceId"
153
+ )
154
+
155
+ self .process .filterActions .fakeSourcesDiaSrcId .selectors .magrange = RangeSelector (
156
+ vectorKey = "mag" , maximum = self .magMax , minimum = self .magMin
157
+ )
158
+
159
+ self .process .filterActions .fakeSourcesDiaSrcId .selectors .fakeFlags = FlagSelector (
160
+ selectWhenFalse = self .fakeFlagsWhenFalse , selectWhenTrue = self .fakeFlagsWhenTrue
92
161
)
93
162
94
163
self .process .calculateActions .numTotalFakeSources = CountAction (vectorKey = "fakeSourcesDiaSrcId" )
95
164
96
165
self .process .calculateActions .numFoundFakeSources = CountAction (
97
166
vectorKey = "fakeSourcesDiaSrcId" , op = "gt" , threshold = 0
98
167
)
168
+
99
169
self .process .calculateActions .fractionFoundFakesDiaAll = FracThreshold (
100
170
vectorKey = "fakeSourcesDiaSrcId" , op = "gt" , threshold = 0
101
171
)
172
+
173
+ self .process .filterActions .fakeSourcesAssocDiaSrcId = MultiCriteriaDownselectVector (
174
+ vectorKey = "isAssocDiaSource"
175
+ )
176
+
177
+ self .process .filterActions .fakeSourcesAssocDiaSrcId .selectors .magrange = RangeSelector (
178
+ vectorKey = "mag" , maximum = self .magMax , minimum = self .magMin
179
+ )
180
+
181
+ self .process .filterActions .fakeSourcesAssocDiaSrcId .selectors .fakeFlags = FlagSelector (
182
+ selectWhenFalse = self .fakeFlagsWhenFalse , selectWhenTrue = self .fakeFlagsWhenTrue
183
+ )
184
+
185
+ self .process .calculateActions .numTotalFakeAssocSources = CountAction (
186
+ vectorKey = "fakeSourcesAssocDiaSrcId"
187
+ )
188
+
189
+ self .process .calculateActions .numFoundFakeAssocSources = CountAction (
190
+ vectorKey = "fakeSourcesAssocDiaSrcId" , op = "gt" , threshold = 0
191
+ )
192
+
193
+ self .process .calculateActions .fractionFoundFakesAssocDiaAll = FracThreshold (
194
+ vectorKey = "fakeSourcesAssocDiaSrcId" , op = "gt" , threshold = 0
195
+ )
196
+
102
197
# the units for the quantity (count, an astropy quantity)
103
198
self .produce .metric .units = {
104
199
"numTotalFakeSources" : "ct" ,
105
200
"numFoundFakeSources" : "ct" ,
106
201
"fractionFoundFakesDiaAll" : "" ,
202
+ "numTotalFakeAssocSources" : "ct" ,
203
+ "numFoundFakeAssocSources" : "ct" ,
204
+ "fractionFoundFakesAssocDiaAll" : "" ,
107
205
}
0 commit comments