2424
2525from ..actions .scalar .scalarActions import MeanAction , MedianAction , SigmaMadAction , StdevAction
2626from ..actions .vector .selectors import SkyObjectSelector , SkySourceSelector
27+ from ..analysisParts .coaddVisit import CoaddVisitConfig
2728from ..interfaces import AnalysisMetric
2829
2930
30- class SkyFluxStatisticMetric (AnalysisMetric ):
31- """Calculate sky flux statistics. This uses the 9-pixel aperture flux for
32- sky sources/objects, and returns multiple statistics on the measured
33- fluxes. Note that either visitContext (measurement on sourceTable) or
34- coaddContext (measurement on objectTable) must be specified.
31+ class SkyFluxStatisticMetric (AnalysisMetric , CoaddVisitConfig ):
32+ """Calculate sky flux statistics.
33+
34+ This uses the 9-pixel aperture flux for sky sources/objects, and returns
35+ multiple statistics on the measured fluxes. Note that self.context must be
36+ set to "visit" (for measurement on sourceTables) or "coadd"
37+ (for measurement on objectTables).
3538 """
3639
3740 fluxType : str = "ap09Flux"
3841
39- def visitContext (self ) -> None :
40- self .prep .selectors .skySourceSelector = SkySourceSelector ()
41- self ._setActions (f"{ self .fluxType } " )
42-
43- def coaddContext (self ) -> None :
44- self .prep .selectors .skyObjectSelector = SkyObjectSelector ()
45- self .prep .selectors .skyObjectSelector .bands = []
46- self ._setActions (f"{{band}}_{ self .fluxType } " )
42+ def _setActions (self ) -> None :
43+ if self .context == "coadd" :
44+ name = f"{{band}}_{ self .fluxType } "
45+ self .prep .selectors .skyObjectSelector = SkyObjectSelector ()
46+ self .prep .selectors .skyObjectSelector .bands = []
4747
48- # Need to pass a mapping of new names so the default names get the
49- # band prepended. Otherwise, each subsequent band's metric will
50- # overwrite the current one (e.g., running with g, r bands without
51- # this, you would get "meanSky," "meanSky"; with it: "g_meanSky,"
52- # "r_meanSky").
53- self .produce .newNames = {
54- "medianSky" : "{band}_medianSky" ,
55- "meanSky" : "{band}_meanSky" ,
56- "stdevSky" : "{band}_stdevSky" ,
57- "sigmaMADSky" : "{band}_sigmaMADSky" ,
58- }
59-
60- def _setActions (self , name : str ) -> None :
48+ # Need to pass a mapping of new names so the default names get the
49+ # band prepended. Otherwise, each subsequent band's metric will
50+ # overwrite the current one (e.g., running with g, r bands without
51+ # this, you would get "meanSky," "meanSky"; with it: "g_meanSky,"
52+ # "r_meanSky").
53+ self .produce .newNames = {
54+ "medianSky" : "{band}_medianSky" ,
55+ "meanSky" : "{band}_meanSky" ,
56+ "stdevSky" : "{band}_stdevSky" ,
57+ "sigmaMADSky" : "{band}_sigmaMADSky" ,
58+ }
59+ elif self .context == "visit" :
60+ name = f"{ self .fluxType } "
61+ self .prep .selectors .skySourceSelector = SkySourceSelector ()
62+ else :
63+ raise ValueError (f"Unsupported { self .context = } " )
6164 self .process .calculateActions .medianSky = MedianAction (vectorKey = name )
6265 self .process .calculateActions .meanSky = MeanAction (vectorKey = name )
6366 self .process .calculateActions .stdevSky = StdevAction (vectorKey = name )
@@ -72,3 +75,8 @@ def setDefaults(self):
7275 "stdevSky" : "nJy" ,
7376 "sigmaMADSky" : "nJy" ,
7477 }
78+
79+ def validate (self ):
80+ super ().validate ()
81+ if not hasattr (self .process .calculateActions , "medianSky" ):
82+ self ._setActions ()
0 commit comments