Coverage for python/lsst/analysis/tools/atools/refCatMatchPlots.py: 26%

273 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-07 14:35 +0000

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 "TargetRefCatDeltaScatterPhotom", 

29 "TargetRefCatDeltaScatterAstrom", 

30 "TargetRefCatDeltaSkyPlotPhotom", 

31 "TargetRefCatDeltaPsfScatterPlot", 

32 "TargetRefCatDeltaCModelScatterPlot", 

33 "TargetRefCatDeltaCModelSkyPlot", 

34 "TargetRefCatDeltaPsfSkyPlot", 

35 "TargetRefCatDeltaRASkyVisitPlot", 

36 "TargetRefCatDeltaAp09ScatterVisitPlot", 

37 "TargetRefCatDeltaPsfScatterVisitPlot", 

38 "TargetRefCatDeltaAp09SkyVisitPlot", 

39 "TargetRefCatDeltaPsfSkyVisitPlot", 

40 "TargetRefCatDeltaDecSkyVisitPlot", 

41 "TargetRefCatDeltaRAScatterVisitPlot", 

42 "TargetRefCatDeltaDecScatterVisitPlot", 

43 "TargetRefCatDeltaMetrics", 

44) 

45 

46from lsst.pex.config import Field 

47 

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

49from ..actions.plot.skyPlot import SkyPlot 

50from ..actions.scalar.scalarActions import MedianAction, SigmaMadAction 

51from ..actions.vector import ( 

52 AngularSeparation, 

53 CoaddPlotFlagSelector, 

54 ConvertFluxToMag, 

55 ConvertUnits, 

56 DownselectVector, 

57 LoadVector, 

58 MagDiff, 

59 RAcosDec, 

60 RangeSelector, 

61 SnSelector, 

62 StarSelector, 

63 SubtractVector, 

64 VisitPlotFlagSelector, 

65) 

66from ..contexts import CoaddContext, RefMatchContext, VisitContext 

67from ..interfaces import AnalysisTool 

68 

69 

70class TargetRefCatDelta(AnalysisTool): 

71 """Plot the difference between a target catalog and a 

72 reference catalog for the quantity set in `setDefaults`. 

73 """ 

74 

75 parameterizedBand = Field[bool]( 

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

77 ) 

78 

79 def coaddContext(self) -> None: 

80 """Apply coadd options for the ref cat plots. 

81 Applies the coadd plot flag selector and sets 

82 flux types. 

83 """ 

84 self.prep.selectors.flagSelector = CoaddPlotFlagSelector() 

85 self.prep.selectors.snSelector.fluxType = "{band}_psfFlux_target" 

86 self.prep.selectors.snSelector.threshold = 200 

87 self.prep.selectors.starSelector.vectorKey = "{band}_extendedness_target" 

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

89 self.process.buildActions.starStatMask.fluxType = "{band}_psfFlux_target" 

90 self.process.buildActions.patch = LoadVector() 

91 self.process.buildActions.patch.vectorKey = "patch_target" 

92 

93 def visitContext(self) -> None: 

94 """Apply visit options for the ref cat plots. 

95 Applies the visit plot flag selector and sets 

96 the flux types. 

97 """ 

98 self.parameterizedBand = False 

99 self.prep.selectors.flagSelector = VisitPlotFlagSelector() 

100 self.prep.selectors.starSelector.vectorKey = "extendedness_target" 

101 self.prep.selectors.snSelector.fluxType = "psfFlux_target" 

102 self.prep.selectors.snSelector.threshold = 50 

103 

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

105 self.process.buildActions.starStatMask.fluxType = "psfFlux_target" 

106 self.process.buildActions.starStatMask.threshold = 200 

107 

108 def setDefaults(self): 

109 super().setDefaults() 

110 

111 self.prep.selectors.snSelector = SnSelector() 

112 self.prep.selectors.starSelector = StarSelector() 

113 

114 

115class TargetRefCatDeltaScatterAstrom(TargetRefCatDelta): 

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

117 reference catalog for the coordinate set in `setDefaults`. Plot it on 

118 a scatter plot. 

