Coverage for python/lsst/faro/measurement/TractTableMeasurementTasks.py: 53%

Shortcuts on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

37 statements  

1# This file is part of faro. 

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

21 

22from lsst.pex.config import Field, DictField 

23from lsst.pipe.base import Struct, Task 

24from lsst.verify import Measurement, Datum 

25 

26from lsst.faro.base.ConfigBase import MeasurementTaskConfig 

27import lsst.faro.utils.selectors as selectors 

28from lsst.faro.utils.tex_table import calculateTEx 

29 

30import astropy.units as u 

31import numpy as np 

32 

33__all__ = ("TExTableConfig", "TExTableTask") 

34 

35 

36class TExTableConfig(MeasurementTaskConfig): 

37 """Class to organize the yaml configuration parameters to be passed to 

38 TExTableTask when using a parquet table input. All values needed to perform 

39 TExTableTask have default values set below. 

40 

41 Optional Input (yaml file) 

42 ---------- 

43 Column names specified as str in yaml configuration for TeX task. These are 

44 the desired column names to be passed to the calcuation. If you wish to use 

45 values other than the default values specified below, add the following e.g. 

46 line to the yaml file: 

47 

48 config.measure.raColumn = "coord_ra_new" 

49 """ 

50 

51 minSep = Field( 

52 doc="Inner radius of the annulus in arcmin", dtype=float, default=0.25 

53 ) 

54 maxSep = Field( 

55 doc="Outer radius of the annulus in arcmin", dtype=float, default=1.0 

56 ) 

57 nbins = Field(doc="Number of log-spaced angular bins", dtype=int, default=10) 

58 rhoStat = Field(doc="Rho statistic to be computed", dtype=int, default=1) 

59 shearConvention = Field( 

60 doc="Use shear ellipticity convention rather than distortion", 

61 dtype=bool, 

62 default=True, 

63 ) 

64 columns = DictField( 

65 doc="""Columns required for metric calculation. Should be all columns in SourceTable contexts, 

66 and columns that do not change name with band in ObjectTable contexts""", 

67 keytype=str, 

68 itemtype=str, 

69 default={"ra": "coord_ra", 

70 "dec": "coord_dec", 

71 "ixx": "ixx", 

72 "ixy": "ixx", 

73 "iyy": "ixx", 

74 "ixxPsf": "ixx", 

75 "ixyPsf": "ixx", 

76 "iyyPsf": "iyy", 

77 "deblend_nChild": "deblend_nChild" 

78 } 

79 ) 

80 columnsBand = DictField( 

81 doc="""Columns required for metric calculation that change with band in ObjectTable contexts""", 

82 keytype=str, 

83 itemtype=str, 

84 default={} 

85 ) 

86 

87 

88class TExTableTask(Task): 

89 """Class to perform the tex_table calculation on a parquet table data 

90 object. 

91 

92 Parameters 

93 ---------- 

94 None 

95 

96 Output: 

97 ---------- 

98 TEx metric with defined configuration. 

99 """ 

100 

101 ConfigClass = TExTableConfig 

102 _DefaultName = "TExTableTask" 

103 

104 def run( 

105 self, metricName, catalog, currentBands, **kwargs 

106 ): 

107 

108 self.log.info("Measuring %s", metricName) 

109 

110 # If accessing objectTable_tract, we need to append the band name at 

111 # the beginning of the column name. 

112 if currentBands is not None: 

113 prependString = currentBands 

114 else: 

115 prependString = None 

116 

117 # filter catalog 

118 catalog = selectors.applySelectors(catalog, 

119 self.config.selectorActions, 

120 currentBands=currentBands) 

121 

122 result = calculateTEx(catalog, self.config, prependString) 

123 if "corr" not in result.keys(): 

124 return Struct(measurement=Measurement(metricName, np.nan * u.Unit(""))) 

125 

126 writeExtras = True 

127 if writeExtras: 

128 extras = {} 

129 extras["radius"] = Datum( 

130 result["radius"], label="radius", description="Separation (arcmin)." 

131 ) 

132 extras["corr"] = Datum( 

133 result["corr"], label="Correlation", description="Correlation." 

134 ) 

135 extras["corrErr"] = Datum( 

136 result["corrErr"], 

137 label="Correlation Uncertianty", 

138 description="Correlation Uncertainty.", 

139 ) 

140 else: 

141 extras = None 

142 return Struct( 

143 measurement=Measurement( 

144 metricName, np.mean(np.abs(result["corr"])), extras=extras 

145 ) 

146 )