Coverage for python/lsst/analysis/tools/atools/sources.py: 24%

34 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-24 03:43 -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__ = ("SourcesTool",) 

24 

25from ..actions.plot.barPlots import BarPanel, BarPlot 

26from ..actions.scalar import CountAction, CountUniqueAction, FracThreshold 

27from ..actions.vector import DownselectVector, LoadVector, ThresholdSelector, VectorSelector 

28from ..interfaces import AnalysisTool 

29 

30 

31class SourcesTool(AnalysisTool): 

32 """Plot a histogram of the associated and unassociated sources.""" 

33 

34 def setDefaults(self, **kwargs): 

35 super().setDefaults() 

36 

37 self.process.buildActions.loadVectorSources = LoadVector() 

38 self.process.buildActions.associatedVectorSelector = ThresholdSelector() 

39 self.process.buildActions.unassociatedVectorSelector = ThresholdSelector() 

40 

41 # assign keys for PSF and AP Flux 

42 self.process.buildActions.loadVectorSources.vectorKey = "nDiaSources" 

43 self.process.buildActions.associatedVectorSelector.vectorKey = "nDiaSources" 

44 self.process.buildActions.associatedVectorSelector.op = "gt" 

45 self.process.buildActions.associatedVectorSelector.threshold = 1.0 

46 self.process.buildActions.unassociatedVectorSelector.vectorKey = "nDiaSources" 

47 self.process.buildActions.unassociatedVectorSelector.op = "le" 

48 self.process.buildActions.unassociatedVectorSelector.threshold = 1.0 

49 

50 self.process.filterActions.allSources = VectorSelector(vectorKey="nDiaSources") 

51 self.process.filterActions.associatedVector = DownselectVector( 

52 vectorKey="nDiaSources", selector=self.process.buildActions.associatedVectorSelector 

53 ) 

54 self.process.filterActions.unassociatedVector = DownselectVector( 

55 vectorKey="nDiaSources", selector=self.process.buildActions.unassociatedVectorSelector 

56 ) 

57 

58 self.process.buildActions.uniqueSources = CountUniqueAction(vectorKey="nDiaSources") 

59 self.process.calculateActions.associatedCount = CountAction(vectorKey="associatedVector") 

60 self.process.calculateActions.unassociatedCount = CountAction(vectorKey="unassociatedVector") 

61 

62 self.process.calculateActions.associatedPercent = FracThreshold( 

63 op="gt", threshold=1.0, vectorKey="nDiaSources" 

64 ) 

65 self.process.calculateActions.unassociatedPercent = FracThreshold( 

66 op="le", threshold=1.0, vectorKey="nDiaSources" 

67 ) 

68 

69 self.process.calculateActions.associatedCount = CountAction(vectorKey="associatedVector") 

70 self.process.calculateActions.unassociatedCount = CountAction(vectorKey="unassociatedVector") 

71 

72 self.produce.plot = BarPlot() 

73 self.produce.plot.panels["panel_source"] = BarPanel() 

74 self.produce.plot.panels["panel_source"].label = "N Assoc and Unassoc Sources" 

75 self.produce.plot.panels["panel_source"].bars = dict( 

76 associatedVector="Associated Sources", 

77 unassociatedVector="Unassociated Sources", 

78 ) 

79 

80 self.produce.metric.units = { 

81 "associatedPercent": "count", 

82 "unassociatedPercent": "count", 

83 "associatedCount": "count", 

84 "unassociatedCount": "count", 

85 "uniqueSources": "count", 

86 }