119 """ 

120 

121 def setDefaults(self): 

122 super().setDefaults() 

123 

124 self.process.buildActions.yStars = ConvertUnits( 

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

126 ) 

127 self.process.buildActions.xStars = ConvertFluxToMag() 

128 self.process.buildActions.xStars.vectorKey = "{band}_psfFlux_target" 

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

130 self.process.calculateActions.stars.lowSNSelector.fluxType = "{band}_psfFlux_target" 

131 self.process.calculateActions.stars.highSNSelector.fluxType = "{band}_psfFlux_target" 

132 self.process.calculateActions.stars.fluxType = "{band}_psfFlux_target" 

133 

134 self.produce = ScatterPlotWithTwoHists() 

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

136 self.produce.magLabel = "PSF Magnitude (mag)" 

137 self.produce.xAxisLabel = "PSF Magnitude (mag)" 

138 self.applyContext(CoaddContext) 

139 self.applyContext(RefMatchContext) 

140 

141 

142class TargetRefCatDeltaScatterAstromVisit(TargetRefCatDelta): 

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

144 reference catalog for the coordinate set in `setDefaults`. Plot it on 

145 a scatter plot. 

146 """ 

147 

148 def setDefaults(self): 

149 super().setDefaults() 

150 

151 self.process.buildActions.yStars = ConvertUnits( 

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

153 ) 

154 self.process.buildActions.xStars = ConvertFluxToMag() 

155 self.process.buildActions.xStars.vectorKey = "psfFlux_target" 

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

157 self.process.calculateActions.stars.lowSNSelector.fluxType = "psfFlux_target" 

158 self.process.calculateActions.stars.highSNSelector.fluxType = "psfFlux_target" 

159 self.process.calculateActions.stars.fluxType = "psfFlux_target" 

160 

161 self.produce = ScatterPlotWithTwoHists() 

162 self.produce.addSummaryPlot = False 

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

164 self.produce.magLabel = "PSF Magnitude (mag)" 

165 self.produce.xAxisLabel = "PSF Magnitude (mag)" 

166 self.applyContext(VisitContext) 

167 self.applyContext(RefMatchContext) 

168 

169 

170class TargetRefCatDeltaScatterPhotom(TargetRefCatDelta): 

171 """Plot the difference in millimags between a target catalog and a 

172 reference catalog for the flux type set in `setDefaults`. 

173 """ 

174 

175 def setDefaults(self): 

176 super().setDefaults() 

177 

178 self.process.buildActions.yStars = MagDiff() 

179 self.process.buildActions.yStars.col2 = "{band}_mag_ref" 

180 self.process.buildActions.yStars.fluxUnits2 = "mag(AB)" 

181 

182 self.process.buildActions.xStars = ConvertFluxToMag() 

183 self.process.buildActions.xStars.vectorKey = "{band}_psfFlux_target" 

184 

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

186 self.process.calculateActions.stars.lowSNSelector.fluxType = "{band}_psfFlux_target" 

187 self.process.calculateActions.stars.highSNSelector.fluxType = "{band}_psfFlux_target" 

188 self.process.calculateActions.stars.fluxType = "{band}_psfFlux_target" 

189 

190 self.produce = ScatterPlotWithTwoHists() 

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

192 self.produce.magLabel = "PSF Magnitude (mag)" 

193 self.produce.xAxisLabel = "PSF Magnitude (mag)" 

194 self.produce.yAxisLabel = "Output Mag - Ref Mag (mmag)" 

195 self.applyContext(CoaddContext) 

196 self.applyContext(RefMatchContext) 

197 

198 

199class TargetRefCatDeltaScatterPhotomVisit(TargetRefCatDelta): 

200 """Plot the difference in millimags between a target catalog and a 

201 reference catalog for the flux type set in `setDefaults`. 

202 """ 

203 

204 def setDefaults(self): 

205 super().setDefaults() 

206 

207 self.process.buildActions.yStars = MagDiff() 

208 self.process.buildActions.yStars.col2 = "mag_ref" 

209 self.process.buildActions.yStars.fluxUnits2 = "mag(AB)" 

210 

211 self.process.buildActions.xStars = ConvertFluxToMag() 

212 self.process.buildActions.xStars.vectorKey = "psfFlux_target" 

213 

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

215 self.process.calculateActions.stars.lowSNSelector.fluxType = "psfFlux_target" 

216 self.process.calculateActions.stars.highSNSelector.fluxType = "psfFlux_target" 

217 self.process.calculateActions.stars.fluxType = "psfFlux_target" 

218 

219 self.produce = ScatterPlotWithTwoHists() 

220 self.produce.addSummaryPlot = False 

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

222 self.produce.magLabel = "PSF Magnitude (mag)" 

