Coverage for python/lsst/analysis/tools/analysisParts/photometricRepeatability.py: 32%

31 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-08 04:01 -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__ = ("StellarPhotometricRepeatabilityMixin",) 

24 

25from lsst.pex.config import Field 

26 

27from ..actions.scalar.scalarActions import CountAction, FracThreshold, MedianAction 

28from ..actions.vector import ( 

29 BandSelector, 

30 MagColumnNanoJansky, 

31 MultiCriteriaDownselectVector, 

32 PerGroupStatistic, 

33 Sn, 

34 ThresholdSelector, 

35) 

36from ..interfaces import AnalysisTool 

37 

38 

39class StellarPhotometricRepeatabilityMixin(AnalysisTool): 

40 """Compute photometric repeatability from multiple measurements of a set of 

41 stars. First, a set of per-source quality criteria are applied. Second, 

42 the individual source measurements are grouped together by object index 

43 and per-group quantities are computed (e.g., a representative S/N for the 

44 group based on the median of associated per-source measurements). Third, 

45 additional per-group criteria are applied. Fourth, summary statistics are 

46 computed for the filtered groups. 

47 """ 

48 

49 fluxType = Field[str](doc="Flux type to calculate repeatability with", default="psfFlux") 

50 PA2Value = Field[float]( 

51 doc="Used to compute the percent of individual measurements that deviate by more than PA2Value" 

52 "from the mean of each measurement (PF1). Units of PA2Value are mmag.", 

53 default=15.0, 

54 ) 

55 

56 def setDefaults(self): 

57 super().setDefaults() 

58 

59 # Apply per-source selection criteria 

60 self.prep.selectors.bandSelector = BandSelector() 

61 

62 # Compute per-group quantities 

63 self.process.buildActions.perGroupSn = PerGroupStatistic() 

64 self.process.buildActions.perGroupSn.buildAction = Sn(fluxType=f"{self.fluxType}") 

65 self.process.buildActions.perGroupSn.func = "median" 

66 self.process.buildActions.perGroupExtendedness = PerGroupStatistic() 

67 self.process.buildActions.perGroupExtendedness.buildAction.vectorKey = "extendedness" 

68 self.process.buildActions.perGroupExtendedness.func = "median" 

69 self.process.buildActions.perGroupCount = PerGroupStatistic() 

70 self.process.buildActions.perGroupCount.buildAction.vectorKey = f"{self.fluxType}" 

71 self.process.buildActions.perGroupCount.func = "count" 

72 # Use mmag units 

73 self.process.buildActions.perGroupStdev = PerGroupStatistic() 

74 self.process.buildActions.perGroupStdev.buildAction = MagColumnNanoJansky( 

75 vectorKey=f"{self.fluxType}", 

76 returnMillimags=True, 

77 ) 

78 self.process.buildActions.perGroupStdev.func = "std" 

79 

80 # Filter on per-group quantities 

81 self.process.filterActions.perGroupStdevFiltered = MultiCriteriaDownselectVector( 

82 vectorKey="perGroupStdev" 

83 ) 

84 self.process.filterActions.perGroupStdevFiltered.selectors.count = ThresholdSelector( 

85 vectorKey="perGroupCount", 

86 op="ge", 

87 threshold=3, 

88 ) 

89 self.process.filterActions.perGroupStdevFiltered.selectors.sn = ThresholdSelector( 

90 vectorKey="perGroupSn", 

91 op="ge", 

92 threshold=200, 

93 ) 

94 self.process.filterActions.perGroupStdevFiltered.selectors.extendedness = ThresholdSelector( 

95 vectorKey="perGroupExtendedness", 

96 op="le", 

97 threshold=0.5, 

98 ) 

99 

100 # Compute summary statistics on filtered groups 

101 self.process.calculateActions.photRepeatStdev = MedianAction(vectorKey="perGroupStdevFiltered") 

102 self.process.calculateActions.photRepeatOutlier = FracThreshold( 

103 vectorKey="perGroupStdevFiltered", 

104 op="ge", 

105 threshold=self.PA2Value, 

106 percent=True, 

107 ) 

108 self.process.calculateActions.photRepeatNsources = CountAction(vectorKey="perGroupStdevFiltered")