Coverage for python/lsst/faro/measurement/TractTableMeasurementTasks.py: 61%
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
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
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/>.
22from lsst.pex.config import Config, Field
23from lsst.pipe.base import Struct, Task
24from lsst.verify import Measurement, Datum
26from lsst.faro.utils.tex_table import calculateTEx
28import astropy.units as u
29import numpy as np
31__all__ = ("TExTableConfig", "TExTableTask")
34class TExTableConfig(Config):
35 """Class to organize the yaml configuration parameters to be passed to
36 TExTableTask when using a parquet table input. All values needed to perform
37 TExTableTask have default values set below.
39 Optional Input (yaml file)
40 ----------
41 Column names specified as str in yaml configuration for TeX task. These are
42 the desired column names to be passed to the calcuation. If you wish to use
43 values other than the default values specified below, add the following e.g.
44 line to the yaml file:
46 config.measure.raColumn = "coord_ra_new"
47 """
49 minSep = Field(
50 doc="Inner radius of the annulus in arcmin", dtype=float, default=0.25
51 )
52 maxSep = Field(
53 doc="Outer radius of the annulus in arcmin", dtype=float, default=1.0
54 )
55 nbins = Field(doc="Number of log-spaced angular bins", dtype=int, default=10)
56 rhoStat = Field(doc="Rho statistic to be computed", dtype=int, default=1)
57 shearConvention = Field(
58 doc="Use shear ellipticity convention rather than distortion",
59 dtype=bool,
60 default=True,
61 )
62 raColumn = Field(doc="RA column", dtype=str, default="coord_ra")
63 decColumn = Field(doc="Dec column", dtype=str, default="coord_dec")
64 ixxColumn = Field(doc="Ixx column", dtype=str, default="ixx")
65 ixyColumn = Field(doc="Ixy column", dtype=str, default="ixy")
66 iyyColumn = Field(doc="Iyy column", dtype=str, default="iyy")
67 ixxPsfColumn = Field(doc="Ixx PSF column", dtype=str, default="ixxPSF")
68 ixyPsfColumn = Field(doc="Ixy PSF column", dtype=str, default="ixyPSF")
69 iyyPsfColumn = Field(doc="Iyy PSF column", dtype=str, default="iyyPSF")
70 extendednessColumn = Field(doc="Extendedness column", dtype=str, default="extendedness")
71 psfFluxColumn = Field(doc="PsfFlux column", dtype=str, default="psfFlux")
72 psfFluxErrColumn = Field(doc="PsfFluxErr column", dtype=str, default="psfFluxErr")
73 deblend_nChildColumn = Field(doc="nChild column", dtype=str, default="deblend_nChild")
74 # Eventually want to add option to use only PSF reserve stars
77class TExTableTask(Task):
78 """Class to perform the tex_table calculation on a parquet table data
79 object.
81 Parameters
82 ----------
83 None
85 Output:
86 ----------
87 TEx metric with defined configuration.
88 """
90 ConfigClass = TExTableConfig
91 _DefaultName = "TExTableTask"
93 def run(
94 self, metricName, catalog, band=None
95 ):
97 self.log.info("Measuring %s", metricName)
99 # If accessing objectTable_tract, we need to append the band name at
100 # the beginning of the column name.
101 if band is not None:
102 prependString = band
103 else:
104 prependString = None
106 result = calculateTEx(catalog, self.config, prependString)
107 if "corr" not in result.keys():
108 return Struct(measurement=Measurement(metricName, np.nan * u.Unit("")))
110 writeExtras = True
111 if writeExtras:
112 extras = {}
113 extras["radius"] = Datum(
114 result["radius"], label="radius", description="Separation (arcmin)."
115 )
116 extras["corr"] = Datum(
117 result["corr"], label="Correlation", description="Correlation."
118 )
119 extras["corrErr"] = Datum(
120 result["corrErr"],
121 label="Correlation Uncertianty",
122 description="Correlation Uncertainty.",
123 )
124 else:
125 extras = None
126 return Struct(
127 measurement=Measurement(
128 metricName, np.mean(np.abs(result["corr"])), extras=extras
129 )
130 )