223 self.produce.xAxisLabel = "PSF Magnitude (mag)" 

224 self.produce.yAxisLabel = "Output Mag - Ref Mag (mmag)" 

225 self.applyContext(VisitContext) 

226 self.applyContext(RefMatchContext) 

227 

228 

229class TargetRefCatDeltaPsfScatterPlot(TargetRefCatDeltaScatterPhotom): 

230 """Plot the difference in millimags between the PSF flux 

231 of a target catalog and a reference catalog 

232 """ 

233 

234 def setDefaults(self): 

235 super().setDefaults() 

236 

237 self.process.buildActions.yStars.col1 = "{band}_psfFlux_target" 

238 

239 

240class TargetRefCatDeltaCModelScatterPlot(TargetRefCatDeltaScatterPhotom): 

241 """Plot the difference in millimags between the CModel flux 

242 of a target catalog and a reference catalog. 

243 """ 

244 

245 def setDefaults(self): 

246 super().setDefaults() 

247 

248 self.process.buildActions.yStars.col1 = "{band}_cModelFlux_target" 

249 

250 

251class TargetRefCatDeltaPsfScatterVisitPlot(TargetRefCatDeltaScatterPhotomVisit): 

252 """Plot the difference in millimags between the PSF flux 

253 of a target catalog and a reference catalog 

254 """ 

255 

256 def setDefaults(self): 

257 super().setDefaults() 

258 

259 self.process.buildActions.yStars.col1 = "psfFlux_target" 

260 

261 

262class TargetRefCatDeltaAp09ScatterVisitPlot(TargetRefCatDeltaScatterPhotomVisit): 

263 """Plot the difference in millimags between the aper 09 flux 

264 of a target catalog and a reference catalog. 

265 """ 

266 

267 def setDefaults(self): 

268 super().setDefaults() 

269 

270 self.process.buildActions.yStars.col1 = "ap09Flux_target" 

271 

272 

273class TargetRefCatDeltaRAScatterPlot(TargetRefCatDeltaScatterAstrom): 

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

275 and a reference catalog 

276 """ 

277 

278 def setDefaults(self): 

279 super().setDefaults() 

280 self.process.buildActions.yStars.buildAction.actionA = RAcosDec( 

281 raKey="coord_ra_target", decKey="coord_dec_target" 

282 ) 

283 self.process.buildActions.yStars.buildAction.actionB = RAcosDec(raKey="ra_ref", decKey="dec_ref") 

284 

285 self.produce.yAxisLabel = "RA$_{{target}}$ - RA$_{{ref}}$ (marcsec)" 

286 

287 

288class TargetRefCatDeltaRAScatterVisitPlot(TargetRefCatDeltaScatterAstromVisit): 

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

290 and a reference catalog 

291 """ 

292 

293 def setDefaults(self): 

294 super().setDefaults() 

295 self.process.buildActions.yStars.buildAction.actionA = RAcosDec( 

296 raKey="coord_ra_target", decKey="coord_dec_target" 

297 ) 

298 self.process.buildActions.yStars.buildAction.actionB = RAcosDec(raKey="ra_ref", decKey="dec_ref") 

299 

300 self.produce.yAxisLabel = "RA$_{{target}}$ - RA$_{{ref}}$ (marcsec)" 

301 

302 

303class TargetRefCatDeltaDecScatterVisitPlot(TargetRefCatDeltaScatterAstromVisit): 

304 """Plot the difference in milliseconds between the Decs of a target catalog 

305 and a reference catalog 

306 """ 

307 

308 def setDefaults(self): 

309 super().setDefaults() 

310 self.process.buildActions.yStars.buildAction.actionA = LoadVector(vectorKey="coord_dec_target") 

311 self.process.buildActions.yStars.buildAction.actionB = LoadVector(vectorKey="dec_ref") 

312 

313 self.produce.yAxisLabel = "RA$_{{target}}$ - RA$_{{ref}}$ (marcsec)" 

314 

315 

316class TargetRefCatDeltaDecScatterPlot(TargetRefCatDeltaScatterAstrom): 

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

318 and a reference catalog 

