Coverage for python/lsst/analysis/tools/atools/astrometryWithReference.py: 31%

83 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-06 04:18 -0700

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__ = ( 

24 "TargetRefCatDeltaRAScatterPlot", 

25 "TargetRefCatDeltaDecScatterPlot", 

26 "TargetRefCatDeltaRASkyPlot", 

27 "TargetRefCatDeltaDecSkyPlot", 

28) 

29 

30from lsst.pex.config import Field 

31 

32from ..actions.plot.scatterplotWithTwoHists import ScatterPlotStatsAction, ScatterPlotWithTwoHists 

33from ..actions.plot.skyPlot import SkyPlot 

34from ..actions.vector import ( 

35 ConvertFluxToMag, 

36 ConvertUnits, 

37 DownselectVector, 

38 LoadVector, 

39 RAcosDec, 

40 SnSelector, 

41 StarSelector, 

42 SubtractVector, 

43 VectorSelector, 

44) 

45from ..interfaces import AnalysisTool 

46from .genericPrep import CoaddPrep, VisitPrep 

47 

48 

49class TargetRefCatDelta(AnalysisTool): 

50 """Plot the difference in milliseconds between a target catalog and a 

51 reference catalog for the coordinate set in `setDefaults`. 

52 """ 

53 

54 parameterizedBand = Field[bool]( 

55 doc="Does this AnalysisTool support band as a name parameter", default=True 

56 ) 

57 

58 def coaddContext(self) -> None: 

59 self.prep = CoaddPrep() 

60 self.process.buildActions.starSelector.vectorKey = "{band}_extendedness" 

61 self.process.buildActions.mags = ConvertFluxToMag(vectorKey="{band}_psfFlux") 

62 self.process.filterActions.psfFlux = DownselectVector( 

63 vectorKey="{band}_psfFlux", selector=VectorSelector(vectorKey="starSelector") 

64 ) 

65 self.process.filterActions.psfFluxErr = DownselectVector( 

66 vectorKey="{band}_psfFluxErr", selector=VectorSelector(vectorKey="starSelector") 

67 ) 

68 

69 def visitContext(self) -> None: 

70 self.parameterizedBand = False 

71 self.prep = VisitPrep() 

72 self.process.buildActions.starSelector.vectorKey = "extendedness" 

73 self.process.buildActions.mags = ConvertFluxToMag(vectorKey="psfFlux") 

74 self.process.filterActions.psfFlux = DownselectVector( 

75 vectorKey="psfFlux", selector=VectorSelector(vectorKey="starSelector") 

76 ) 

77 self.process.filterActions.psfFluxErr = DownselectVector( 

78 vectorKey="psfFluxErr", selector=VectorSelector(vectorKey="starSelector") 

79 ) 

80 

81 def setDefaults(self, coordinate): 

82 super().setDefaults() 

83 

84 self.process.buildActions.starSelector = StarSelector() 

85 self.process.buildActions.astromDiff = ConvertUnits( 

86 buildAction=SubtractVector, inUnit="degree", outUnit="milliarcsecond" 

87 ) 

88 

89 self.process.filterActions.xStars = DownselectVector( 

90 vectorKey="mags", selector=VectorSelector(vectorKey="starSelector") 

91 ) 

92 self.process.filterActions.yStars = DownselectVector( 

93 vectorKey="astromDiff", selector=VectorSelector(vectorKey="starSelector") 

94 ) 

95 

96 self.process.calculateActions.stars = ScatterPlotStatsAction(vectorKey="yStars") 

97 self.process.calculateActions.stars.lowSNSelector.fluxType = "psfFlux" 

98 self.process.calculateActions.stars.highSNSelector.fluxType = "psfFlux" 

99 self.process.calculateActions.stars.fluxType = "psfFlux" 

100 

101 self.produce.plot = ScatterPlotWithTwoHists() 

102 

103 self.produce.plot.plotTypes = ["stars"] 

104 self.produce.plot.xAxisLabel = "PSF Magnitude (mag)" 

105 self.produce.plot.yAxisLabel = f"${coordinate}_{{target}} - {coordinate}_{{ref}}$ (marcsec)" 

106 self.produce.plot.magLabel = "PSF Magnitude (mag)" 

107 

108 

109class TargetRefCatDeltaRAScatterPlot(TargetRefCatDelta): 

