Coverage for python/lsst/analysis/tools/analysisMetrics/skyFluxStatisticMetrics.py: 48%

23 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-16 01:27 -0800

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/>. 

21from __future__ import annotations 

22 

23__all__ = ("SkyFluxStatisticMetric",) 

24 

25from ..actions.scalar.scalarActions import MeanAction, MedianAction, SigmaMadAction, StdevAction 

26from ..actions.vector.selectors import SkyObjectSelector, SkySourceSelector 

27from ..interfaces import AnalysisMetric 

28 

29 

30class 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. 

35 """ 

36 

37 fluxType: str = "ap09Flux" 

38 

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}") 

47 

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: 

61 self.process.calculateActions.medianSky = MedianAction(vectorKey=name) 

62 self.process.calculateActions.meanSky = MeanAction(vectorKey=name) 

63 self.process.calculateActions.stdevSky = StdevAction(vectorKey=name) 

64 self.process.calculateActions.sigmaMADSky = SigmaMadAction(vectorKey=name) 

65 

66 def setDefaults(self): 

67 super().setDefaults() 

68 

69 self.produce.units = { # type: ignore 

70 "medianSky": "nJy", 

71 "meanSky": "nJy", 

72 "stdevSky": "nJy", 

73 "sigmaMADSky": "nJy", 

74 }