319 """ 

320 

321 def setDefaults(self): 

322 super().setDefaults() 

323 self.process.buildActions.yStars.buildAction.actionA = LoadVector(vectorKey="coord_dec_target") 

324 self.process.buildActions.yStars.buildAction.actionB = LoadVector(vectorKey="dec_ref") 

325 

326 self.produce.yAxisLabel = "Dec$_{{target}}$ - Dec$_{{ref}}$ (marcsec)" 

327 

328 

329class TargetRefCatDeltaSkyPlot(TargetRefCatDelta): 

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

331 difference of the quantity defined in the vector key parameter between 

332 the target and reference catalog as the color. 

333 """ 

334 

335 parameterizedBand = Field[bool]( 

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

337 ) 

338 

339 def setDefaults(self): 

340 super().setDefaults() 

341 

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

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

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

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

346 

347 self.produce = SkyPlot() 

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

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

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

351 self.produce.plotOutlines = False 

352 

353 

354class TargetRefCatDeltaSkyPlotAstrom(TargetRefCatDeltaSkyPlot): 

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

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

357 the color. 

358 """ 

359 

360 def setDefaults(self): 

361 super().setDefaults() 

362 

363 self.process.buildActions.zStars = ConvertUnits( 

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

365 ) 

366 

367 self.applyContext(CoaddContext) 

368 self.applyContext(RefMatchContext) 

369 

370 self.process.buildActions.starStatMask.fluxType = "{band}_psfFlux_target" 

371 

372 

373class TargetRefCatDeltaSkyPlotAstromVisit(TargetRefCatDeltaSkyPlot): 

374 """Base class for plotting the RA/Dec distribution of stars at 

375 the visit level, with the difference between the RA or Dec of 

376 the target and reference catalog as the color. 

377 """ 

378 

379 def setDefaults(self): 

380 super().setDefaults() 

381 

382 self.process.buildActions.zStars = ConvertUnits( 

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

384 ) 

385 

386 self.applyContext(VisitContext) 

387 self.applyContext(RefMatchContext) 

388 

389 

390class TargetRefCatDeltaSkyPlotPhotomVisit(TargetRefCatDeltaSkyPlot): 

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

392 difference between the photometry of the target and reference catalog as 

393 the color. 

394 """ 

395 

396 def setDefaults(self): 

397 super().setDefaults() 

398 

399 self.process.buildActions.zStars = MagDiff() 

400 self.process.buildActions.zStars.col2 = "mag_ref" 

401 self.process.buildActions.zStars.fluxUnits2 = "mag(AB)" 

402 

403 self.produce.plotName = "photomDiffSky" 

404 self.produce.zAxisLabel = "Output Mag - Ref Mag (mmag)" 

405 self.applyContext(VisitContext) 

406 self.applyContext(RefMatchContext) 

407 

408 

409class TargetRefCatDeltaSkyPlotPhotom(TargetRefCatDeltaSkyPlot): 

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

411 difference between the photometry of the target and reference catalog as 

412 the color. 

413 """ 

414 

415 def setDefaults(self): 

416 super().setDefaults() 

417 

418 self.process.buildActions.zStars = MagDiff() 

419 self.process.buildActions.zStars.col2 = "{band}_mag_ref" 

420 self.process.buildActions.zStars.fluxUnits2 = "mag(AB)" 

421 

422 self.produce.plotName = "photomDiffSky_{band}" 

423 self.produce.zAxisLabel = "Output Mag - Ref Mag (mmag)" 

424 self.applyContext(CoaddContext) 

425 self.applyContext(RefMatchContext) 

426 

427 

428class TargetRefCatDeltaPsfSkyPlot(TargetRefCatDeltaSkyPlotPhotom): 

429 """Plot the RA/Dec distribution of stars, with the 

430 difference between the PSF photometry of the target and reference 

431 catalog as the color. 

432 """ 

433 

434 def setDefaults(self): 

435 super().setDefaults() 

436 

437 self.process.buildActions.zStars.col1 = "{band}_psfFlux_target" 

438 

439 

440class TargetRefCatDeltaPsfSkyVisitPlot(TargetRefCatDeltaSkyPlotPhotomVisit): 

441 """Plot the RA/Dec distribution of stars, with the 

442 difference between the PSF photometry of the target and reference 

443 catalog as the color. 

444 """ 

445 

446 def setDefaults(self): 

447 super().setDefaults() 

448 

449 self.process.buildActions.zStars.col1 = "psfFlux_target" 

450 

451 

452class TargetRefCatDeltaAp09SkyVisitPlot(TargetRefCatDeltaSkyPlotPhotomVisit): 

453 """Plot the RA/Dec distribution of stars, with the 