110 """Plot the difference in milliseconds between the RA of a target catalog 

111 and a reference catalog 

112 """ 

113 

114 def setDefaults(self): 

115 super().setDefaults(coordinate="RA") 

116 self.process.buildActions.astromDiff.buildAction.actionA = RAcosDec( 

117 raKey="coord_ra_target", decKey="coord_dec_ref" 

118 ) 

119 self.process.buildActions.astromDiff.buildAction.actionB = RAcosDec( 

120 raKey="coord_ra_ref", decKey="coord_dec_ref" 

121 ) 

122 

123 

124class TargetRefCatDeltaDecScatterPlot(TargetRefCatDelta): 

125 """Plot the difference in milliseconds between the Dec of a target catalog 

126 and a reference catalog 

127 """ 

128 

129 def setDefaults(self): 

130 super().setDefaults(coordinate="Dec") 

131 self.process.buildActions.astromDiff.buildAction.actionA = LoadVector(vectorKey="coord_dec_target") 

132 self.process.buildActions.astromDiff.buildAction.actionB = LoadVector(vectorKey="coord_dec_ref") 

133 

134 

135class TargetRefCatDeltaSkyPlot(AnalysisTool): 

136 """Base class for plotting the RA/Dec distribution of stars, with the 

137 difference between the RA or Dec of the target and reference catalog as 

138 the color. 

139 """ 

140 

141 parameterizedBand = Field[bool]( 

142 doc="Does this AnalysisTool support band as a name parameter", default=True 

143 ) 

144 

145 def coaddContext(self) -> None: 

146 self.prep = CoaddPrep() 

147 

148 self.process.buildActions.starStatMask = SnSelector() 

149 self.process.buildActions.starStatMask.fluxType = "{band}_psfFlux" 

150 

151 def visitContext(self) -> None: 

152 self.parameterizedBand = False 

153 self.prep = VisitPrep() 

154 

155 self.process.buildActions.starStatMask = SnSelector() 

156 self.process.buildActions.starStatMask.fluxType = "psfFlux" 

157 

158 def setDefaults(self, coordinate): 

159 super().setDefaults() 

160 

161 self.process.buildActions.zStars = ConvertUnits( 

162 buildAction=SubtractVector, inUnit="degree", outUnit="milliarcsecond" 

163 ) 

164 self.process.buildActions.xStars = LoadVector() 

165 self.process.buildActions.xStars.vectorKey = "coord_ra_target" 

166 self.process.buildActions.yStars = LoadVector() 

167 self.process.buildActions.yStars.vectorKey = "coord_dec_target" 

168 

169 self.produce = SkyPlot() 

170 self.produce.plotTypes = ["stars"] 

171 self.produce.plotName = f"astromDiffSky_{coordinate}" 

172 self.produce.xAxisLabel = "R.A. (degrees)" 

173 self.produce.yAxisLabel = "Dec. (degrees)" 

174 self.produce.zAxisLabel = f"${coordinate}_{{target}} - {coordinate}_{{ref}}$ (marcsec)" 

175 self.produce.plotOutlines = False 

176 

177 

178class TargetRefCatDeltaRASkyPlot(TargetRefCatDeltaSkyPlot): 

179 """Plot the difference in milliseconds between the RA of a target catalog 

180 and a reference catalog as a function of RA and Dec. 

181 """ 

182 

183 def setDefaults(self): 

184 super().setDefaults(coordinate="RA") 

185 self.process.buildActions.zStars.buildAction.actionA = RAcosDec( 

186 raKey="coord_ra_target", decKey="coord_dec_ref" 

187 ) 

188 self.process.buildActions.zStars.buildAction.actionB = RAcosDec( 

189 raKey="coord_ra_ref", decKey="coord_dec_ref" 

190 ) 

191 

192 

193class TargetRefCatDeltaDecSkyPlot(TargetRefCatDeltaSkyPlot): 

194 """Plot the difference in milliseconds between the Dec of a target catalog 

195 and a reference catalog as a function of RA and Dec. 

196 """ 

197 

198 def setDefaults(self): 

199 super().setDefaults(coordinate="Dec") 

200 

201 self.process.buildActions.zStars.buildAction.actionA = LoadVector(vectorKey="coord_dec_target") 

202 

203 self.process.buildActions.zStars.buildAction.actionB = LoadVector(vectorKey="coord_dec_ref")