454 difference between the Ap09 photometry of the target and reference 

455 catalog as the color. 

456 """ 

457 

458 def setDefaults(self): 

459 super().setDefaults() 

460 

461 self.process.buildActions.zStars.col1 = "ap09Flux_target" 

462 

463 

464class TargetRefCatDeltaCModelSkyPlot(TargetRefCatDeltaSkyPlotPhotom): 

465 """Plot the RA/Dec distribution of stars, with the 

466 difference between the CModel photometry of the target and reference 

467 catalog as the color. 

468 """ 

469 

470 def setDefaults(self): 

471 super().setDefaults() 

472 

473 self.process.buildActions.zStars.col1 = "{band}_cModelFlux_target" 

474 

475 

476class TargetRefCatDeltaRASkyPlot(TargetRefCatDeltaSkyPlotAstrom): 

477 """Plot the RA/Dec distribution of stars, with the 

478 difference between the RA of the target and reference catalog as 

479 the color. 

480 """ 

481 

482 def setDefaults(self): 

483 super().setDefaults() 

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

485 raKey="coord_ra_target", decKey="coord_dec_target" 

486 ) 

487 self.process.buildActions.zStars.buildAction.actionB = RAcosDec(raKey="ra_ref", decKey="dec_ref") 

488 

489 self.produce.plotName = "astromDiffSky_RA" 

490 self.produce.zAxisLabel = "RA$_{{target}}$ - RA$_{{ref}}$ (marcsec)" 

491 

492 

493class TargetRefCatDeltaRASkyVisitPlot(TargetRefCatDeltaSkyPlotAstromVisit): 

494 """Plot the RA/Dec distribution of stars, with the 

495 difference between the RA of the target and reference catalog as 

496 the color. 

497 """ 

498 

499 def setDefaults(self): 

500 super().setDefaults() 

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

502 raKey="coord_ra_target", decKey="coord_dec_target" 

503 ) 

504 self.process.buildActions.zStars.buildAction.actionB = RAcosDec(raKey="ra_ref", decKey="dec_ref") 

505 self.produce.plotName = "astromDiffSky_RA" 

506 self.produce.zAxisLabel = "RA$_{{target}}$ - RA$_{{ref}}$ (marcsec)" 

507 

508 

509class TargetRefCatDeltaDecSkyVisitPlot(TargetRefCatDeltaSkyPlotAstromVisit): 

510 """Plot the RA/Dec distribution of stars, with the 

511 difference between the RA of the target and reference catalog as 

512 the color. 

513 """ 

514 

515 def setDefaults(self): 

516 super().setDefaults() 

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

518 self.process.buildActions.zStars.buildAction.actionB = LoadVector(vectorKey="dec_ref") 

519 

520 self.produce.plotName = "astromDiffSky_Dec" 

521 self.produce.zAxisLabel = "Dec$_{{target}}$ - Dec$_{{ref}}$ (marcsec)" 

522 

523 

524class TargetRefCatDeltaDecSkyPlot(TargetRefCatDeltaSkyPlotAstrom): 

525 """Plot the RA/Dec distribution of stars, with the 

526 difference between the Dec of the target and reference catalog as 

527 the color. 

528 """ 

529 

530 def setDefaults(self): 

531 super().setDefaults() 

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

533 self.process.buildActions.zStars.buildAction.actionB = LoadVector(vectorKey="dec_ref") 

534 

535 self.produce.plotName = "astromDiffSky_Dec" 

536 self.produce.zAxisLabel = "Dec$_{{target}}$ - Dec$_{{ref}}$ (marcsec)" 

537 

538 

539class TargetRefCatDeltaMetrics(AnalysisTool): 

540 """Calculate the AA1 metric and the sigma MAD from the difference between 

541 the target and reference catalog coordinates. 

542 """ 

543 

544 parameterizedBand = Field[bool]( 

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

546 ) 

547 

548 def coaddContext(self) -> None: 

549 """Apply coadd options for the metrics. Applies the coadd plot flag 

550 selector and sets flux types. 

551 """ 

552 self.prep.selectors.flagSelector = CoaddPlotFlagSelector() 

553 self.prep.selectors.starSelector.vectorKey = "{band}_extendedness_target" 

554 

555 self.applyContext(RefMatchContext) 

556 

557 self.process.buildActions.mags.vectorKey = "{band}_psfFlux_target" 

558 

559 self.produce.metric.newNames = { 

560 "AA1_RA": "{band}_AA1_RA_coadd", 

561 "AA1_sigmaMad_RA": "{band}_AA1_sigmaMad_RA_coadd", 

562 "AA1_Dec": "{band}_AA1_Dec_coadd", 

563 "AA1_sigmaMad_Dec": "{band}_AA1_sigmaMad_Dec_coadd", 

564 "AA1_tot": "{band}_AA1_tot_coadd", 

565 "AA1_sigmaMad_tot": "{band}_AA1_sigmaMad_tot_coadd", 

566 } 

567 

568 def visitContext(self) -> None: 

569 """Apply visit options for the metrics. Applies the visit plot flag 

570 selector and sets flux types. 

571 """ 

572 self.parameterizedBand = False 

573 self.prep.selectors.flagSelector = VisitPlotFlagSelector() 

574 self.prep.selectors.starSelector.vectorKey = "extendedness_target" 

575 

576 self.applyContext(RefMatchContext) 

577 

578 self.process.buildActions.mags.vectorKey = "psfFlux_target" 

579 

580 def setDefaults(self): 

581 super().setDefaults() 

582 

583 self.prep.selectors.starSelector = StarSelector() 

584 

585 # Calculate difference in RA 

586 self.process.buildActions.astromDiffRA = ConvertUnits( 

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

588 ) 

589 self.process.buildActions.astromDiffRA.buildAction.actionA = RAcosDec( 

590 raKey="coord_ra_target", decKey="dec_ref" 

591 ) 

592 self.process.buildActions.astromDiffRA.buildAction.actionB = RAcosDec( 

593 raKey="ra_ref", decKey="dec_ref" 

594 ) 

595 # Calculate difference in Dec 

596 self.process.buildActions.astromDiffDec = ConvertUnits( 

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

598 ) 

599 self.process.buildActions.astromDiffDec.buildAction.actionA = LoadVector(vectorKey="coord_dec_target") 

600 self.process.buildActions.astromDiffDec.buildAction.actionB = LoadVector(vectorKey="dec_ref") 

601 # Calculate total difference (using astropy) 

602 self.process.buildActions.astromDiffTot = AngularSeparation( 

603 raKey_A="coord_ra_target", 

604 decKey_A="coord_dec_target", 

605 raKey_B="ra_ref", 

606 decKey_B="dec_ref", 

607 ) 

608 

609 self.process.buildActions.mags = ConvertFluxToMag() 

610 

611 # Filter down to only objects with mag 17-21.5 

612 self.process.filterActions.brightStarsRA = DownselectVector(vectorKey="astromDiffRA") 

613 self.process.filterActions.brightStarsRA.selector = RangeSelector( 

614 vectorKey="mags", minimum=17, maximum=21.5 

615 ) 

616 

617 self.process.filterActions.brightStarsDec = DownselectVector(vectorKey="astromDiffDec") 

618 self.process.filterActions.brightStarsDec.selector = RangeSelector( 

619 vectorKey="mags", minimum=17, maximum=21.5 

620 ) 

621 

622 self.process.filterActions.brightStarsTot = DownselectVector(vectorKey="astromDiffTot") 

623 self.process.filterActions.brightStarsTot.selector = RangeSelector( 

624 vectorKey="mags", minimum=17, maximum=21.5 

625 ) 

626 

627 # Calculate median and sigmaMad 

628 self.process.calculateActions.AA1_RA = MedianAction(vectorKey="brightStarsRA") 

629 self.process.calculateActions.AA1_sigmaMad_RA = SigmaMadAction(vectorKey="brightStarsRA") 

630 

631 self.process.calculateActions.AA1_Dec = MedianAction(vectorKey="brightStarsDec") 

632 self.process.calculateActions.AA1_sigmaMad_Dec = SigmaMadAction(vectorKey="brightStarsDec") 

633 

634 self.process.calculateActions.AA1_tot = MedianAction(vectorKey="brightStarsTot") 

635 self.process.calculateActions.AA1_sigmaMad_tot = SigmaMadAction(vectorKey="brightStarsTot") 

636 

637 self.produce.metric.units = { 

638 "AA1_RA": "mas", 

639 "AA1_sigmaMad_RA": "mas", 

640 "AA1_Dec": "mas", 

641 "AA1_sigmaMad_Dec": "mas", 

642 "AA1_tot": "mas", 

643 "AA1_sigmaMad_tot": "mas", 

644 }